PHP With GD - Fixing Your PHP Server On Mac OS X Without Homebrew/MacPorts

By mrbagnall | 27 February 2015

There are a lot of opinions with regard to how to get various types of open source web server and applications programming software working with OS X. A lot of these center around installing a package management service such as Homebrew or MacPorts. While this may be the way some folks wish to go, I am not very big on using these as they introduce unnecessary dependencies, applications and libraries that are not necessary in the day to day operation of your web server. My opinion is that you still have configuration you need to do even when using Homebrew or MacPorts and the systems themselves need maintenance and a degree of know how.

 

My preferred method is to get down and dirty with installing things that need to be installed an nothing more. As such, I’ve learned to extend things on the base version of PHP that come with Mac OS X (starting with Yoesmite and continuing with El Capitain) without the need of package managing services.

 

Building additional components for your web server can be pretty simple if you are comfortable around a command line and following a few instructions. This involves just a few more commands than it would take to run a package manager and gives you a lot more control while at the same time understanding a bit more about how your software works.

 

Using my method, I accomplished a few basic tasks:

 

  1. Remove the compiled-in GD installation on Mac OS X’s PHP installation as it does not support the creation of png files which is a must have.

 

  1. Add the PHP multi-threaded pcntl extension to the command line for processing command line scripts properly programmed to use multi-threaded processes.

 

  1. Make mcrypt work with the installed PHP (VERY important and almost a deal breaker to running a secure web server on Mac OS X).

 

To accomplish these things, I have created an installer that allows you to specify the version of PHP you wish to install on your Mac and integrate with OS X Server. The versions of PHP available are mapped to their corresponding versions of OS X specified in the installer. There is also an experimental way to install PHP 7 with a little command line familiarity which we will discuss later.

 

Here is a list of upgraded and dependent software. Most of this is already stock on OS X but is a different version - in many cases upgraded:

 

libressl

bisonv 

re2c 

autoconf 

libtool 

freetype 

jpegsrc 

libgd 

libmcrypt 

libpng 

ffmpeg (optional)

icu4c (optional)

 

Links to these packages can be found on google or you can use the TINHuB installer that I have created and maintained at the link below:

 

http://elusivemind.github.io/osx_server_enhancements/

 

Note that some of these are not using the latest/greatest versions due to compatibility issues, so please make sure you are downloading the correct versions of this software.

The internationalization library and extension icu4c / intl were also recently added to assist in Magento 2 development.

 

Also of note is that to install this you will need to disable System Integrity Protection in El Capitain. This is a new feature that prevents the modification of system paths. To do this, boot to your restore image and go to the Utilities menu. Select the terminal option and on the command line type:

 

csrutil disable

 

Once you have installed your base OS X system or are dealing with your existing one, make sure you have command line tools installed on the machine for which we wish to enhance PHP. I normally do this by making sure that git is installed. Drop to a terminal and issue the git command and if it is not installed yet (assuming you have not installed directly from the git project), then OS X should give you the option to install command line utilities. This should take 5-10 minutes. Once completed, you should be ready to continue with the rest of this tutorial.

 

Note that if you have already installed the XCode application, git will work, but you will need to download the XCode Command Line Utilities package found on the Apple Developers web site.

 

Run the installer you downloaded from the TINHuB project above

 

sudo ./installer.sh

 

Select the version of PHP and any other options and allow the installer to run. If you run into any issues, please gzip or zip up the "logs" file and create an issue on the github ticket system and I'll be happy to investigate.

 

Once this has completed and run, we will have successfully over-ridden our default, installed version of PHP on OS X Yosemite and we are ready to begin adding our components.

 

PHP Version 7.x

 

If you opt to install PHP 7, you will need to manually tell Apache to look for the libphp7.so file in /usr/libexec/apache after compilation.

 

The relevant changes need to occur in:

 

/Library/Server/Web/Config/apache2/httpd_server_app.conf

 

around lines 128 and again on line 600

 

LoadModule php7_module libexec/apache2/libphp7.so

<IfModule php7_module>

    AddType application/x-httpd-php .php

    AddType application/x-httpd-php-source .phps

    <IfModule dir_module>

        DirectoryIndex index.html index.php

    </IfModule>

</IfModule>