PHP Install

To run PHP on your own machine you need a web server, the PHP interpreter, and usually a database, which are easiest to get through an all-in-one package.

Do you need to install anything?

Not always. Many web hosting providers already have PHP installed and configured, so if you simply upload a .php file to a host that supports PHP, it will run without any setup on your part. You only need a local installation when you want to build and test PHP applications on your own computer before publishing them. Once installed, you are ready for the PHP Syntax lesson.

  • A web server such as Apache or Nginx to receive requests and serve pages
  • The PHP interpreter, which actually executes your PHP code
  • Optionally a database such as MySQL or MariaDB if your app stores data

The easy way: an all-in-one stack

For beginners, the simplest approach is to install a bundled package that includes the web server, PHP, and a database together, already configured to work as a unit. These stacks let you skip the tricky manual configuration and start writing code within minutes.

PackageBest forIncludes
XAMPPWindows, macOS, LinuxApache, PHP, MariaDB, phpMyAdmin
MAMPmacOS and WindowsApache/Nginx, PHP, MySQL
LaragonWindowsApache/Nginx, PHP, MySQL, easy virtual hosts
Built-in serverQuick testing anywherePHP only, no separate web server needed
Note: XAMPP is a popular starting point because it works the same way across operating systems and includes a control panel where you can start and stop the server with a single click.

Running PHP without a full server

PHP ships with a small built-in web server that is perfect for learning and quick experiments. Once PHP is installed and available on your command line, you can serve the files in a folder with a single command. This avoids installing Apache or Nginx just to try things out.

Example

# Move into your project folder, then start the server
php -S localhost:8000

# Now open http://localhost:8000 in your browser

You can also run a PHP script directly from the command line without any browser at all. This is useful for testing small snippets or writing scripts that are not meant to be web pages.

Example

<?php
// Save this as hello.php
echo "PHP is installed and working!\n";
echo "Running version: " . phpversion();
?>

Example

# Run the script from your terminal
php hello.php

# Check which version of PHP you have
php -v
Note: Aim to install a currently supported version of PHP (PHP 8.1 or newer at the time of writing). Older versions no longer receive security updates and lack many modern language features.

Exercise: PHP Install

What do you need on a machine to actually run PHP scripts?