codegurukool.com · Free coding tutorials & online compiler

Home › PHP Tutorial › PHP installation

PHP installation

Full step-by-step installation for Windows, macOS and Linux.

Windows (XAMPP)

  1. Open apachefriends.org and download XAMPP for Windows.
  2. Run the installer. Keep Apache and PHP ticked and install to C:\xampp.
  3. Open the XAMPP Control Panel and click Start next to Apache. Allow it through the firewall if asked.
  4. Save your PHP files inside C:\xampp\htdocs.

macOS (Homebrew)

  1. Open Terminal and install Homebrew from brew.sh if you do not have it.
  2. Run brew install php.
  3. Run php -v to check it.

Linux (Ubuntu or Debian)

  1. Run sudo apt update.
  2. Run sudo apt install php-cli.
  3. Run php -v to check it.

Run your first program

  1. Save the code from the editor below as hello.php.
  2. In the terminal, go to its folder and run php hello.php.
  3. Or start the built-in server with php -S localhost:8000 and open http://localhost:8000/hello.php in a browser. Stop it with Ctrl+C.
  4. With XAMPP, open http://localhost/hello.php.

If something goes wrong

Example code

<?php
echo "PHP is installed";
?>

Run this code in the online editor

← PHP introductionPHP install and syntax →