Home › PHP Tutorial › PHP installation
PHP installation
Full step-by-step installation for Windows, macOS and Linux.
Windows (XAMPP)
- Open
apachefriends.organd download XAMPP for Windows. - Run the installer. Keep Apache and PHP ticked and install to
C:\xampp. - Open the XAMPP Control Panel and click Start next to Apache. Allow it through the firewall if asked.
- Save your PHP files inside
C:\xampp\htdocs.
macOS (Homebrew)
- Open Terminal and install Homebrew from
brew.shif you do not have it. - Run
brew install php. - Run
php -vto check it.
Linux (Ubuntu or Debian)
- Run
sudo apt update. - Run
sudo apt install php-cli. - Run
php -vto check it.
Run your first program
- Save the code from the editor below as
hello.php. - In the terminal, go to its folder and run
php hello.php. - Or start the built-in server with
php -S localhost:8000and openhttp://localhost:8000/hello.phpin a browser. Stop it with Ctrl+C. - With XAMPP, open
http://localhost/hello.php.
If something goes wrong
- The browser shows the PHP code as text: open the page through
http://localhost, not by double-clicking the file. - Apache will not start: another program uses port 80. Close it or change the port in XAMPP.
'php' is not recognized: add the PHP folder to your PATH and reopen the terminal.
Example code
<?php
echo "PHP is installed";
?>