PHP Introduction

Beginner
⏱️ 14 min read
📚 Updated: Jul 2026
🎯 5 Examples
echo · server · HTML

What You’ll Learn

This page is a self-contained introduction to PHP—a server-side language for dynamic websites. You will understand what PHP does, how it runs on a web server, and write your first programs that output HTML.

01

What is PHP

Language overview.

02

History

Rasmus Lerdorf.

03

How it works

Server runtime.

04

Hello World

First program.

05

Open source

Free to use.

06

Examples

Hands-on code.

🤔 What is PHP?

PHP (Hypertext Preprocessor) is a server-side programming language widely used to develop dynamic websites and web applications. Unlike JavaScript running in the browser, PHP executes on the web server and sends the finished HTML to the visitor.

PHP handles form submissions, user login, database queries, file uploads, session management, and API backends. It powers popular CMS platforms like WordPress, frameworks like Laravel and Symfony, and countless custom business sites.

💡
Beginner tip

PHP files usually end in .php. The server processes PHP tags and replaces them with output before the browser ever sees your source code.

👴 Who Is the Father of PHP?

PHP was created by Rasmus Lerdorf in 1994 as a set of Common Gateway Interface (CGI) scripts for tracking visits to his online resume. It evolved into a full language and is now maintained by The PHP Group and a large open-source community.

EventYearHighlight
PHP created1994Rasmus Lerdorf personal home page tools
PHP/FI 2.01997Form interpreter release
PHP 31998Renamed Hypertext Preprocessor
PHP 52004Improved OOP support
PHP 72015Major speed and memory improvements
PHP 8+2020+JIT, attributes, named arguments, union types

⚙️ How PHP Works

PHP code is executed on the server before the web page is sent to the client’s browser. That allows dynamic content based on user input, database results, the time of day, or any logic you write in PHP.

  1. The browser requests a page (e.g. index.php)
  2. The web server (Apache, Nginx) passes the file to the PHP engine
  3. PHP runs your code and builds HTML output
  4. The server sends plain HTML/CSS/JS back to the browser

Visitors never see your raw PHP source—only the generated result.

📝 Where to Write PHP Code?

PHP can be embedded directly into HTML, which makes it a natural fit for web development. Use any text editor or IDE (VS Code, PhpStorm, Notepad++), save files with a .php extension, and place them in your web server’s document root (e.g. htdocs in XAMPP).

index.php
<!DOCTYPE html>
<html lang="en">
<head>
  <title>My PHP Page</title>
</head>
<body>
  <h1>Today is <?php echo date('Y-m-d'); ?></h1>
</body>
</html>

Anything outside <?php ?> tags is sent to the browser as normal HTML.

📖 Is PHP Easy to Learn?

PHP is considered relatively easy to learn, especially for beginners new to programming. Its syntax resembles C, Java, and JavaScript, and the language is designed to be practical for web tasks like printing output and reading form data.

PHP has a large, active community with tutorials, forums, and packages on Packagist. The official PHP documentation is comprehensive and beginner-friendly.

As with any language, difficulty depends on your prior experience and project complexity. Start with variables, echo, and simple forms before tackling databases and frameworks.

🔓 Is PHP Open Source?

Yes. PHP is an open-source language released under the PHP License. Developers can use it freely in personal and commercial projects and contribute to its development on GitHub.

The runtime, standard library, and documentation are maintained collaboratively. Hosting providers worldwide ship PHP preinstalled, so deploying PHP apps is straightforward and inexpensive.

💻 Install and Run PHP Locally

Pick one of these beginner-friendly setups:

  • XAMPP / WAMP / Laragon (Windows) — Apache + PHP + MySQL in one installer
  • Homebrew (macOS) — brew install php
  • Built-in server (any OS with PHP installed) — quick testing without Apache
terminal
php -v
cd my-project
php -S localhost:8000

Open http://localhost:8000/demo.php in your browser after starting the built-in server.

📄 Hello World in PHP

Here is a simple PHP program that prints Hello, World! to the browser:

PHP
<?php
echo "Hello, World!";
?>

The echo statement outputs text. Wrap PHP in <?php and ?> tags inside .php files. Learn more in the dedicated PHP echo tutorial.

🌐 Sites Using PHP

PHP runs behind many global websites and platforms. Here are seven well-known examples:

  1. Facebook — early backend infrastructure included PHP (HHVM evolved from it)
  2. Wikipedia — powered by MediaWiki, built with PHP
  3. Tumblr — blogging platform with PHP in its stack
  4. Slack — parts of its web infrastructure use PHP
  5. Mailchimp — email marketing platform with PHP heritage
  6. Etsy — marketplace with PHP in its technology mix
  7. WordPress — the world’s most popular CMS, written entirely in PHP

Millions of smaller sites, agencies, and hosting plans still rely on PHP for its simplicity and ecosystem.

🧰 Core Building Blocks

ConceptWhat it does
Variables$name = "Alex"; store data
echo / printOutput text and HTML to the browser
Superglobals$_GET, $_POST, $_SESSION for web input
Control flowif, for, foreach, while
FunctionsReusable blocks: function greet() { }
ArraysLists and associative maps of data
Include filesrequire / include for shared layout code

⚡ Quick Reference

TaskPHP code
Open PHP block<?php
Print textecho "Hello";
Variable$count = 10;
Read GET param$_GET['name'] ?? ''
String concat$full = $first . ' ' . $last;
Comment// line or /* block */

Examples Gallery

Five starter programs. Save each as a .php file and open it through your local server or php -S localhost:8000.

Example 1 — Hello, World!

PHP
<?php
echo "Hello, World!";
?>

Example 2 — Variables and echo

PHP
<?php
$name = "Alex";
$age = 20;
echo "Name: $name\n";
echo "Age: " . $age;
?>

Variables start with $. Double-quoted strings expand variables; use . to concatenate.

Example 3 — PHP embedded in HTML

index.php
<!DOCTYPE html>
<html lang="en">
<body>
  <h1><?php echo "Welcome to PHP!"; ?></h1>
  <p>Server time: <?php echo date("H:i:s"); ?></p>
</body>
</html>

Example 4 — Even or odd with if-else

PHP
<?php
$n = 7;

if ($n % 2 === 0) {
    echo "$n is even";
} else {
    echo "$n is odd";
}
?>

Example 5 — A simple function

PHP
<?php
function add(int $a, int $b): int {
    return $a + $b;
}

echo "Sum = " . add(3, 5);
?>

Modern PHP supports type hints (int) and return types for clearer, safer code.

🧠 How PHP Serves a Web Page

1

Browser requests page

The user visits https://example.com/page.php or submits a form.

HTTP request
2

Web server invokes PHP

Apache or Nginx passes the file to the PHP engine with request data in superglobals.

Execute
3

PHP builds output

Your script queries databases, reads files, and echoes HTML fragments.

Generate
=

HTML response sent

The browser renders the final page; PHP source stays on the server.

Summary

  • PHP is a server-side language for dynamic websites and web apps.
  • Created by Rasmus Lerdorf in 1994; maintained by The PHP Group and the community.
  • PHP runs on the server, generates HTML, and integrates easily with databases and forms.
  • It is open source, beginner-friendly, and powers WordPress and many frameworks.
  • Write code in .php files using <?php ?> tags and echo.
  • Next step: learn PHP echo and PHP strings.

💡 Best Practices

✅ Do

  • Use a current PHP 8.x release for performance and security fixes
  • Validate and sanitize all user input from $_GET and $_POST
  • Enable error reporting while learning; hide errors from users in production
  • Use prepared statements (PDO/MySQLi) when talking to databases
  • Keep logic in separate files; use includes for headers and footers
  • Follow PSR coding standards as your projects grow

❌ Don’t

  • Mix large blocks of HTML and PHP without structure—refactor into templates
  • Trust raw user input in SQL queries (SQL injection risk)
  • Expose phpinfo() or debug details on public servers
  • Skip HTTPS for login forms and sensitive data
  • Store passwords in plain text—always hash with password_hash()
  • Run outdated PHP 5.x or 7.0 versions that no longer receive security updates

❓ Frequently Asked Questions

PHP (Hypertext Preprocessor) is a server-side scripting language used to build dynamic websites and web applications. The server runs PHP code and sends the resulting HTML to the browser.
Yes. PHP powers WordPress, Laravel, Symfony, and millions of sites. It remains one of the most deployed server languages, especially for content sites, e-commerce, and CMS platforms.
It helps. PHP is often embedded in HTML pages. Learn basic HTML tags and forms first, then add PHP to generate dynamic content and handle user input.
Install XAMPP, WAMP, or Laragon on Windows, or use Homebrew on macOS. Save a .php file, start Apache, and open http://localhost/yourfile.php. For quick tests, run php -S localhost:8000 in a folder.
Yes. PHP is open source under the PHP License. You can use it freely in personal and commercial projects without licensing fees.
Study echo, variables, strings, if-else, loops, functions, and forms. Then explore MySQL, sessions, and a framework like Laravel when you are ready for larger projects.
Fun fact

PHP originally stood for Personal Home Page, but it was later renamed to Hypertext Preprocessor to reflect its broader role as a general-purpose web language. It is one of the few recursive acronyms in computing—the “P” in PHP stands for PHP itself.

Try It Yourself

Install PHP or XAMPP, save the Hello World example, and open it in your browser.

Continue to PHP echo →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful