Apache Crashing with PHP 7 Enabled after High Sierra Upgrade

Upgrading (partially) for a System PHP 7

I finally got around to upgrading to High Sierra, which has PHP 7 as a system PHP instead of PHP 5.6. As part of that upgrade, my quick hacks of httpd-vhosts.conf for a couple of small projects had disappeared, since bringing up those virtual hosts would bring up the default site.

In the process of restoring these changes, I checked the main /private/etc/apache2/httpd.conf and noticed that
LoadModule php7_module libexec/apache2/libphp7.so
was commented out. So I uncommented it, much like I seem to recall doing for prior Apache setup.

Problems and Debugging

Strangely, after sudo /usr/sbin/apachectl restart, I was getting a connection refused. I checked for instances of httpd processes running:
ps aux | grep httpd
I found none.

Eventually, I figured out that I could do a -k option on apachectl:

sudo /usr/sbin/apachectl -k restart
httpd not running, trying to start
/usr/sbin/apachectl: line 92: 37326 Segmentation fault $HTTPD "$@"

Searching around on StackOverflow, I found that conflicting PHP versions were potentially the problem. So I commented out the php7 module again, restarted, and loaded a page with phpinfo(); on it. Sure enough, PHP 5.6 was running.


Searching in /private/etc/apache2 for other php module mentions, I found /private/etc/apache2/other/+php-osx.conf and commented out the following line:

LoadModule php5_module /usr/local/php5/libphp5.so

Restoring the php7_module in httpd.conf, I restarted Apache, and magically phpinfo(); displayed the 7.1.7 PHP version.