This guide will help you set up a local development environment.Below is a clear, step-by-step guide to installing PHP for undergraduate web programming. It covers the three most common platforms and ends with a quick sanity check and common pitfalls.
This guide installs PHP 8.x, suitable for modern web development and coursework.
Open a terminal (Command Prompt / PowerShell on Windows) and run:
php -v
If you see a version number (e.g. PHP 8.2.x), PHP is already installed.
If not, follow the instructions below.
MAMP is a popular choice for macOS, bundling Apache, MySQL, and PHP. However, for simplicity and ease of use, we recommend using Homebrew to install PHP directly.
Start MAMP and navigate to http://localhost:8888 to verify the installation.
MAMP localhost shows the MAMP welcome page.
To enhance your web development experience, consider installing the following browser extensions:
Most students on macOS should use Homebrew.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Restart the terminal after installation.
brew install php
php -v
You should see something like:
PHP 8.2.x (cli)
/opt/homebrew/bin/php (Apple Silicon)/opt/homebrew/etc/php/8.2/php.iniXAMPP bundles PHP + Apache + MySQL, which is ideal for learning.
Open XAMPP Shell or Command Prompt and run:
php -v
If not recognised:
C:\xampp\php\php.exeDownload PHP from: https://windows.php.net/download/
C:\phpC:\php to PATHsudo apt update
sudo apt install php php-cli php-common
Optional but useful extensions:
sudo apt install php-curl php-mbstring php-xml php-mysql
Verify:
php -v
PHP includes a built-in development web server.
Create index.php:
<?php
echo "Hello, PHP!";
From the directory containing index.php:
php -S localhost:8000
Visit:
http://localhost:8000
You should see:
Hello, PHP!
.html → static, served as-is.php → executed on the server, then HTML is sent to the browserExample:
<?php
$name = "Student";
?>
<!doctype html>
<html>
<body>
<h1>Hello <?= $name ?></h1>
</body>
</html>
php: command not foundC:\xampp\php is in PATHfile://)php -S localhost:8000 and access via http://brew upgrade phpsudo apt upgrade phpFor first-year undergraduates, I recommend:
Editor → VS Code with:
php -v worksphp -S localhost:8000 runslocalhost:8000.php files execute correctly