Reconfiguring PHP 5.6 to run on MacOS 10.13 High Sierra

I need to get PHP 5.6 running on a Mac that had to be updated to 10.13. So I reinstalled 5.6, verified its location, and added it to httpd.conf:

LoadModule php5_module libexec/apache2/libphp5.so

...and made sure the line for PHP 7 is still commented out. Restarted Apache, and Apache starts fine, throws no errors, and works, but no PHP! So as a test, I commented out the PHP 5 line and uncommented the PHP 7 line:

LoadModule php7_module libexec/apache2/libphp7.so

...restarted Apache, and again it works fine, but still no PHP! So I queried the httpd binary to make sure I'm editing the right httpd.conf and I am. Neither version of PHP will run, and yet neither causes an error in Apache when it starts. (When I say Apache runs but PHP doesn't, I mean a browser displays:

<?php phpinfo(); ?>

...without rendering it. Help? I've run out of ideas to get PHP 5.6 running.


Solution 1:

Using PHP5.6 with HighSierra

Enable building of shared Apache Handler module Make sure you have the latest version of PHP56 installed along with http option enabled (either install/upgrade/reinstall as needed)

$brew upgrade php56 --with-httpd

Linking the module in Apache2 Config file Add following statement in apache2 config file /etc/apache2/httpd.conf

LoadModule php5_module /usr/local/Cellar/php56/5.6.32_8/libexec/apache2/libphp5.so

or, for newer version 5.6.36_1 and above (credits to @avidenic)

LoadModule php5_module /usr/local/Cellar/[email protected]/5.6.36_1/lib/httpd/modules/libphp5.so

Adding the PHP5 config file

Make a copy from the php7.conf

$ cd /etc/apache2/other ; sudo cp php7.conf php5.conf

In php5.conf replace php7_module with php5_module

Restart Apache Server

$ sudo /usr/sbin/apachectl restart

Solution 2:

I had to reinstall xcode stuff and php56 with apache support to make it work again.

xcode-select --install
brew reinstall php56 --with-httpd

libphp5.so is not provided by the OS any more, but it's there on the file system because we just installed it. So you have to change your apache config file enabling php5, too:

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