78
1
0
How to Install PHP on Any OS - Windows, macOS, Linux

How to Install PHP on Any OS - Windows, macOS, Linux

Published on June 26, 2025 by OBSCountdown Editorial

How to Install PHP on Any OS - Windows, macOS, Linux

A complete beginner's guide to setting up PHP using XAMPP, MAMP, Docker, Laragon, or manual installation methods.

πŸ“Œ Why Learn to Install PHP?

PHP powers millions of websites and is essential for web developers who want to build server-side applications. Whether you’re planning to build a blog, a content management system, or a REST API, PHP is a reliable and easy-to-learn language.

But before you can code in PHP, you need a working development environment. In this guide, you'll learn multiple ways to install PHP across Windows, macOS, and Linux, including easy bundled environments like XAMPP and flexible containerized setups like Docker.

🧭 Table of Contents

πŸ”§ Option 1: Install PHP with XAMPP

XAMPP is an easy-to-use package that includes PHP, Apache, MySQL, and more. It’s available on Windows, macOS, and Linux.

βœ… Steps:

  1. Go to the official XAMPP website: apachefriends.org
  2. Download the version for your OS.
  3. Install XAMPP and follow the setup wizard.
  4. Launch the XAMPP Control Panel.
  5. Start the Apache module.
  6. Place your PHP files inside the htdocs folder (e.g., C:\xampp\htdocs\myproject\index.php).
  7. Open a browser and go to http://localhost/myproject to run your script.

Pros: All-in-one package, great for beginners, simple UI.

Cons: Slightly heavier footprint compared to minimal installs.

πŸͺŸ Option 2: Install PHP with Laragon (Windows Only)

Laragon is a modern alternative to XAMPP for Windows users. It’s lightweight, portable, and supports multiple PHP versions.

βœ… Steps:

  1. Visit: laragon.org
  2. Download and install the full version.
  3. Start Apache or Nginx from Laragon's panel.
  4. Use the www directory to place your PHP files (e.g., www/test/index.php).
  5. Open http://localhost/test in your browser.

Pros: Fast, modern interface, easy switch between PHP versions.

Cons: Windows-only.

🍏 Option 3: Install PHP with MAMP (macOS/Windows)

MAMP is ideal for macOS users who want a simple PHP/Apache/MySQL stack. A Windows version is also available.

βœ… Steps:

  1. Download MAMP from: mamp.info
  2. Install and launch the MAMP app.
  3. Click Start Servers to start Apache and MySQL.
  4. Place PHP files in the htdocs directory.
  5. Visit http://localhost:8888 to view your project.

Pros: Reliable for macOS users, includes GUI tools.

Cons: Free version is limited compared to MAMP PRO.

🐳 Option 4: Install PHP Using Docker (Cross-Platform)

Docker allows you to run PHP in a container, ideal for consistency across machines and deploying apps.

βœ… Prerequisites:

βœ… Example Docker Command:

docker run -d -p 8080:80 -v ${PWD}:/var/www/html php:8.2-apache

This command pulls the official PHP+Apache image, maps your current directory to the container, and serves files on localhost:8080.

Pros: Professional-grade setup, replicable environments.

Cons: Learning curve for Docker newbies.

πŸ” Option 5: Manual PHP Installation

Advanced users may want to install PHP manually for more control.

βœ… On Windows:

  1. Download PHP from windows.php.net
  2. Extract files to C:\php or a custom path.
  3. Add PHP to the Windows PATH environment variable.
  4. Verify by opening a terminal and running php -v.

βœ… On macOS:

  1. Install Homebrew from brew.sh
  2. Run: brew install php
  3. Verify with: php -v

βœ… On Linux (Ubuntu):

sudo apt update
sudo apt install php

Pros: Full control, minimal setup.

Cons: Requires command-line usage and configuration.

πŸ§ͺ How to Verify PHP Installation

After installation, create a file named info.php in your web root with the following content:

<?php phpinfo(); ?>

Open http://localhost/info.php in your browser. You should see a detailed PHP info page.

πŸš€ What to Do After Installing PHP

  • Create your first PHP script: echo "Hello, World!";
  • Learn about PHP variables, loops, and functions.
  • Connect PHP to a database like MySQL or SQLite.
  • Experiment with form handling, sessions, and file uploads.

Want to go further? Use frameworks like Laravel or CodeIgniter for building robust applications faster.


Tags: install PHP, XAMPP PHP, PHP setup, PHP on Windows, PHP on macOS, PHP on Linux, beginner PHP guide

πŸ“š Stay tuned for more PHP tutorials on installing Composer, using databases, and building your first web app!

Comments (0)

No comments yet. Be the first to comment!

Leave a Comment
Replying to someone's comment. Cancel
78
1
0
Join Our OBS Community

Loading...

Join Now