November 19, 2026 - 11:04
PHP Lesson 01 — Run PHP Locally and Open Your First Page Image
PHP Tutorials

PHP Lesson 01 — Run PHP Locally and Open Your First Page

0 Comments

Try opening a PHP file the same way you open an HTML file and you may see the code instead of a page. PHP needs to run first. Let’s get one page working on your computer so we have somewhere to put our tasks next time.

Install PHP first

You need a text editor, a terminal and PHP 8.3 or newer. If php -v already reports a suitable version, move on to the project folder. Otherwise follow the instructions for your operating system.

Windows

On 64-bit Intel or AMD Windows, download the stable x64 Non Thread Safe (NTS) ZIP from PHP’s download page. Extract it to a directory such as C:\php. Add the directory that contains php.exe to your Windows user Path. Open a fresh PowerShell window and run php -v. If the executable reports a missing runtime, install the Visual C++ Redistributable linked in the PHP manual.

PHP for Windows downloads · Windows installation requirements

Ubuntu or Debian

Run sudo apt update, then sudo apt install php-cli. Check the result with php -v. If your distribution supplies a PHP release older than 8.3, use a local environment with a newer supported distribution release.

Ubuntu PHP installation guide

macOS

If you use Homebrew, run brew install php. If you need Homebrew, follow its official setup instructions first. Open a new terminal and run php -v after installation.

Homebrew installation · PHP formula

Create the first file

Name your working folder php-task-list. Create a public directory inside it and save a new UTF-8 file at public/index.php. On Windows, show file extensions to check that the editor saved it as index.php.

The $title variable holds the heading. <?= is shorthand for printing a value. htmlspecialchars() keeps special characters in the heading from being interpreted as markup.

Complete working files

public/index.php

PHP
<?php
$title = 'Task list';
?>
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title><?= htmlspecialchars($title, ENT_QUOTES, 'UTF-8') ?></title>
<h1><?= htmlspecialchars($title, ENT_QUOTES, 'UTF-8') ?></h1>
</html>
BASH
php -v
php -S 127.0.0.1:8000 -t public

From the folder that contains public, start the server with the second command. Visit http://127.0.0.1:8000 while the terminal is still open.

Save the example at public/index.php inside a new php-task-list folder. The heading lives in $title, so it only needs to be assigned once. Replace Task list with Today’s tasks, save, and refresh. Both the tab title and the page heading should change.

PHP built-in server

Related Articles

Comments (0)

No comments yet. Be the first to comment!

Leave a Comment