Replace PHP 5.5/5.6 with PHP 7 on OS X Server (Yosemite)

I thought I needed PHP version 7 for our machine running OS X Server and used the following steps successfully:

1. Launch and execute the following commands:

curl -s | bash -s 7.0
sudo pico /Library/Server/Web/Config/apache2/httpd_server_app.conf

2. Search (control-w) for “php5_module” (for my system, it was line 184 – press control-c to see the line number in pico) and make these changes:

#Comment out the PHP5 module
#LoadModule php5_module libexec/apache2/

#Enable PHP 7 module
LoadModule php7_module /usr/local/php5-7.0.0RC8-20151127-210333/

LoadModule php7_module /usr/local/php5-7.0.10-20160831-102733/

Search (control-w) for “FilesMatch” (for my system, it was line 292) and paste in:
SetHandler application/x-httpd-php

3. Execute the following commands in to see your changes live:

sudo apachectl restart
php -version

So far PHP 7 seems to be compatible with other services that rely on PHP, so that’s good…

** UPDATE 6-12-2020 **
php 7.0.10 ran on my macOS Server, now running High Sierra, until today when WordPress reminded me this version of php is out of date. For those updating to php 7.3.8, check out my updated post.

11 thoughts on “Replace PHP 5.5/5.6 with PHP 7 on OS X Server (Yosemite)

  1. Hi,
    The “SetHandler” line – is it supposed to replace the current code? What I find in my file is:

    Require all denied

  2. Hmmm… some of that disappeared. Probably since I pasted code. I´ll try to remove the
    Require all denied

  3. Einar,

    You raise a good question. Since you wrote this, I had to rebuild my server from a backup and I appear to have lost this modification.

    Since I’m now back to PHP5, I may be trying this again and I will update step #2 when I do.


  4. Hi…

    I’ve followed your tuto … but If php5 doesn’t load anymore (as I comment the line)… php7 doesn’t kick in…

    of course, the php7 I’ve installed is less old than the one in the tuto, and of course, I carefully used the right path…

  5. Brad, how are your long term experiences with that PHP replacement?
    I’ve read that the some tasks of macOS server that rely on PHP will maybe break.

  6. So far it’s working great. Just upgraded to from Mavericks to High Sierra and the latest macOS Server today. This upgrade seems to have been the smoothest one ever. Everything seems to be working so far.

  7. To find the right path of “usr/local/php5-7.0.10-20160831-102733/” (this may very per php version), just open a new terminal window and type “ls /usr/local/php” and press tab multiple times.
    Skip the modifying “SetHandler application/x-httpd-php”. Instead, in the httpd_server_app.conf there is block called “Ifmodule php5_module”. Just replace it with “ifmodule php7_module”.

  8. Addendum to my comment:
    now php -v still shows the wrong version, so do the following:
    1. edit the bash_profile
    pico ~/.bash_profile
    2. add this line
    export PATH=/usr/local/php5/bin:$PATH
    3. save, open a new terminal window, now it should work

  9. Pingback: macOS Server on Catalina and php 7.3.8 « Schwie's Pad

  10. In response to Richard’s 11-11-17 comment, my macOS Server machine is now running PHP 7.3.8 and it appears somewhere along the way I broke macOS Server’s ability to show stats. When I upgrade to PHP 7.4, I’m going to see if I can somehow dual load PHP 5 for macOS Server functions, but I don’t know if this will be possible.

Leave a Reply

Your email address will not be published. Required fields are marked *