What Is PHP?
Meet the language running the server side of a huge share of the web
Every website you visit is really a conversation between two computers. Your computer runs a browser, and somewhere else in the world a machine called a server is waiting. Your browser asks for a page, the server sends one back, and your browser draws it on the screen.
HTML and CSS describe what a page looks like once it arrives. But someone has to decide what goes into the page before it leaves the server. Should it say Good morning or Good evening? Should it show your shopping cart or somebody else's? Should the news page show today's stories or last week's? That deciding work happens on the server, and PHP is one of the most popular languages ever made for doing it.
PHP runs on the server
Here is the journey of a single page view on a PHP website:
- You click a link, and your browser sends a request to the server.
- The server sees that the page is a PHP file, so it hands the file to PHP.
- PHP runs the code inside the file. It might check the time, look things up, or do some math.
- PHP produces plain HTML as its output.
- The server sends that HTML back to your browser, which displays it.
Notice something important in step 5: the browser only ever receives HTML. It never sees your PHP code. If you view the source of a PHP page in your browser, you will find ordinary HTML, because the PHP already ran and finished its job on the server.
Why learn PHP?
PHP has been around since the mid 1990s, and it quietly runs an enormous share of the web. WordPress, the system behind a huge slice of all websites, is written in PHP. Wikipedia runs on PHP. Facebook was originally built with it. When people say PHP powers a big part of the internet, they are not exaggerating.
For a beginner, PHP has some real advantages:
- It was designed for building web pages, so common web tasks feel natural.
- Almost every cheap or free web host in the world supports it out of the box.
- You can start small: a PHP file can be ninety percent plain HTML with a tiny bit of PHP sprinkled in.
What a PHP file looks like
A PHP file usually ends in .php, and PHP code lives between special tags: <?php to open and ?> to close. Everything outside those tags is treated as ordinary HTML. Here is a tiny taste, just to look at:
<p>The server says:</p>
<?php
echo "Hello from PHP!";
?>Do not worry about the details yet. In the next lesson you will learn exactly what echo does and how PHP and HTML share the same file.
This course focuses on reading and understanding PHP, so you do not need to install anything. If you want to experiment along the way, any free online PHP sandbox will run the examples exactly as written.
Quick check
Q1 Where does PHP code actually run?
Q2 You view the source of a PHP-powered page in your browser. What do you see?
Want to save your progress? It's free.
Create a free account