How to Install PHP on Windows, macOS, and Linux (Beginner-Friendly Guide)
Last updated 4 months ago | 287 views 75 5

Introduction: Why PHP Installation Matters
Before you can write and run your first PHP script, you need to install PHP on your machine. Whether you're building dynamic websites, creating REST APIs, or running server-side applications, PHP must be properly configured in your local development environment.
This guide walks you through step-by-step PHP installation on all major operating systems: Windows, macOS, and Linux. We'll also cover how to verify the installation and run your first PHP script.
What You Need to Get Started
Before diving in, here’s a quick overview of what’s needed:
-
A computer running Windows, macOS, or Linux
-
Admin/root access
-
Internet connection
-
Optional: A code editor (VS Code, Sublime Text, etc.)
How to Install PHP on Windows
✅ Method 1: Install XAMPP (Recommended for Beginners)
XAMPP includes Apache, MySQL, and PHP—everything you need in one package.
Steps:
-
Download the XAMPP installer for Windows
-
Run the installer and follow the setup wizard
-
Select components: Apache, MySQL, PHP, phpMyAdmin
-
Launch XAMPP Control Panel
-
Start Apache (for PHP) and MySQL (optional)
PHP location:
C:\xampp\php\
To test:
Open http://localhost
in your browser.
✅ Method 2: Manual Installation (Advanced)
-
Download PHP zip package from https://windows.php.net/download/
-
Extract to
C:\php\
-
Add
C:\php
to System Environment Variables > PATH -
Create a
php.ini
file (copyphp.ini-development
and rename) -
Open terminal → run:
php -v
How to Install PHP on macOS
✅ Option 1: Use Homebrew (Recommended)
Steps:
-
Open Terminal
-
Install Homebrew (if not already):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-
Install PHP:
brew install php
-
Verify installation:
php -v
PHP is typically installed to:
/opt/homebrew/bin/php
(Apple Silicon)
/usr/local/bin/php
(Intel)
✅ Option 2: Use MAMP (GUI-based)
-
Download MAMP from https://www.mamp.info
-
Install it and run the app
-
MAMP also includes Apache and MySQL
How to Install PHP on Linux (Ubuntu/Debian)
✅ Steps:
-
Open Terminal
-
Update package list:
sudo apt update
-
Install PHP:
sudo apt install php
-
Verify:
php -v
✅ To install additional PHP modules:
sudo apt install php-mysql php-curl php-xml php-mbstring
PHP config file: /etc/php/{version}/apache2/php.ini
How to Verify PHP Installation
Run this command in terminal:
php -v
You should see something like:
PHP 8.3.6 (cli) (built: Jun 1 2025 10:02:45) ( NTS )
Create and Run Your First PHP Script
✅ 1. Create a file test.php
with the following content:
<?php
echo "PHP is working!";
?>
✅ 2. Move it to your web server directory:
-
XAMPP (Windows):
C:\xampp\htdocs\test.php
-
macOS/Linux (Apache):
/var/www/html/test.php
✅ 3. Open browser and visit:
http://localhost/test.php
You should see:
PHP is working!
⚠️ Tips & Common Pitfalls
✅ Tips:
-
Use XAMPP or MAMP for faster setup if you’re new.
-
Always check
php.ini
for tweaking settings like upload size, memory limits, etc. -
Install extensions only when needed to avoid performance overhead.
-
Use the latest stable version of PHP for security and performance.
❌ Pitfalls:
-
Missing PHP in PATH variable (CLI won’t work).
-
Forgetting to restart Apache after editing
php.ini
. -
Mixing multiple versions of PHP in PATH.
-
Editing the wrong
php.ini
file if multiple versions are installed.
Quick Comparison Table
Platform | Recommended Tool | CLI Command | GUI Available | Ease of Setup |
---|---|---|---|---|
Windows | XAMPP | php -v |
Yes | ⭐⭐⭐⭐⭐ |
macOS | Homebrew | php -v |
MAMP | ⭐⭐⭐⭐ |
Linux | apt/yum | php -v |
No | ⭐⭐⭐⭐ |
Summary & Best Practices
Installing PHP is the first step in building modern web applications. The right setup ensures a smooth development experience and avoids frustrating bugs later on.
Best Practices:
-
Use a stack installer (XAMPP, MAMP) for quick setup.
-
Use Homebrew or apt for lightweight, command-line control.
-
Regularly run
php -v
to confirm installation/version. -
Keep PHP updated to stay protected from vulnerabilities.
✅ Final Thoughts
Now that you've successfully installed PHP, you're ready to start building! From handling forms to interacting with databases, the world of PHP is wide open.
Next step? Try connecting PHP with MySQL, build a simple login system, or create your own CMS. Want help with that too? Just ask!