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:

ComponentPurpose
Web Server (Apache/Nginx)Executes PHP code and serves web pages
PHP InterpreterProcesses PHP scripts on the server
Database (MySQL/MariaDB)Stores dynamic data like users, products, etc.
BrowserDisplays 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:

  1. Download XAMPP:

  2. Install XAMPP:

    • Run the installer and follow the setup wizard.

    • Select components: Apache, MySQL, PHP, phpMyAdmin.

  3. Start Apache and MySQL:

    • Open XAMPP Control Panel.

    • Click Start next to Apache and MySQL.

  4. Verify Installation:

    • Open your browser and go to:
      http://localhost/

    • If you see the XAMPP welcome page —  PHP is working.

  5. Create Your First PHP File:

    • Go to C:\xampp\htdocs\

    • Create a file named test.php

    • Add 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:

  1. Go to https://www.wampserver.com

  2. Download WAMP for your Windows version (64-bit or 32-bit).

  3. Run the installer and follow the prompts.

  4. Once installed, open the WAMP Control Panel.

  5. Start Apache and MySQL services.

  6. 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):

  1. Update your system:

     
    sudo apt update
  2. Install Apache:

     
    sudo apt install apache2
  3. Install MySQL:

     
    sudo apt install mysql-server
  4. Install PHP:

     
    sudo apt install php libapache2-mod-php php-mysql
  5. Restart Apache:

     
    sudo systemctl restart apache2
  6. Verify Installation:

    • Create a test file in /var/www/html/:

       
      sudo nano /var/www/html/info.php
    • Add 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:

  1. Install Docker:

  2. Create a Project Folder:

     
    mkdir my-php-app cd my-php-app
  3. Create a Dockerfile:

     
    FROM php:8.2-apache COPY . /var/www/html/ EXPOSE 80
  4. Add a PHP file (index.php):

     
    <?php echo "Hello from PHP in Docker!"; ?>
  5. Build and Run the Container:

     
    docker build -t my-php-app . docker run -p 8080:80 my-php-app
  6. View in Browser:
    http://localhost:8080

You’ll see “Hello from PHP in Docker!”

Comparing PHP Environment Options

EnvironmentPlatformBest ForEase of UsePerformance
XAMPPWindows, Mac, LinuxBeginners & Students⭐⭐⭐⭐⭐⭐⭐⭐⭐
WAMPWindowsWindows users⭐⭐⭐⭐⭐⭐⭐⭐
LAMPLinuxDevelopers, Servers⭐⭐⭐⭐⭐⭐⭐⭐
DockerCross-PlatformAdvanced 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 .php and accessed through localhost.