PHP Installation & Setup

Install PHP 8.3 locally on Windows, macOS, and Linux. Verify your install, edit php.ini, and run your very first PHP file in under 10 minutes.

Beginner 8 min read 5 examples

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)
Beginner-friendly recommendation

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)

  1. Download XAMPP from apachefriends.org.
  2. Run the installer. Accept defaults - it installs to C:\xampp.
  3. Open the XAMPP Control Panel. Click Start next to Apache and MySQL.
  4. Put your PHP files inside C:\xampp\htdocs\.
  5. Visit http://localhost/yourfile.php in your browser.

Option B: Laragon (lighter, more modern)

  1. Download Laragon Full from laragon.org.
  2. Install. Laragon auto-detects Apache/Nginx, PHP, MySQL, and Composer.
  3. 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:

PowerShell install.ps1
# 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
Windows PATH gotcha

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)

Bash terminal
# 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

Bash terminal
# 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

Bash terminal
# 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:

Bash
php -v
php -m       # list loaded extensions
php --ini    # find which php.ini is loaded
PHP 8.3.4 (cli) (built: Mar 14 2024 06:32:00) (NTS) Copyright (c) The PHP Group Zend Engine v4.3.4, Copyright (c) Zend Technologies with Zend OPcache v8.3.4

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:

INI php.ini
; 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
After editing php.ini

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 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):

Bash
cd /folder/with/hello.php
php -S localhost:8000
# Visit http://localhost:8000/hello.php

Option 3: via CLI directly:

Bash
php hello.php

Common Installation Errors

"php is not recognized as an internal command"

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.

"Port 80 is already in use" in XAMPP

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.

"Class 'mysqli' not found"

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:

Frequently Asked Questions

Use XAMPP if you want a cross-platform one-click installer (Windows/Mac/Linux). Use Laragon on Windows for a faster, lighter, developer-friendly stack with built-in Composer and Node. Use Homebrew on Mac for command-line control. Choose apt or yum on Linux servers.

Always install the latest stable PHP 8.x (currently 8.3). PHP 7.x reached end-of-life in November 2022 and no longer receives security patches. Modern frameworks like Laravel 11 and Symfony 7 require PHP 8.2+.

XAMPP and Laragon bundle Apache + MySQL + PHP together, which is the easiest path for beginners. If you only need PHP for CLI scripts or use PHP's built-in dev server (php -S), you can skip Apache entirely.

On Mac use brew install php@8.2 and brew link --force --overwrite php@8.2. On Linux use update-alternatives --set php /usr/bin/php8.3. On Windows, Laragon has a built-in version switcher under PHP > Version.

PHP is installed but not in your PATH. On Windows, add C:\xampp\php (or your install path) to System Environment Variables. On Mac/Linux, add export PATH="/usr/local/php/bin:$PATH" to ~/.zshrc or ~/.bashrc and restart the terminal.