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?

StackPlatformIncludesBest for
XAMPPWindows / Linux / macOSApache, MySQL/MariaDB, PHP, PerlBeginner-friendly, cross-platform
WAMPWindowsApache, MySQL/MariaDB, PHPWindows-only lightweight dev
LAMPLinuxApache, MySQL/MariaDB, PHPMost common on servers
MAMPmacOSApache, MySQL, PHPMac local development

1) Install PHP with XAMPP (Windows / Linux / macOS)

  1. Download XAMPP from the official website and choose your OS.
  2. Install with default settings. On Windows, install to C:\xampp.
  3. Open XAMPP Control Panel → start Apache and MySQL.
  4. Open http://localhost in your browser — you should see the XAMPP dashboard.
  5. 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.

Note: On Linux XAMPP, default htdocs lives under /opt/lampp/htdocs.

2) Install PHP with WAMP (Windows)

  1. Download WAMP (64-bit) and install to C:\wamp64.
  2. Start WAMP: green tray icon should appear (Apache + MySQL + PHP running).
  3. Project root: C:\wamp64\www\myapp.
  4. 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)

  1. Download MAMP for macOS and install (default: /Applications/MAMP).
  2. Open MAMP app → Start Servers.
  3. Project root: /Applications/MAMP/htdocs/myapp.
  4. 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: ...)
Tip: If php is not found, add the PHP folder to your system PATH (see below).

Common Paths

StackDocument RootPHP Executable
XAMPP (Win)C:\xampp\htdocsC:\xampp\php\php.exe
WAMP (Win)C:\wamp64\wwwC:\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
Remember: Restart Apache after changing 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

  1. Create folder myapp inside the document root (see table above).
  2. 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
Note: Enable 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.ini and restart Apache.
  • Permission denied (Linux): Use sudo chown -R www-data:www-data /var/www/html or appropriate user, and check file permissions.
Next step: Learn the core syntax and comments → PHP Syntax