Skip to content
BENIBIX Learn

PHP and Ruby for the Web

Level 2 · Languages of the web

Two languages that build web pages on the server before they are sent. What PHP is used for, why Ruby is known for Rails, and how they differ.

Course contentsLesson 6 of 12

Level 3 · General-purpose and systems languages

  1. Python, Java and C#
  2. C, C++, Rust and Go

Level 4 · Languages for phones

  1. Swift, Kotlin and Dart

Level 5 · Data and functional languages

  1. R, Julia and MATLAB
  2. Haskell, Scala and Elixir

Level 6 · Scripting languages

  1. Shell Scripts, Perl and Lua

After this lesson you can

  • Explain what server-side code does
  • Say what PHP is best known for
  • Say what Ruby on Rails made easy

11 mincovers 2 glossary entries

Worth reading first: JavaScript and TypeScript

Which languages build a page on the server

Some code runs on the server, not in the browser. When you open a page, the server can run a program that builds the page for you, such as your inbox or your basket, and then sends the finished HTML. PHP and Ruby are two languages made for that job. You never see their code, only the page it built.

PHP was first made in 1994 for building personal home pages, and it grew into a full language. It runs on almost every web host, and it is cheap to run. WordPress, the tool behind a huge share of the world's websites, is written in PHP.

PHP can sit right inside an HTML file. A page can be mostly HTML, with a few PHP lines that drop in today's date or the user's name. That made it easy to start with, which is a big part of why it spread so far.

Ruby was made in Japan in the mid 1990s to be pleasant to write. Its code reads almost like English, such as 3.times { puts "Hi" }. It became famous through Ruby on Rails, a framework from 2004 that sets up a whole web app for you, so a small team can ship fast.

Both are dynamically typed and interpreted. PHP's strength is that it is everywhere and costs little to host. Ruby's strength is that Rails makes common jobs short. Sites like GitHub and Shopify were built with Rails.

Many new projects use JavaScript or Python on the server instead. Still, a huge part of the web runs on PHP today. Keeping all of it running is a big job market of its own.

The common mistake is to call PHP dead because it is old and often mocked. Modern PHP has types and is fast. Choose a server language by what your team knows and what your host runs, not by the jokes.

php
<h1>Hello, <?php echo $name; ?>!</h1>
<p>Today is <?php echo date("l"); ?>.</p>
The server runs the PHP bits, then sends the browser plain HTML such as Hello, Emma! Today is Monday.
The code runs on the server and builds the page. The browser only ever sees the finished HTML.

Worked example

Jack builds a booking site in a weekend

Jack needs a booking site for his bike repair shop. With Rails, one command sets up the app, and a second makes the bookings page with a form and a database table.

He has a working site in 2 days. He hosts it on a $7 a month plan.

The words for this lesson2

Check yourself

Where does PHP code run when you open a web page?

Finished this lesson?

Marking it complete also marks its 2 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.