Getting Started: Environment Setup
Last updated: April 6, 2026 Minimum PHP Version: PHP 7.4+ Status: Stable
Overview
Before writing PHP code, you need PHP installed on your computer. This guide walks you through installation for Windows, Mac, and Linux. We'll also set up a simple web server so you can run PHP scripts.
Windows Installation
Option 1: Xampp (Easiest - Recommended)
- Download XAMPP from apachefriends.org
- Download the PHP 8.2 version
- Run the installer and follow the wizard
- Select components: Apache, MySQL, PHP (minimum)
- Install to
C:\xampp(default location) - After install, open XAMPP Control Panel
- Click "Start" next to Apache and MySQL
Test it:
- Create C:\xampp\htdocs\test.php
- Add content:
<?php
echo "Hello, PHP!";
?>
http://localhost/test.php in your browser
- You should see: Hello, PHP!
Option 2: Windows PHP Standalone
- Download PHP from php.net
- Choose the "Windows Downloads" → "Thread Safe" version
- Extract to
C:\php - Add
C:\phpto your system PATH - Open Command Prompt and verify:
php --version
Option 3: Windows Subsystem for Linux (WSL)
If you're comfortable with Linux:
# Install WSL2 first, then in WSL terminal:
sudo apt update
sudo apt install php php-cli php-mysql
php --version
Mac Installation
Option 1: Homebrew (Recommended)
# Install Homebrew if you don't have it
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install PHP
brew install php
# Verify
php --version
Option 2: Using MAMP
- Download MAMP for Mac
- Install to Applications
- Launch MAMP
- Click "Start Servers"
- Create files in
MAMP/htdocs/
Option 3: Docker
docker run -p 8000:80 -v /path/to/files:/var/www/html php:8.2-apache
Linux Installation
Ubuntu/Debian
# Update package list
sudo apt update
# Install PHP and Apache
sudo apt install php apache2
# Enable PHP module
sudo a2enmod php8.2
# Restart Apache
sudo systemctl restart apache2
# Verify
php --version
Fedora/RHEL
# Install PHP
sudo dnf install php php-common php-fpm
# Verify
php --version
Start a Development Server
Once installed, start the built-in PHP server:
# Navigate to your project directory
cd ~/my-project
# Start server on port 8000
php -S localhost:8000
# Visit http://localhost:8000 in browser
Testing Your Installation
Create a file phpinfo.php:
<?php
phpinfo();
?>
Put it in your web root (htdocs, public_html, or current directory) and visit it in your browser. You should see detailed PHP configuration information.
Recommended Development Setup
Text Editors / IDEs
Choose one: - VS Code (free, lightweight) + PHP Intelephense extension - PhpStorm (paid, full-featured) - Sublime Text (free, very fast) - Vim/Nano (terminal-based, powerful)
For This Guide
We recommend VS Code + XAMPP:
1. Install XAMPP for local server
2. Install VS Code from code.visualstudio.com
3. Install "PHP Intelephense" extension in VS Code
4. Create files in C:\xampp\htdocs\
Troubleshooting
Port 80/8000 already in use?
# Use different port
php -S localhost:8001
Can't find PHP command?
- Windows: Verify PATH environment variable
- Mac/Linux: Try /usr/local/bin/php --version
Apache won't start in XAMPP? - Port 80 conflict - change port in XAMPP config - Run as Administrator on Windows
Permission denied errors on Mac/Linux?
# Make files readable
chmod 755 filename.php
Next Steps
- ✅ PHP installed and running
- ⏳ Your First Script - Write PHP code
- ⏳ Continue with Basics: Variables
Related Topics
- Control Flow - Make decisions
- Functions - Write reusable code
See Also
Once installed, move to Your First Script!