To run PHP code on your computer, you need a local web server environment. PHP itself is
a server-side language, which means it cannot run by simply opening a .php
file in your browser the way an HTML file can. You need a proper server setup. This
guide covers the easiest and most reliable ways to get started on Windows, macOS, and
Linux.
A typical PHP development environment consists of three things working together:
.php
filesYou can install each of these separately, or use an all-in-one stack that bundles all three for you. For beginners, the all-in-one approach is almost always the better choice.
PHP runs on all major platforms. Choose the one that matches your computer:
Laragon is a modern, lightweight local development environment for Windows. It bundles Apache, PHP, MySQL, and phpMyAdmin and gets you running in minutes — no complex configuration required.
laragon.org/download and download the Full
version (which includes Apache, PHP, MySQL, and phpMyAdmin).
.php files inside the C:\laragon\www\ folder.
Open a browser and navigate to http://localhost to see them run.
www\. For example, a folder named myproject becomes
accessible at http://myproject.test — no manual configuration needed.
XAMPP is the most popular cross-platform PHP stack in the world. It includes Apache, PHP, MySQL (MariaDB), and phpMyAdmin, and works on all three major operating systems.
apachefriends.org and download the XAMPP installer for your
operating system.
C:\xampp on Windows).
.php files inside C:\xampp\htdocs\ (Windows) or
/opt/lampp/htdocs/ (Linux). Access them at
http://localhost/your-file.php.
On Ubuntu or Debian-based Linux systems, you can install PHP directly using the package manager. Open your terminal and run:
sudo apt update
sudo apt install apache2 php libapache2-mod-php
sudo apt install mysql-server php-mysql
sudo systemctl restart apache2
Your PHP files go inside /var/www/html/. Open a browser and visit
http://localhost to confirm Apache is running.
macOS comes with a version of PHP pre-installed, but it is often outdated. The recommended way to get the latest PHP on macOS is through Homebrew:
brew install php
Check which version was installed:
php -v
To use a built-in development server (no Apache needed) for testing:
php -S localhost:8000
Then open http://localhost:8000 in your browser to see your PHP files run.
php -S) is intended for
development and testing only. It is not suitable for production use.
| Tool | OS | Includes Apache | Includes MySQL | Best For |
|---|---|---|---|---|
| Laragon | Windows | ✔ Yes | ✔ Yes | Fast, modern Windows dev |
| XAMPP | All platforms | ✔ Yes | ✔ Yes | Cross-platform beginners |
| MAMP | macOS, Windows | ✔ Yes | ✔ Yes | macOS developers |
| apt install | Linux | ✔ Yes | ✔ Yes | Linux server setup |
| php -S | All platforms | ✘ Built-in only | ✘ No | Quick testing only |
After setting up your server, create a file called info.php inside your web
root folder (www, htdocs, or /var/www/html) with
the following content:
<?php
phpinfo();
?>
Then open your browser and visit:
http://localhost/info.php
If PHP is installed and running correctly, you will see a detailed PHP information page with your version number, configuration settings, and enabled extensions.
info.php after you have
confirmed PHP is working. Leaving it on a public server exposes sensitive information
about your server configuration.
.php
files by double-clicking them like HTML filessudo apt install php apache2 to get started quicklyphpinfo() pageinfo.php from any public-facing server after testing