After upgrading to MacOS High Sierra, I haven't been able to access my localhost. I tried restarting Apache, but it still didn't work. So I did apachectl configtest
and got this error message:
httpd: Syntax error on line 544 of /private/etc/apache2/httpd.conf:
Syntax error on line 8 of /private/etc/apache2/other/+php-osx.conf:
Cannot load /usr/local/php5/libphp5.so into server:
dlopen(/usr/local/php5/libphp5.so, 10): Symbol not found: _environ\n
Referenced from: /usr/local/php5/libphp5.so\n Expected in:
/usr/sbin/httpd\n
Line 544 of my httpd.conf file is
Include /private/etc/apache2/other/*.conf
The +php-osx.conf is an alias to entropy-php.conf, and line 8 of that file is
LoadModule php5_module /usr/local/php5/libphp5.so
The remaining lines of entropy-php.conf are:
LoadModule php5_module /usr/local/php5/libphp5.so
<IfModule mod_php5.c>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule mod_dir.c>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>
I am using Apache/2.4.28 (Unix) and PHP 5.6.30.
Everything was working fine until the update. I have searched online for any solution this issue, but to no avail. Someone posted a similar question here a couple of years ago regarding the same syntax error, however, he didn't provide enough details or any follow-up regarding his setup, and no solution could be offered: Mac apache not working – apachectl configtest errors
Best Answer
Here an (old) 3rd party PHP probably from entropy.ch was installed to /local/usr/bin/. The Sierra httpd.conf was modified to work with the different PHP (and virtual hosts).
While updating to macOS to High Sierra, the Sierra httpd.conf was backed up to httpd.conf.sierra, a new High Sierra httpd.conf was installed and gained control, but won't work with the custom PHP5.
After backing up the High Sierra httpd.conf to httpd.conf.high_sierra:
reactivating the httpd.conf.sierra:
uncommenting the httpd.conf line
#LoadModule php5_module libexec/apache2/libphp5.so
and changing the version number from 5 to 7 so that it reads:
LoadModule php7_module libexec/apache2/libphp7.so
renaming the custom /local/usr/bin/php to php5:
replacing the soft link /private/etc/apache2/other/+php-osx.conf (linking to /usr/local/php5/entropy-php.conf) with the High Sierra default /private/etc/apache2/other/php7.conf
and removing any reference to the custom PHP5,
apachectl configtest
was OK and Apache worked again - now with Apple's PHP7.