Introduction to PHP
Learn what PHP is, how server-side scripting works, and why PHP still powers a massive share of the web.
Introduction
When you visit a website and see a personalized greeting, a shopping cart with your items, or a blog post pulled from a database, there is a good chance server-side code generated that page before it ever reached your browser. PHP is one of the oldest and most widely used languages for exactly that job.
This lesson introduces what PHP is, how it differs from browser-based languages like JavaScript, and why — despite being decades old — it still powers a huge share of the modern web, including giants like WordPress and Facebook's early years.
- What PHP is and what "server-side scripting" means.
- How a PHP file gets turned into the HTML you see in your browser.
- How PHP differs from client-side JavaScript.
- What PHP is commonly used to build.
- Where PHP fits in the modern web development landscape.
What is PHP?
PHP (originally "Personal Home Page," now recursively "PHP: Hypertext Preprocessor") is a server-side scripting language built specifically for web development. PHP code runs on the web server, and the results — usually HTML — are what get sent to the visitor's browser.
Unlike a general-purpose language you might use for desktop software, PHP was designed from the start around one job: taking a request from a browser, doing some work (often involving a database), and producing a web page in response.
Server-Side
PHP code executes on the server, never inside the visitor's browser.
Embedded in HTML
PHP code lives inside <?php ?> tags, mixed directly with regular HTML markup.
Database-Friendly
PHP has first-class support for talking to databases like MySQL.
Open Source & Free
PHP is free to use, runs on every major operating system, and has a massive community.
- PHP runs on the server, not in the browser.
- It generates dynamic HTML based on data, user input, or a database.
- It is embedded directly inside HTML files using <?php ?> tags.
How PHP Works
When a browser requests a .php file, the web server hands that file to the PHP interpreter. The interpreter executes any PHP code it finds, and the result — plain HTML, CSS, or even JSON — is what gets sent back. The browser never sees the original PHP source; it only sees the output.
Because PHP runs before the page ever reaches the browser, it can safely access things a browser never should — database passwords, private files, secret API keys — without exposing them to the visitor.
PHP vs Client-Side JavaScript
It is easy to confuse PHP and JavaScript, since both are often used to build the same website. The key difference is where each one runs.
PHP (Server-Side)
- Runs on the web server
- Can access databases and files directly
- Generates the HTML before it reaches the browser
- Cannot directly manipulate the page after it has loaded
JavaScript (Client-Side)
- Runs in the visitor's browser
- Cannot directly access server files or databases
- Runs after the HTML has already loaded
- Can update the page instantly without reloading
In practice, most real websites use both: PHP to build the initial page and talk to the database, and JavaScript to make that page interactive once it is loaded.
What Can PHP Do?
Generate Dynamic Pages
Build pages whose content changes based on data, users, or a database.
Talk to Databases
Read and write data in MySQL and other databases to power real applications.
Handle Forms
Process form submissions — logins, contact forms, checkouts, and more.
Manage Sessions & Cookies
Keep track of logged-in users as they move between pages.
Work with Files
Read, write, and upload files on the server.
Build APIs
Return JSON data for a JavaScript frontend or a mobile app to consume.
Where PHP Is Used
PHP has been powering the web since 1995 and, decades later, still runs a remarkable share of it.
WordPress
WordPress is written in PHP and powers a huge percentage of all websites on the internet.
Facebook (early years)
Facebook was originally built in PHP, and later created HHVM to run PHP-like code faster at scale.
E-commerce
Platforms like WooCommerce and Magento use PHP to power online stores.
Modern Frameworks
Laravel and Symfony bring modern architecture and tooling to PHP development.
Example: A First Look at PHP Code
You do not need to understand every detail yet — this is just a preview. Notice how PHP code sits inside <?php ?> tags, right alongside regular HTML.
<!DOCTYPE html>
<html>
<body>
<h1>Welcome!</h1>
<?php
$framework = "PHP";
echo "<p>This page was generated by $framework.</p>";
?>
</body>
</html>Welcome!
This page was generated by PHP.Common Mistakes
- Assuming PHP runs in the browser like JavaScript — it always runs on the server first.
- Forgetting that visitors never see your raw PHP source code, only its output.
- Thinking PHP is "outdated" — modern PHP (8.x) is fast, typed, and actively maintained.
- Skipping the basics and jumping straight into a framework like Laravel before understanding plain PHP.
Best Practices
- Install a local development environment (covered in the next few lessons) before writing real projects.
- Learn plain PHP fundamentals before adopting a framework.
- Keep the official PHP manual (php.net) bookmarked as your primary reference.
- Practice by building small, complete pages rather than only reading about syntax.
Frequently Asked Questions
Is PHP still worth learning today?
Yes. PHP powers a massive share of the web (largely through WordPress) and remains actively developed, with modern versions offering strong performance and typing features.
Do I need to know HTML before learning PHP?
Basic HTML knowledge helps a lot, since PHP is so often mixed directly with HTML markup to generate pages.
Is PHP the same as HTML?
No. HTML describes structure and content; PHP is a programming language that can generate HTML dynamically based on logic and data.
Can PHP be used without a database?
Yes, though most real-world PHP applications eventually use a database like MySQL to store persistent data.
What is the difference between PHP and a PHP framework like Laravel?
PHP is the language itself. Laravel is a framework built in PHP that provides structure, tools, and conventions to build applications faster.
Key Takeaways
- PHP is a server-side scripting language built specifically for the web.
- PHP code runs on the server and outputs HTML (or JSON, etc.) to the browser.
- PHP is commonly embedded directly inside HTML using <?php ?> tags.
- PHP and JavaScript solve different problems: server-side logic vs. browser interactivity.
- PHP still powers a huge share of the web, largely through WordPress and modern frameworks like Laravel.
Summary
PHP is a server-side scripting language purpose-built for the web. It runs on the server, generates the HTML your browser displays, and has powered a huge portion of the internet for decades.
In this lesson, you learned what PHP is, how a PHP file becomes a webpage, how it compares to client-side JavaScript, and where it is used today. Next, you will explore the history behind PHP and how it evolved into the language it is now.
- You understand what PHP is and why it exists.
- You can explain how a PHP file becomes an HTML response.
- You know the key difference between PHP and JavaScript.
- You are ready to explore the history of PHP.