Learn PHP from Scratch

Introduction to PHP: Setup and Your First Script

Lesson 1 of 7 2 min read Updated 10 October 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.

Practice tasks

Reading is not enough. Try these without copying code, then compare with the lesson.

  • Install a local server stack and run a script that prints your name.
  • Mix PHP and HTML in one file.
  • Use phpinfo() once to see your configuration, then delete the file.

Common mistakes

  • Opening the PHP file directly from the file system so the code does not run.
  • Leaving phpinfo() on a public server.

Quick check

What do PHP files need to run?

A web server with PHP, not just a browser.

What are the PHP opening tags?

<?php and optionally ?> at the end.