Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP not working after MacOS update to High Sierra

I updated my mac to newest version of os. When I try to run PHP project, browser shows the php code instead of interpreting it. I noticed that in new OS php is in version 7.1. I installed 5.6 (it's required for me) using homebrew and change module in httpd.conf to:

LoadModule php5_module /usr/local/Cellar/php56/5.6.31_7/libexec/apache2/libphp5.so

Here's apache error log:

[Tue Sep 26 23:59:38.600410 2017] [mpm_prefork:notice] [pid 980] AH00169: caught SIGTERM, shutting down [Tue Sep 26 23:59:38.622998 2017] [core:notice] [pid 980] AH00060: seg fault or similar nasty error detected in the parent process AH00557: httpd: apr_sockaddr_info_get() failed for MacBook-Pro-Kamil.local AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message [Tue Sep 26 23:59:48.838005 2017] [mpm_prefork:notice] [pid 991] AH00163: Apache/2.4.27 (Unix) PHP/5.6.31 configured -- resuming normal operations [Tue Sep 26 23:59:48.838097 2017] [core:notice] [pid 991] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'

like image 334
kamcik Avatar asked Sep 26 '17 22:09

kamcik


3 Answers

Adding the following lines to my httpd.conf file fixed the problem:

AddType x-httpd-php .php
AddHandler application/x-httpd-php .php .php5

Hopefully this helps!

Edit: just to provide a bit more detail, as crmpicco suggests, I did also replace the new High Sierra httpd.conf and httpd-vhosts.conf files with my old Sierra ones like so:

mv httpd-vhosts.conf~previous httpd-vhosts.conf
mv httpd.conf~previous httpd.conf

Even after all of this and restarting Apache it still wasn't working - had to do a reboot for everything to take effect.

like image 181
Erebus Avatar answered Nov 18 '22 17:11

Erebus


The MacOS upgrade process seems to move your Apache config out into ~previous files, whilst creating new, fresh versions. You just need to move them back. This worked for me:

mv httpd-ssl.conf~previous httpd-ssl.conf
mv httpd-vhosts.conf~previous httpd-vhosts.conf
mv httpd.conf~previous httpd.conf

Check the syntax.

apachectl -S

Restart Apache.

apachectl restart
like image 3
crmpicco Avatar answered Nov 18 '22 17:11

crmpicco


Using PHP5.6 with HighSierra

  1. 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

  2. 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

  3. Adding the PHP5 config file

    Make a copy from the php7.conf

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

    Replace php7_module with php5_module

  4. Restart Apache Server

    $ sudo /usr/sbin/apachectl restart

like image 1
Raghav Tandon Avatar answered Nov 18 '22 16:11

Raghav Tandon