So you want to start coding in PHP but don’t know where to begin?
No worries! ❤️ In this guide, I’ll walk you through how to set up your local PHP development environment using tools like XAMPP, LAMP, or MAMP.
No more messing with complicated terminal commands (unless you want to 😉). Let’s keep it simple and fun!
🧠 What’s a PHP Development Environment?
When you’re coding PHP, your browser can’t run PHP files on its own—it needs a server. That’s where a local development environment comes in.
You need 3 main things:
- PHP – the scripting language
- MySQL/MariaDB – the database engine
- Apache or Nginx – the web server
Instead of installing these separately, we use bundles like XAMPP, MAMP, or LAMP that include everything!
💻 Option 1: XAMPP (Windows, macOS, Linux)
XAMPP stands for:
X = Cross-platform
A = Apache
M = MySQL
P = PHP
P = Perl
🔧 Steps to Install XAMPP:
- Download XAMPP
Go to https://www.apachefriends.org
Choose your OS and download the installer. - Install XAMPP
Run the installer and follow the prompts (you can skip Perl). - Open XAMPP Control Panel
Start Apache and MySQL. - Create a PHP File
Go to thehtdocs
folder:
On Windows:
C:\xampp\htdocs
Create a file called index.php
:
<?php
echo "Hello from PHP!";
?>
- Open in Browser
Go to:
http://localhost/index.php
🎉 You should see:
Hello from PHP!
🐧 Option 2: LAMP Stack (Linux)
LAMP = Linux + Apache + MySQL + PHP
Perfect if you’re using Ubuntu, Debian, or any other Linux distro.
🔧 Steps to Install LAMP on Ubuntu:
Open your terminal and run:
sudo apt update
sudo apt install apache2
sudo apt install mysql-server
sudo apt install php libapache2-mod-php php-mysql
Restart Apache:
sudo systemctl restart apache2
Create your PHP file:
sudo nano /var/www/html/index.php
Paste this:
<?php
echo "Hello from LAMP!";
?>
Save it, then go to browser and type below URL:
http://localhost/index.php
Boom 💥! You’re now running PHP on Linux.
🍏 Option 3: MAMP (macOS and Windows)
MAMP is great for Mac users (also works on Windows).
🔧 Steps to Install MAMP:
- Download it from https://www.mamp.info
- Install it like a regular Mac app
- Open MAMP, then click Start Servers
- Go to terminal and type this:
/Applications/MAMP/htdocs
- Create a new file:
hello.php
<?php
echo "Hi from MAMP!";
?>
- Visit in browser:
http://localhost:8888/hello.php
You’re good to go! 🍎
💬 Quick Comparison
Feature | XAMPP | LAMP | MAMP |
---|---|---|---|
OS | All | Linux only | macOS / Win |
Interface | GUI | CLI | GUI |
Beginner-Friendly | ✅ | ⚠️ Intermediate | ✅ |
🧪 Bonus: Use PHP Built-in Server (No Apache Needed)
If you have PHP installed already (e.g. via Homebrew, Chocolatey, or manually), you can run:
php -S localhost:8000
Put your files in that directory, and open http://localhost:8000
Super useful for testing small projects!
🙌 Wrapping Up
Setting up PHP on your local machine doesn’t have to be scary. Whether you go with XAMPP, LAMP, or MAMP, you now have the power to build dynamic, database-driven websites right from your computer.
So go ahead — open that code editor, fire up your server, and start writing PHP like a champ! 💪
Leave a Reply