HTML CSS Bootstrap JavaScript jQuery MySQL PHP Data Mining

PHP Installation

To run PHP code on your computer, you need a local web server environment. PHP itself is a server-side language, which means it cannot run by simply opening a .php file in your browser the way an HTML file can. You need a proper server setup. This guide covers the easiest and most reliable ways to get started on Windows, macOS, and Linux.


What Do You Need?

A typical PHP development environment consists of three things working together:

  • A web server — Apache or Nginx, which handles incoming HTTP requests
  • PHP — the language engine that processes your .php files
  • A database — usually MySQL, for storing and retrieving data

You can install each of these separately, or use an all-in-one stack that bundles all three for you. For beginners, the all-in-one approach is almost always the better choice.


Supported Operating Systems

PHP runs on all major platforms. Choose the one that matches your computer:

🪟
Windows
🍎
macOS
🐧
Linux

Option 1: Using Laragon (Windows — Highly Recommended)

Laragon is a modern, lightweight local development environment for Windows. It bundles Apache, PHP, MySQL, and phpMyAdmin and gets you running in minutes — no complex configuration required.

Step-by-Step Installation

1
Download Laragon
Visit laragon.org/download and download the Full version (which includes Apache, PHP, MySQL, and phpMyAdmin).
2
Run the installer
Double-click the downloaded installer and follow the on-screen steps. The default settings work perfectly for most developers.
3
Start Laragon
Open Laragon and click the "Start All" button. This starts both Apache and MySQL at once.
4
Create your first PHP file
Place your .php files inside the C:\laragon\www\ folder. Open a browser and navigate to http://localhost to see them run.
Tip: Laragon automatically creates a local domain for each subfolder inside www\. For example, a folder named myproject becomes accessible at http://myproject.test — no manual configuration needed.

Option 2: Using XAMPP (Windows, macOS, Linux)

XAMPP is the most popular cross-platform PHP stack in the world. It includes Apache, PHP, MySQL (MariaDB), and phpMyAdmin, and works on all three major operating systems.

1
Download XAMPP
Go to apachefriends.org and download the XAMPP installer for your operating system.
2
Run the installer
Follow the installation wizard. You can keep the default installation path (C:\xampp on Windows).
3
Open the XAMPP Control Panel
Click Start next to Apache and MySQL. Both should show a green status.
4
Place your files
Save your .php files inside C:\xampp\htdocs\ (Windows) or /opt/lampp/htdocs/ (Linux). Access them at http://localhost/your-file.php.

Option 3: Manual PHP Installation on Linux

On Ubuntu or Debian-based Linux systems, you can install PHP directly using the package manager. Open your terminal and run:

Update Package Lists

sudo apt update

Install Apache and PHP

sudo apt install apache2 php libapache2-mod-php

Install MySQL (Optional)

sudo apt install mysql-server php-mysql

Restart Apache

sudo systemctl restart apache2

Your PHP files go inside /var/www/html/. Open a browser and visit http://localhost to confirm Apache is running.


Option 4: Manual PHP Installation on macOS

macOS comes with a version of PHP pre-installed, but it is often outdated. The recommended way to get the latest PHP on macOS is through Homebrew:

brew install php

Check which version was installed:

php -v

To use a built-in development server (no Apache needed) for testing:

php -S localhost:8000

Then open http://localhost:8000 in your browser to see your PHP files run.

Note: PHP's built-in server (php -S) is intended for development and testing only. It is not suitable for production use.

Choosing the Right Option

Tool OS Includes Apache Includes MySQL Best For
Laragon Windows ✔ Yes ✔ Yes Fast, modern Windows dev
XAMPP All platforms ✔ Yes ✔ Yes Cross-platform beginners
MAMP macOS, Windows ✔ Yes ✔ Yes macOS developers
apt install Linux ✔ Yes ✔ Yes Linux server setup
php -S All platforms ✘ Built-in only ✘ No Quick testing only

Verify Your PHP Installation

After setting up your server, create a file called info.php inside your web root folder (www, htdocs, or /var/www/html) with the following content:

<?php
    phpinfo();
?>

Then open your browser and visit:

http://localhost/info.php

If PHP is installed and running correctly, you will see a detailed PHP information page with your version number, configuration settings, and enabled extensions.

Security Tip: Delete or rename info.php after you have confirmed PHP is working. Leaving it on a public server exposes sensitive information about your server configuration.

Key Points to Remember

  • PHP is a server-side language — you cannot run .php files by double-clicking them like HTML files
  • For Windows beginners, Laragon or XAMPP is the fastest and easiest setup
  • On Linux, use sudo apt install php apache2 to get started quickly
  • On macOS, use Homebrew to install the latest PHP version
  • Always verify your install by creating a phpinfo() page
  • Delete info.php from any public-facing server after testing
What's next? With PHP installed and running, you are ready to write your first real PHP scripts. The next lesson covers PHP Syntax — the rules and patterns every PHP file follows.