Why Install PHP Locally?
Local PHP development gives you a fast, offline workspace where you can experiment without uploading to a server every few minutes. You can run multiple PHP versions side-by-side, inspect errors instantly, and integrate with editors like VS Code or PhpStorm.
You have three common options:
- All-in-one stacks (XAMPP, Laragon, MAMP) - bundle Apache + MySQL + PHP
- Package managers (Homebrew, apt, yum) - install raw PHP, configure manually
- Docker - run PHP inside a container (covered in the Docker tutorial)
If you are new, install XAMPP (cross-platform) or Laragon (Windows). They give you a working PHP + MySQL stack with one installer and a control panel to start/stop services.
Install PHP on Windows
Option A: XAMPP (recommended for beginners)
- Download XAMPP from
apachefriends.org. - Run the installer. Accept defaults - it installs to
C:\xampp. - Open the XAMPP Control Panel. Click Start next to Apache and MySQL.
- Put your PHP files inside
C:\xampp\htdocs\. - Visit
http://localhost/yourfile.phpin your browser.
Option B: Laragon (lighter, more modern)
- Download Laragon Full from
laragon.org. - Install. Laragon auto-detects Apache/Nginx, PHP, MySQL, and Composer.
- Project files go in
C:\laragon\www\- each folder becomes a virtual host automatically.
Option C: Standalone PHP
If you only need the PHP CLI:
# Download PHP 8.3 (Thread Safe) from windows.php.net
# Extract to C:\php
# Add to PATH (run as Administrator)
$env:Path += ";C:\php"
[Environment]::SetEnvironmentVariable("Path", $env:Path, "Machine")
# Verify
php -v
After editing the PATH, close and reopen your terminal. The new PATH only applies to new shell sessions.
Install PHP on macOS
Using Homebrew (recommended)
# Install Homebrew first (if missing)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install latest PHP
brew install php
# Or pick a specific version
brew install php@8.2
# Verify
php -v
Using MAMP (GUI alternative)
Download MAMP from mamp.info. It installs Apache + MySQL + PHP under /Applications/MAMP/ with a control panel similar to XAMPP.
Install PHP on Linux
Ubuntu / Debian
# Add Ondrej PPA for the latest PHP versions
sudo add-apt-repository ppa:ondrej/php
sudo apt update
# Install PHP 8.3 with common extensions
sudo apt install -y php8.3 php8.3-cli php8.3-mysql php8.3-curl \
php8.3-mbstring php8.3-xml php8.3-zip
# Verify
php -v
CentOS / RHEL / Fedora
# Enable Remi repository
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm
sudo dnf module enable -y php:remi-8.3
sudo dnf install -y php php-cli php-mysqlnd php-mbstring php-xml
php -v
Verify Your Installation
Open a terminal (CMD/PowerShell/Bash) and run:
php -v
php -m # list loaded extensions
php --ini # find which php.ini is loaded
If you see a version number, PHP is installed correctly.
Configuring php.ini
php.ini is PHP's main configuration file. Find it with php --ini and open it in any text editor. The most useful settings for local development:
; Show all errors while developing
display_errors = On
error_reporting = E_ALL
; Increase limits for file uploads and long scripts
upload_max_filesize = 64M
post_max_size = 64M
memory_limit = 256M
max_execution_time = 300
; Set your timezone (avoids warnings)
date.timezone = Asia/Kolkata
; Enable common extensions
extension=mysqli
extension=pdo_mysql
extension=mbstring
extension=curl
extension=gd
extension=zip
Restart Apache or PHP-FPM for changes to take effect. For the CLI (php -S), every invocation reloads php.ini automatically.
Run Your First PHP File
Create a file called hello.php:
<?php
echo "PHP is working! Version: " . PHP_VERSION;
Option 1: via Apache - save to htdocs/hello.php and visit http://localhost/hello.php.
Option 2: via PHP built-in server (no Apache needed):
cd /folder/with/hello.php
php -S localhost:8000
# Visit http://localhost:8000/hello.php
Option 3: via CLI directly:
php hello.php
Common Installation Errors
PHP is not in your PATH. Add the PHP install folder (e.g. C:\xampp\php or /usr/local/php/bin) to your system PATH and restart the terminal.
Another service (often IIS, Skype, or Windows World Wide Web Publishing Service) is using port 80. Either stop it from the Services panel, or change Apache to port 8080 in httpd.conf and visit http://localhost:8080.
The mysqli extension is not enabled. Open php.ini, uncomment extension=mysqli, then restart your web server.
Next Steps
PHP is installed and working. Time to write some code: