Setting Up PHP Environment (XAMPP, WAMP, LAMP, and Docker) — Step-by-Step for Beginners
Introduction – Why Do You Need a PHP Environment?
Before writing and running PHP programs, you must set up a PHP environment on your computer.
PHP code cannot run directly in browsers like HTML or CSS — it needs:
A Web Server (like Apache or Nginx)
The PHP Interpreter
A Database (like MySQL or MariaDB)
Together, these components form a development stack that allows you to run, test, and build PHP applications locally.
Components of a PHP Development Environment
Let’s understand the core parts that make PHP run properly:
| Component | Purpose |
|---|---|
| Web Server (Apache/Nginx) | Executes PHP code and serves web pages |
| PHP Interpreter | Processes PHP scripts on the server |
| Database (MySQL/MariaDB) | Stores dynamic data like users, products, etc. |
| Browser | Displays the output of PHP scripts |
Instead of installing each part separately, we use ready-made stacks like XAMPP, WAMP, or LAMP that include all tools in one package.
Option 1 – Setting Up PHP Using XAMPP (Windows, macOS, Linux)
What is XAMPP?
XAMPP stands for:
X (Cross-platform) + Apache + MySQL + PHP + Perl
It is an all-in-one solution that includes everything you need to start developing PHP applications easily.
Steps to Install XAMPP:
Download XAMPP:
Choose your OS (Windows, macOS, Linux)
Download the installer file.
Install XAMPP:
Run the installer and follow the setup wizard.
Select components: Apache, MySQL, PHP, phpMyAdmin.
Start Apache and MySQL:
Open XAMPP Control Panel.
Click Start next to Apache and MySQL.
Verify Installation:
Open your browser and go to:
http://localhost/If you see the XAMPP welcome page — PHP is working.
Create Your First PHP File:
Go to
C:\xampp\htdocs\Create a file named
test.phpAdd this code:
<?php echo "PHP is running successfully!"; ?>Visit:
http://localhost/test.php
You’ll see “PHP is running successfully!” on your screen.
Option 2 – Setting Up PHP Using WAMP (Windows Only)
What is WAMP?
WAMP stands for:
Windows + Apache + MySQL + PHP
It’s similar to XAMPP but designed specifically for Windows users.
Steps to Install WAMP:
Download WAMP for your Windows version (64-bit or 32-bit).
Run the installer and follow the prompts.
Once installed, open the WAMP Control Panel.
Start Apache and MySQL services.
Open your browser → type:
http://localhost/
If the WAMP homepage appears, PHP is working perfectly.
PHP Files Location:C:\wamp\www\
Create a new PHP file:
<?php phpinfo(); ?> Visit: http://localhost/phpinfo.php
You’ll see all PHP configuration details.
Option 3 – Setting Up PHP Using LAMP (Linux)
What is LAMP?
LAMP stands for:
Linux + Apache + MySQL + PHP
This is the most common stack for Linux users and used in real web servers.
Steps to Install LAMP Stack (Ubuntu Example):
Update your system:
sudo apt updateInstall Apache:
sudo apt install apache2Install MySQL:
sudo apt install mysql-serverInstall PHP:
sudo apt install php libapache2-mod-php php-mysqlRestart Apache:
sudo systemctl restart apache2Verify Installation:
Create a test file in
/var/www/html/:sudo nano /var/www/html/info.phpAdd this code:
<?php phpinfo(); ?>Open in browser:
http://localhost/info.php
You’ll see your PHP configuration page.
Option 4 – Setting Up PHP Using Docker
What is Docker?
Docker is a containerization platform that lets you run PHP, MySQL, and Apache inside lightweight containers — without installing them on your system.
It’s ideal for developers and teams who want consistent environments across machines
Steps to Set Up PHP Using Docker:
Install Docker:
Visit https://www.docker.com
Download Docker Desktop for your OS.
Create a Project Folder:
mkdir my-php-app cd my-php-appCreate a
Dockerfile:FROM php:8.2-apache COPY . /var/www/html/ EXPOSE 80Add a PHP file (
index.php):<?php echo "Hello from PHP in Docker!"; ?>Build and Run the Container:
docker build -t my-php-app . docker run -p 8080:80 my-php-appView in Browser:
http://localhost:8080
You’ll see “Hello from PHP in Docker!”
Comparing PHP Environment Options
| Environment | Platform | Best For | Ease of Use | Performance |
|---|---|---|---|---|
| XAMPP | Windows, Mac, Linux | Beginners & Students | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ |
| WAMP | Windows | Windows users | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ |
| LAMP | Linux | Developers, Servers | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
| Docker | Cross-Platform | Advanced developers | ⭐⭐ | ⭐⭐⭐⭐⭐ |
Verifying PHP Installation
After installation, verify PHP is working by running this command:
Command Line Method:
php -v You should see something like:
PHP 8.2.10 (cli) (built: Sep 10 2025) This confirms PHP is installed successfully.
Troubleshooting Tips
Apache not starting?
→ Change port number from 80 to 8080 in Apache config.MySQL not connecting?
→ Check if MySQL service is running.PHP code not showing output?
→ Ensure file is saved as.phpand accessed throughlocalhost.