PHP Installation
This guide helps you install and verify PHP on Windows, Linux, and macOS using popular stacks:
XAMPP, WAMP, LAMP, and MAMP. We’ll also configure php.ini, enable common extensions,
install Composer, and run your first PHP file.
Which Stack Should I Use?
| Stack | Platform | Includes | Best for |
|---|---|---|---|
| XAMPP | Windows / Linux / macOS | Apache, MySQL/MariaDB, PHP, Perl | Beginner-friendly, cross-platform |
| WAMP | Windows | Apache, MySQL/MariaDB, PHP | Windows-only lightweight dev |
| LAMP | Linux | Apache, MySQL/MariaDB, PHP | Most common on servers |
| MAMP | macOS | Apache, MySQL, PHP | Mac local development |
1) Install PHP with XAMPP (Windows / Linux / macOS)
- Download XAMPP from the official website and choose your OS.
- Install with default settings. On Windows, install to
C:\xampp. - Open XAMPP Control Panel → start Apache and MySQL.
- Open http://localhost in your browser — you should see the XAMPP dashboard.
- Create a project folder in
C:\xampp\htdocs\myapp(Windows) or/Applications/XAMPP/xamppfiles/htdocs/myapp(macOS).
Test with Hello World
<?php
// file: C:\xampp\htdocs\myapp\index.php
echo "XAMPP is working!";
?>
Visit http://localhost/myapp/ — you should see the message.
htdocs lives under /opt/lampp/htdocs.2) Install PHP with WAMP (Windows)
- Download WAMP (64-bit) and install to
C:\wamp64. - Start WAMP: green tray icon should appear (Apache + MySQL + PHP running).
- Project root:
C:\wamp64\www\myapp. - Open http://localhost/ to verify WAMP homepage.
Test with Hello World
<?php
// file: C:\wamp64\www\myapp\index.php
echo "WAMP is working!";
?>
3) Install LAMP (Linux: Ubuntu/Debian)
Update packages & install
$ sudo apt update
$ sudo apt install apache2 php libapache2-mod-php php-mysql mariadb-server
Check versions
$ php -v
$ apache2 -v
$ mysql --version
Create a test file
$ echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
$ sudo systemctl restart apache2
Visit http://localhost/info.php to see PHP info page.
4) Install MAMP (macOS)
- Download MAMP for macOS and install (default:
/Applications/MAMP). - Open MAMP app → Start Servers.
- Project root:
/Applications/MAMP/htdocs/myapp. - MAMP homepage: http://localhost:8888/
Test with Hello World
<?php
// file: /Applications/MAMP/htdocs/myapp/index.php
echo "MAMP is working!";
?>
Verify PHP from Command Line (All OS)
$ php -v
PHP 8.x.x (cli) (built: ...)
php is not found, add the PHP folder to your system PATH (see below).Common Paths
| Stack | Document Root | PHP Executable |
|---|---|---|
| XAMPP (Win) | C:\xampp\htdocs | C:\xampp\php\php.exe |
| WAMP (Win) | C:\wamp64\www | C:\wamp64\bin\php\phpX.Y.Z\php.exe |
| LAMP (Linux) | /var/www/html | /usr/bin/php |
| MAMP (macOS) | /Applications/MAMP/htdocs | /Applications/MAMP/bin/php/phpX.Y.Z/bin/php |
Set PATH for PHP (Optional)
Windows: Add C:\xampp\php or your WAMP PHP folder to Environment Variables → Path, then restart terminal.
Linux/macOS: Add to shell profile:
$ echo 'export PATH="/usr/bin:$PATH"' >> ~/.bashrc
$ source ~/.bashrc
Configure php.ini
Where is php.ini?
- XAMPP (Win):
C:\xampp\php\php.ini - WAMP (Win): via tray icon → PHP → php.ini
- LAMP (Linux):
/etc/php/8.x/apache2/php.ini(version may vary) - MAMP (macOS):
/Applications/MAMP/bin/php/phpX.Y.Z/conf/php.ini
Useful settings
; development friendly
display_errors = On
error_reporting = E_ALL
date.timezone = Asia/Kolkata
upload_max_filesize = 20M
post_max_size = 25M
memory_limit = 256M
php.ini.Enable Common Extensions
Uncomment (remove ;) in php.ini:
;extension=curl ; remove leading ';'
;extension=mysqli
;extension=openssl
;extension=gd
After enabling, restart Apache. Verify via phpinfo() page.
Create Your First Project
- Create folder
myappinside the document root (see table above). - Create
index.php:
<?php
// Simple routing-style example
$name = $_GET['name'] ?? 'Guest';
echo "Hello, {$name}!";
?>
Open http://localhost/myapp/?name=Sonu
Install Composer (PHP Package Manager)
Windows (XAMPP/WAMP): Download Composer installer and point it to your php.exe. Then:
$ composer -V
Composer version X.Y.Z
Linux/macOS:
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
$ php composer-setup.php --install-dir=/usr/local/bin --filename=composer
$ composer -V
Optional: Virtual Hosts (Clean URLs)
Apache vhost example (Windows XAMPP)
<VirtualHost *:80>
ServerName myapp.local
DocumentRoot "C:/xampp/htdocs/myapp/public"
<Directory "C:/xampp/htdocs/myapp/public">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Edit C:\Windows\System32\drivers\etc\hosts and add:
127.0.0.1 myapp.local
mod_rewrite in Apache for pretty URLs.Common Troubleshooting
- Port 80 in use: Stop conflicting services (IIS/Skype). Change Apache port to 8080 if needed.
- Blank page / 500 error: Enable errors in
php.ini(display_errors=On,error_reporting=E_ALL). - php not recognized (CLI): Add PHP folder to PATH.
- Extension missing: Enable in
php.iniand restart Apache. - Permission denied (Linux): Use
sudo chown -R www-data:www-data /var/www/htmlor appropriate user, and check file permissions.