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 1 · How languages differ
Level 2 · Languages of the web
Level 3 · General-purpose and systems languages
Level 4 · Languages for phones
Level 5 · Data and functional languages
Level 6 · Scripting languages
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.
<h1>Hello, <?php echo $name; ?>!</h1>
<p>Today is <?php echo date("l"); ?>.</p>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.