Writing

Web Development · 4 min read

Running PHP 5.6 with Apache on El Capitan

The Apache module path was the easy-to-miss part of running Homebrew's PHP 5.6 on macOS El Capitan. Here is the full setup.

In this article11 sections

Historical setup This records my 2016 El Capitan setup. PHP 5.6 is end-of-life, and the php56 commands below are historical. Use a supported PHP release and current installation instructions for a new setup.

I wanted a local PHP setup closer to the production servers I worked with, without waiting on MAMP. El Capitan already shipped with Apache, so I used that with Homebrew’s PHP 5.6 and MySQL.

The easy-to-miss step is pointing Apache at Homebrew’s PHP module instead of Apple’s bundled copy.

Why not the built-in PHP?

Apple’s bundled PHP is outdated and locked to specific modules. Homebrew gives you:

  • Control over PHP version and extensions
  • Easy upgrades without waiting for macOS updates
  • Access to the full PECL extension ecosystem
  • More control over matching production PHP versions and extensions

Prerequisites

You need Homebrew. 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 mcrypt (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.

Configuring Apache for Homebrew’s PHP

macOS’s Apache config lives in /private/etc/apache2/httpd.conf:

sudo nano /private/etc/apache2/httpd.conf

Uncomment the rewrite_module line:

-#LoadModule rewrite_module libexec/apache2/mod_rewrite.so
+LoadModule rewrite_module libexec/apache2/mod_rewrite.so

This enables URL rewriting (most PHP frameworks need it for clean URLs).

Replace the built-in php5_module line with the Homebrew version:

-#LoadModule php5_module libexec/apache2/libphp5.so
+LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so

Finding your php.ini

Homebrew’s PHP config is at /usr/local/etc/php/5.6/php.ini. Adjust upload_max_filesize, memory_limit, or timezone there.

To find the CLI’s active php.ini path:

php --ini

The CLI and Apache module can load different configuration files. Check the web-served phpinfo() page below for Apache’s loaded configuration rather than assuming php --ini describes it. See PHP’s configuration-file documentation.

Starting MySQL and Apache

Start MySQL:

mysql.server start

Start through Homebrew services (without sudo, this runs at user login):

brew services start mysql

Start Apache (requires sudo for port 80):

sudo apachectl start

Restart after config changes:

sudo apachectl restart

Open http://localhost in your browser. You should see the “It works.” page.

VirtualHosts for local domains

VirtualHosts map custom domain names (like example.local) to specific directories. Cleaner than localhost/subfolder/ URLs.

Uncomment the VirtualHost include in /private/etc/apache2/httpd.conf:

 # Virtual hosts
-#Include /private/etc/apache2/extra/httpd-vhosts.conf
+Include /private/etc/apache2/extra/httpd-vhosts.conf

Edit the VirtualHost config:

sudo nano /private/etc/apache2/extra/httpd-vhosts.conf

Add your site:

<VirtualHost example.local:80>
    DocumentRoot "/Users/example/projects/cors"
    ServerName example.local
    ErrorLog "/private/var/log/apache2/example.local-error_log"
    CustomLog "/private/var/log/apache2/example.local-access_log" common
</VirtualHost>

<Directory /Users/example/projects/>
  Options Indexes FollowSymLinks
  AllowOverride All
  Require all granted
</Directory>
  • DocumentRoot points to your project’s web root (for CakePHP, this might be webroot or public)
  • ServerName matches the domain you want locally
  • AllowOverride All lets .htaccess files work (needed for most PHP frameworks)
  • Require all granted allows access to the directory

Adding the domain to your hosts file

Apache won’t respond to example.local unless your system resolves it locally:

sudo nano /etc/hosts

Add:

127.0.0.1  example.local

Restart Apache:

sudo apachectl restart

Visiting http://example.local should load your project.

Testing PHP

Create a test file in your DocumentRoot:

echo "<?php phpinfo();" > /Users/example/projects/cors/info.php

Visit http://example.local/info.php. You should see PHP’s configuration page showing version 5.6. Delete info.php after the check; it exposes configuration and environment details.

Common issues

“403 Forbidden”: Check the <Directory> permissions. Make sure Require all granted is set and the path matches your project directory.

PHP not executing: Verify LoadModule php5_module 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 shipped 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.

These days, I don’t run PHP locally at all. For this blog, a static site generator removed the database and server setup entirely.

Was this useful?

What was missing?

Thanks for the feedback.