How to Install PHP on Any OS - Windows, macOS, Linux
A complete beginner's guide to setting up PHP using XAMPP, MAMP, Docker, Laragon, or manual installation methods.
π Why Learn to Install PHP?
PHP powers millions of websites and is essential for web developers who want to build server-side applications. Whether youβre planning to build a blog, a content management system, or a REST API, PHP is a reliable and easy-to-learn language.
But before you can code in PHP, you need a working development environment. In this guide, you'll learn multiple ways to install PHP across Windows, macOS, and Linux, including easy bundled environments like XAMPP and flexible containerized setups like Docker.
π§ Table of Contents
π§ Option 1: Install PHP with XAMPP
XAMPP is an easy-to-use package that includes PHP, Apache, MySQL, and more. Itβs available on Windows, macOS, and Linux.
β Steps:
- Go to the official XAMPP website: apachefriends.org
- Download the version for your OS.
- Install XAMPP and follow the setup wizard.
- Launch the XAMPP Control Panel.
- Start the Apache module.
- Place your PHP files inside the
htdocs
folder (e.g.,C:\xampp\htdocs\myproject\index.php
). - Open a browser and go to
http://localhost/myproject
to run your script.
Pros: All-in-one package, great for beginners, simple UI.
Cons: Slightly heavier footprint compared to minimal installs.
πͺ Option 2: Install PHP with Laragon (Windows Only)
Laragon is a modern alternative to XAMPP for Windows users. Itβs lightweight, portable, and supports multiple PHP versions.
β Steps:
- Visit: laragon.org
- Download and install the full version.
- Start Apache or Nginx from Laragon's panel.
- Use the
www
directory to place your PHP files (e.g.,www/test/index.php
). - Open
http://localhost/test
in your browser.
Pros: Fast, modern interface, easy switch between PHP versions.
Cons: Windows-only.
π Option 3: Install PHP with MAMP (macOS/Windows)
MAMP is ideal for macOS users who want a simple PHP/Apache/MySQL stack. A Windows version is also available.
β Steps:
- Download MAMP from: mamp.info
- Install and launch the MAMP app.
- Click Start Servers to start Apache and MySQL.
- Place PHP files in the
htdocs
directory. - Visit
http://localhost:8888
to view your project.
Pros: Reliable for macOS users, includes GUI tools.
Cons: Free version is limited compared to MAMP PRO.
π³ Option 4: Install PHP Using Docker (Cross-Platform)
Docker allows you to run PHP in a container, ideal for consistency across machines and deploying apps.
β Prerequisites:
- Install Docker Desktop from docker.com
β Example Docker Command:
docker run -d -p 8080:80 -v ${PWD}:/var/www/html php:8.2-apache
This command pulls the official PHP+Apache image, maps your current directory to the container, and serves files on localhost:8080
.
Pros: Professional-grade setup, replicable environments.
Cons: Learning curve for Docker newbies.
π Option 5: Manual PHP Installation
Advanced users may want to install PHP manually for more control.
β On Windows:
- Download PHP from windows.php.net
- Extract files to
C:\php
or a custom path. - Add PHP to the Windows PATH environment variable.
- Verify by opening a terminal and running
php -v
.
β On macOS:
- Install Homebrew from brew.sh
- Run:
brew install php
- Verify with:
php -v
β On Linux (Ubuntu):
sudo apt update
sudo apt install php
Pros: Full control, minimal setup.
Cons: Requires command-line usage and configuration.
π§ͺ How to Verify PHP Installation
After installation, create a file named info.php
in your web root with the following content:
<?php phpinfo(); ?>
Open http://localhost/info.php
in your browser. You should see a detailed PHP info page.
π What to Do After Installing PHP
- Create your first PHP script:
echo "Hello, World!";
- Learn about PHP variables, loops, and functions.
- Connect PHP to a database like MySQL or SQLite.
- Experiment with form handling, sessions, and file uploads.
Want to go further? Use frameworks like Laravel or CodeIgniter for building robust applications faster.
Tags: install PHP, XAMPP PHP, PHP setup, PHP on Windows, PHP on macOS, PHP on Linux, beginner PHP guide
π Stay tuned for more PHP tutorials on installing Composer, using databases, and building your first web app!