Running PHP 5.6 with Apache on El Capitan
MAMP works for quick local PHP development, but it's slow and doesn't match production server environments. macOS El Capitan ships with Apache built-in, so you can build a proper PHP development environment with Homebrew that's faster and more configurable.
This guide sets up PHP 5.6 with MySQL using the native Apache that comes with macOS.
Why not use macOS's built-in PHP?
El Capitan includes PHP, but Apple's version is outdated and locked to specific modules. Using Homebrew gives you:
- Control over which PHP version and extensions you install
- Easy upgrades without waiting for macOS updates
- Access to the full PECL extension ecosystem
- Configuration that matches production Linux servers
Prerequisites
You need Homebrew. If you don't have it, install from brew.sh:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Installing MySQL and PHP 5.6
Install MySQL, PHP 5.6, and the mcrypt extension (which many PHP frameworks require):
brew install mysql
brew install php56
brew install php56-mcrypt
Homebrew installs PHP to /usr/local/opt/php56 and puts the Apache module at /usr/local/opt/php56/libexec/apache2/libphp5.so. This is where we'll point Apache.
Configuring Apache to use Homebrew's PHP
macOS's Apache config lives in /private/etc/apache2/httpd.conf. Open it:
sudo nano /private/etc/apache2/httpd.conf
Find the line for rewrite_module. It's commented out by default:
#LoadModule rewrite_module libexec/apache2/mod_rewrite.so
Uncomment it:
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
This enables URL rewriting (which most PHP frameworks need for clean URLs).
Next, find the php5_module line. It references the old built-in PHP:
#LoadModule php5_module libexec/apache2/libphp5.so
Replace it with the Homebrew version:
LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so
This tells Apache to use Homebrew's PHP instead of the system version.
Finding your php.ini
Homebrew's PHP config is at /usr/local/etc/php/5.6/php.ini. This is where you adjust settings like upload_max_filesize, memory_limit, or timezone.
To find the active php.ini path, run:
php --ini
Starting MySQL and Apache
Start MySQL:
mysql.server start
To have MySQL start automatically on boot:
brew services start mysql
Start Apache (requires sudo because it binds to port 80):
sudo apachectl start
To restart Apache after config changes:
sudo apachectl restart
Check if Apache is running by opening http://localhost in your browser. You should see the "It works!" page.
Setting up VirtualHosts for local domains
VirtualHosts let you map custom domain names (like myproject.local) to specific directories. This is cleaner than using localhost/subfolder/ URLs.
First, enable VirtualHost support. In /private/etc/apache2/httpd.conf, find this line:
# Virtual hosts
#Include /private/etc/apache2/extra/httpd-vhosts.conf
Uncomment it:
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf
Now edit the VirtualHost config:
sudo nano /private/etc/apache2/extra/httpd-vhosts.conf
Add your site config:
<VirtualHost cors.kahwee:80>
DocumentRoot "/Users/kahwee/projects/cors"
ServerName cors.kahwee
ErrorLog "/private/var/log/apache2/cors.kahwee-error_log"
CustomLog "/private/var/log/apache2/cors.kahwee-access_log" common
</VirtualHost>
<Directory /Users/kahwee/projects/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
A few things to note:
DocumentRootpoints to your project's web root (for CakePHP, this might be awebrootorpublicsubdirectory)ServerNamematches the domain you want to use locally- The
<Directory>block sets permissions for the entire projects folder AllowOverride Alllets.htaccessfiles work (needed for most PHP frameworks)Require all grantedallows access to the directory
Adding the domain to your hosts file
Apache won't respond to cors.kahwee unless your system knows to resolve it locally. Edit your hosts file:
sudo nano /etc/hosts
Add this line:
127.0.0.1 cors.kahwee
Save and restart Apache:
sudo apachectl restart
Now visiting http://cors.kahwee in your browser should load your project.
Testing PHP
Create a test file in your DocumentRoot:
echo "<?php phpinfo();" > /Users/kahwee/projects/cors/info.php
Visit http://cors.kahwee/info.php. You should see PHP's configuration page showing version 5.6.
Common issues
"403 Forbidden" error: Check the <Directory> permissions. Make sure Require all granted is set and the path matches your project directory.
PHP not executing: Verify the LoadModule php5_module line points to the Homebrew path, not the system path.
Changes not taking effect: Restart Apache after every config change: sudo apachectl restart
Why PHP 5.6 in 2016
PHP 7 was released in late 2015, but many frameworks and plugins weren't compatible yet. PHP 5.6 was the safe choice for production work in mid-2016. It included important features like better TLS support and improved performance over 5.5.
If you're following this guide in 2025, use brew install php (which installs the latest version) instead of php56.
These days, I don't run PHP locally at all. Static site generators eliminated the need for dynamic server setups like this. But if you're maintaining legacy PHP projects, this workflow still works.