Installing PHP is the first step to building dynamic web applications. Whether you're using Windows, macOS, or Linux, PHP can be set up quickly with the right tools.
This guide covers traditional installation methods and a modern approach using Docker.
What You Need Before Installing PHP
- A computer running Windows, macOS, or Linux
- Administrator (or sudo) access
- Basic command-line knowledge
Install PHP on Windows
Option 1: Using XAMPP (Recommended for beginners)
- Download XAMPP
- Run the installer
- Start Apache
Option 2: Manual Installation
- Download PHP
- Extract to
C:\php - Add to PATH
php -v
Install PHP on macOS
Using Homebrew
brew update
brew install php
Install PHP on Linux
Ubuntu / Debian
sudo apt update
sudo apt install php
Install PHP with Docker (Recommended for modern development)
Docker allows you to run PHP without installing it directly on your system. This is ideal for consistent environments and team projects.
1. Install Docker
Download and install Docker Desktop or Docker Engine.
2. Run PHP container
docker run --rm php:8.3-cli php -v
This runs PHP instantly without installation.
3. Run PHP script
docker run --rm -v $(pwd):/app -w /app php:8.3-cli php index.php
4. Run PHP with built-in server
docker run -p 8000:8000 -v $(pwd):/app -w /app php:8.3-cli php -S 0.0.0.0:8000
Open in browser:
http://localhost:8000
5. Using Docker Compose (recommended)
services:
php:
image: php:8.3-cli
volumes:
- .:/app
working_dir: /app
command: php -S 0.0.0.0:8000
Run:
docker compose up
Install PHP with Web Server
Apache
sudo apt install apache2 php libapache2-mod-php
Nginx + PHP-FPM
sudo apt install nginx php-fpm
Test PHP Installation
<?php
phpinfo();
Open:
http://localhost
Common Issues
PHP not found
Add PHP to PATH.
Port conflict
Use another port like 8080.
Docker permission issues
Run Docker with proper permissions or sudo.
Best Practices
- Use latest PHP version
- Prefer Docker for consistency
- Use Composer for dependencies
FAQ
Is Docker better than local installation?
For most modern workflows, yes. It ensures consistency and avoids system conflicts.
Do I need PHP installed if I use Docker?
No. Docker runs PHP inside containers.
Which method should I choose?
Beginners → XAMPP. Developers → Docker.
Conclusion
You can install PHP locally or use Docker for a cleaner and more flexible setup. Both approaches work — choose based on your workflow.