π Lesson 1: What Is PHP?
PHP is the invisible engine behind the majority of the web. Before you write a single line of code, let's understand what PHP is, how it works, and why it's been a powerhouse for over two decades.
π― Learning Objectives
By the end of this lesson, you will be able to:
- Explain what PHP is and what "server-side" means
- Distinguish between client-side and server-side code execution
- Describe the HTTP request/response cycle and PHP's role in it
- Identify real-world platforms and use cases powered by PHP
- Trace PHP's history from a personal project to a global language
Estimated Time: 30 minutes
Prerequisites: Basic familiarity with HTML (helpful but not required)
π In This Lesson
What Is PHP?
π Definition
PHP (PHP: Hypertext Preprocessor) is an open-source, general-purpose scripting language designed primarily for web development. It runs on the server, processing requests and generating HTML that gets sent to the user's browser.
That recursive acronym β PHP stands for "PHP: Hypertext Preprocessor" β is a fun bit of programmer humor. Originally it stood for "Personal Home Page," but the name evolved as the language grew far beyond personal websites.
Here's the key idea: when you visit a PHP-powered website, your browser never sees any PHP code. The server runs the PHP, and what arrives at your browser is plain HTML, CSS, and JavaScript β just like any other web page. PHP does its work before the page reaches you.
A Quick Taste
Here's what a tiny PHP file looks like. Don't worry about understanding every detail yet β just notice how PHP mixes with HTML:
<!DOCTYPE html>
<html>
<body>
<h1>Welcome!</h1>
<p>Today is <?php echo date("l, F j, Y"); ?></p>
</body>
</html>
The <?php ... ?> tags tell the server: "Run this as PHP." The echo command outputs text. The date() function grabs the current date. When the browser receives this page, it just sees something like:
What the browser receives:
<!DOCTYPE html>
<html>
<body>
<h1>Welcome!</h1>
<p>Today is Wednesday, April 16, 2026</p>
</body>
</html>
No PHP anywhere in the output β just clean HTML. That's the essence of server-side processing.
Client-Side vs. Server-Side
To understand PHP, you need to understand where code runs. There are two sides to every web interaction:
| Aspect | Client-Side | Server-Side |
|---|---|---|
| Runs on | User's browser (Chrome, Firefox, etc.) | Web server (Apache, Nginx, etc.) |
| Languages | HTML, CSS, JavaScript | PHP, Python, Ruby, Java, Node.js, etc. |
| Visible to user? | Yes β anyone can "View Source" | No β user only sees the output |
| When it runs | After the page loads in the browser | Before the page is sent to the browser |
| Can access | DOM, browser APIs, local storage | Databases, file system, email, APIs |
| Good for | UI interactions, animations, form validation | Data processing, authentication, storage |
β Key Insight
Client-side and server-side aren't competitors β they're partners. A modern website uses both. PHP handles the "back end" (data, logic, security), while HTML/CSS/JS handle the "front end" (what users see and interact with).
Why Does Server-Side Matter?
Some things simply cannot be done in the browser:
- Database queries β You can't let browsers connect directly to your database (that would be a massive security risk)
- User authentication β Passwords must be verified on the server, never in client-side code
- Sending emails β Browsers can't send email; servers can
- File processing β Uploading, resizing images, generating PDFs β all server tasks
- Sensitive business logic β Pricing calculations, access control, and anything you don't want users to tamper with
How PHP Works: The Request/Response Cycle
Every time you load a PHP-powered web page, a precise sequence of events occurs. Understanding this cycle is fundamental to everything you'll build in this course.
(Apache) participant P as π PHP Engine participant D as ποΈ Database
(MySQL) B->>S: 1. HTTP Request
(GET /products.php) S->>P: 2. "This is a .php file,
process it" P->>D: 3. Query: SELECT * FROM products D-->>P: 4. Results: product data P-->>S: 5. Generated HTML S-->>B: 6. HTTP Response
(HTML page) Note over B: 7. Browser renders
the HTML page
Step by Step
- The user makes a request β They type a URL or click a link. Their browser sends an HTTP request to the web server.
- The server recognizes PHP β The web server (Apache, in our case) sees that the requested file ends in
.phpand hands it to the PHP engine. - PHP executes the code β The PHP engine reads the file top-to-bottom, running any PHP code it finds. It might query a database, process form data, check login status, or perform calculations.
- The database responds β If PHP asked the database for data, it gets the results back.
- PHP generates HTML β PHP combines its processed data with the HTML in the file and produces a complete HTML document.
- The server sends the response β The generated HTML is sent back to the browser as an HTTP response.
- The browser renders the page β The browser receives plain HTML (no PHP) and displays it to the user.
β οΈ Important
PHP is stateless β each request starts fresh. When a user loads a new page, PHP doesn't automatically remember anything about the previous request. (We'll learn how to maintain state with sessions and cookies in Module 5.)
What Can You Build with PHP?
PHP powers an enormous portion of the web. Here are some of the most common things built with PHP:
Content Management Systems (CMS)
WordPress β the most popular CMS in the world β is built entirely in PHP. It powers roughly 40% of all websites on the internet, from personal blogs to enterprise news sites. Other PHP-based CMS platforms include Drupal and Joomla.
E-Commerce Platforms
Major e-commerce solutions like WooCommerce (a WordPress plugin), Magento, and OpenCart are all PHP-based. If you've ever bought something online, there's a good chance PHP processed your order.
Social Media & Communication
Facebook was originally built with PHP (they later created their own PHP variant called Hack). Slack's backend started as a PHP application. Many forums, chat apps, and community platforms use PHP.
Web Applications
PHP excels at building full-featured web applications: project management tools, customer relationship managers (CRMs), learning management systems (LMS), booking systems, inventory trackers, and more.
APIs & Microservices
Modern PHP (with frameworks like Laravel and Symfony) is widely used to build REST APIs that serve data to mobile apps and single-page applications.
π PHP by the Numbers
- PHP is used by approximately 75β77% of websites with a known server-side language
- WordPress alone (built with PHP) powers about 40% of all websites
- PHP has been a top-10 language on the TIOBE index for over 20 years
- Major frameworks: Laravel, Symfony, CodeIgniter, CakePHP, Slim
A Brief History of PHP
PHP has a fascinating origin story β it was never designed to become one of the world's most-used programming languages. It justβ¦ happened.
The Key Milestones
1994 β The Beginning: Rasmus Lerdorf, a Danish-Canadian programmer, created a set of C programs to track visits to his online rΓ©sumΓ©. He called them "Personal Home Page Tools" (PHP Tools). He open-sourced them, and other developers started using and improving them.
1997 β PHP 3: Two Israeli developers, Zeev Suraski and Andi Gutmans, rewrote the parser from scratch. PHP 3 transformed PHP from a simple tool into a genuine programming language. The acronym was changed to the recursive "PHP: Hypertext Preprocessor."
2004 β PHP 5: This was the big leap. PHP 5 introduced proper object-oriented programming with classes, interfaces, abstract classes, and exceptions. It also brought PDO (PHP Data Objects), a clean way to interact with databases that we'll use extensively in this course.
2015 β PHP 7: After PHP 5, the community planned PHP 6 (with Unicode support), but the effort stalled and was scrapped. They jumped straight to PHP 7, which delivered dramatic performance improvements β roughly twice as fast as PHP 5. It also added scalar type declarations, return types, and the null coalescing operator (??).
2020 β PHP 8: PHP 8 introduced the JIT (Just-In-Time) compiler, named arguments, the match expression, attributes (annotations), and union types. PHP 8.x releases have continued to modernize the language with enums, fibers, readonly properties, and more.
π‘ Fun Fact: There is no PHP 6. The planned Unicode rewrite was abandoned, and the community decided to skip the version number entirely to avoid confusion with the abandoned project.
PHP Today: Myths vs. Reality
PHP has a reputation problem. Some of the criticism was valid years ago, but modern PHP (version 8.x) is a very different language from the PHP of the early 2000s. Let's separate fact from fiction:
| Myth | Reality |
|---|---|
| "PHP is slow" | PHP 7/8 is dramatically faster than older versions. With the JIT compiler and opcode caching (OPcache), PHP competes well with other server-side languages for web workloads. |
| "PHP is insecure" | PHP itself isn't insecure β poorly written code is. Modern PHP provides excellent security tools: prepared statements (PDO), password hashing (password_hash), input filtering, and CSRF protection. We'll cover all of these. |
| "PHP is dying" | PHP powers roughly 75%+ of server-side web. WordPress, Laravel, Symfony, and Drupal all have thriving ecosystems. PHP job demand remains strong globally. |
| "PHP isn't a 'real' language" | Modern PHP has type declarations, enums, interfaces, traits, generics (planned), async fibers, attributes, and a mature package ecosystem (Composer/Packagist). It's a fully-featured language. |
| "Nobody uses PHP for new projects" | Laravel is one of the most popular web frameworks in any language. New projects are built with PHP daily. The Laravel ecosystem (Livewire, Inertia, Forge, Vapor) is particularly vibrant. |
β Bottom Line
PHP is a pragmatic choice for web development. It has a massive ecosystem, excellent hosting support (nearly every web host supports PHP out of the box), a gentle learning curve, and decades of battle-tested libraries. It's not the only option β but it's a solid, well-supported one.
Knowledge Check
π― Quick Quiz
Question 1: Where does PHP code execute?
Question 2: What does PHP send to the browser?
Question 3: Which of these tasks requires server-side code (like PHP) rather than client-side JavaScript?
Question 4: What does "PHP: Hypertext Preprocessor" tell us about when PHP runs?
Question 5: Why was PHP version 6 never released?
Summary
π Key Takeaways
- PHP is a server-side language β it runs on the web server, not in the browser. Users never see PHP code.
- Server-side code complements client-side code β PHP handles databases, authentication, and business logic; HTML/CSS/JS handle the user interface.
- The request/response cycle β the browser sends a request, the server runs PHP, PHP generates HTML, and the HTML is sent back to the browser.
- PHP powers the web β from WordPress to Facebook's origins, PHP runs on roughly 75% of server-side websites.
- Modern PHP is mature and performant β PHP 8.x includes a JIT compiler, type system, OOP features, and a rich ecosystem.
π Additional Resources
- PHP Official Website β Documentation, downloads, and news
- History of PHP β Official history from php.net
- PHP: The Right Way β Best practices and modern PHP conventions
- W3Techs PHP Usage Statistics β Current PHP market share data
π What's Next?
Now that you understand what PHP is and how it fits into web development, it's time to get your hands dirty! In Lesson 2: Setting Up Your Environment, you'll verify your LAMP stack, configure Apache, and run your first PHP script on your own machine.
π Congratulations!
You've completed Lesson 1! You now understand what PHP is β next, let's set it up so you can start using it.