Learn PHP from Scratch

Introduction to PHP: Setup and Your First Script

Lesson 1 of 7 2 min read Updated 28 September 2026

What is PHP?

PHP is a server-side scripting language. The server runs your PHP code and sends plain HTML to the browser. It powers a very large share of websites, including WordPress, and it works well with MySQL databases.

What you need

  • XAMPP or a similar package that bundles PHP, Apache and MySQL, or
  • PHP installed on its own, using its built-in development server.

To use the built-in server, open a terminal in your project folder and run:

php -S localhost:8000

Then open http://localhost:8000 in your browser.

Your first script

Create index.php:

<?php
echo "Hello, World!";

PHP code lives inside <?php ... ?>. Each statement ends with a semicolon.

Mixing PHP and HTML

<!DOCTYPE html>
<html>
<body>
  <h1><?php echo "Welcome to PHP"; ?></h1>
  <p>Today is <?php echo date("d M Y"); ?>.</p>
</body>
</html>

Comments

// single line
# also single line
/* multiple
   lines */

Note: You cannot open a .php file by double-clicking it. It must run through a PHP server, otherwise the browser shows the raw code.

Practice

Create a page that prints your name, the current date and a heading using PHP.