Tutorial – Install PHP 5.4 on Apple Mac OSX Mojave

UPDATED 10/11/2019! https://php-osx.liip.ch/ started working again. PHP-OSX is by far the easiest way to get PHP 5.4 installed on OSX. The tutorial below is still valid if you’d like to install PHP using PHPBrew.

A while back, I had to figure out how to install PHP 5.4 on to my newly updated MacBook PRO running OSX (10.14) Mojave. As it turns out, the ability to install PHP 5 dot anything, has been removed from Homebrew. With that being said, I tried to find another method and came across https://php-osx.liip.ch/, but was not successful. Neither Homebrew, nor php-osx are your answer for installing PHP 5 onto your Mac.

Installing PHP 5.4 on Mac OSX 10.14 Mojave

The answer is a bit simpler. You will need to use PHPBrew. To use PHPBrew, follow these steps:

Install PHPBrew:

curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrew
chmod +x phpbrew
sudo mv phpbrew /usr/local/bin/phpbrew

Initialize PHPBrew:

phpbrew init

Add PHPBrew to .bash_profile configuration:

source ~/.phpbrew/bashrc

Install the version of PHP you’d like:

phpbrew install --mirror=https://www.php.net 5.4

Please take note that the above command includes an option for the mirror --mirror=https://www.php.net. This is required for Mojave specifically because PHPBrew needs to be informed that it will follow a mirror. This seems to be a defect within PHPBrew at this time.

Troubleshooting

When installing PHP 5.4 I ran into several problems with dependencies not being found:

$ phpbrew install --mirror=https://www.php.net 5.4
===> phpbrew will now build 5.4.45
===> Loading and resolving variants...
Checking distribution checksum...
Checksum matched: 4e0d28b1554c95cfaea6fa2b64aac85433f158ce72bb571bcd5574f98f4c6582
===> Distribution file was successfully extracted, skipping...
===> Checking patches...
Checking patch for replace apache php module name with custom version name
Found existing build.log, renaming it to /Users/josjohns/.phpbrew/build/php-5.4.45/build.log.1567601306
===> Configuring 5.4.45...


Use tail command to see what's going on:
   $ tail -F /Users/josjohns/.phpbrew/build/php-5.4.45/build.log


Error: Configure failed:
The last 5 lines in the log file:
checking if the location of ZLIB install directory is defined... no

checking whether to enable bc style precision math functions... yes

checking for BZip2 support... yes

checking for BZip2 in default path... not found

configure: error: Please reinstall the BZip2 distribution

Please checkout the build log file for more details:
	 tail /Users/josjohns/.phpbrew/build/php-5.4.45/build.log

To fix this issue, I installed BZip2 via Homebrew

brew install bzip2

Then, I included the path to bzip2 in my command to install PHP 5.4:

phpbrew install --mirror=https://www.php.net 5.4 +bz2=/usr/local/Cellar/bzip2/1.0.8

Then I saw the next issue pop up:

$ phpbrew install --mirror=https://www.php.net 5.4 +bz2=/usr/local/Cellar/bzip2/1.0.8
===> phpbrew will now build 5.4.45
===> Loading and resolving variants...
Checking distribution checksum...
Checksum matched: 4e0d28b1554c95cfaea6fa2b64aac85433f158ce72bb571bcd5574f98f4c6582
===> Distribution file was successfully extracted, skipping...
===> Checking patches...
Checking patch for replace apache php module name with custom version name
Found existing build.log, renaming it to /Users/josjohns/.phpbrew/build/php-5.4.45/build.log.1567601602
===> Configuring 5.4.45...


Use tail command to see what's going on:
   $ tail -F /Users/josjohns/.phpbrew/build/php-5.4.45/build.log


Error: Configure failed:
The last 5 lines in the log file:
checking for cURL support... yes

checking if we should use cURL for url streams... no

checking for cURL in default path... not found

configure: error: Please reinstall the libcurl distribution -

    easy.h should be in <curl-dir>/include/curl/

Please checkout the build log file for more details:
	 tail /Users/josjohns/.phpbrew/build/php-5.4.45/build.log

To solve this, I included curl into my PHPBrew command to install PHP 5.4:

phpbrew install --mirror=https://www.php.net 5.4 +bz2=/usr/local/Cellar/bzip2/1.0.8 +curl=/usr/local/opt/curl

Then I saw this issue come up:

phpbrew install --mirror=https://www.php.net 5.4 +bz2=/usr/local/Cellar/bzip2/1.0.8 +curl=/usr/local/opt/curl
===> phpbrew will now build 5.4.45
===> Loading and resolving variants...
Checking distribution checksum...
Checksum matched: 4e0d28b1554c95cfaea6fa2b64aac85433f158ce72bb571bcd5574f98f4c6582
===> Distribution file was successfully extracted, skipping...
===> Checking patches...
Checking patch for replace apache php module name with custom version name
Found existing build.log, renaming it to /Users/josjohns/.phpbrew/build/php-5.4.45/build.log.1567601880
===> Configuring 5.4.45...


Use tail command to see what's going on:
   $ tail -F /Users/josjohns/.phpbrew/build/php-5.4.45/build.log


Error: Configure failed:
The last 5 lines in the log file:
checking for XSL support... yes

checking for EXSLT support... not found

checking for zip archive read/writesupport... yes

checking pcre install prefix... /usr/local

checking for the location of zlib... configure: error: zip support requires ZLIB. Use --with-zlib-dir=<DIR> to specify prefix where ZLIB include and library are located

Please checkout the build log file for more details:
	 tail /Users/josjohns/.phpbrew/build/php-5.4.45/build.log

Now, install zlib via Homebrew:

brew install zlib

And finally, include zlib in the PHPBrew command:

phpbrew install --mirror=https://www.php.net 5.4 +bz2=/usr/local/Cellar/bzip2/1.0.8 +curl=/usr/local/opt/curl +zlib=/usr/local/Cellar/zlib/1.2.11

Done!

Leave a comment

Leave a Reply