The world is changing faster than a GP 1 car rpms!
When it comes to IT the pace is even faster, most generations of developer hardly share any knowledge and from time to time old issues pop up and new approaches are useless.
That’s my scope for this post, having an machine with an outdate operating system where no official support is available and new tools (like docker) aren’t supported but the number of processors and memory makes it wordy of usage.
Problem:
- We need PHP 7.*, Mysql 5.7, Apache
- We have and El Capitan Machine (not upgradable to Latest OSX)
brew would it be a solution if we could have the latest version of the operating system, actually brew it’s helpful still to get dependencies like openssl .
Apache is 2.4 so we are good with the default apache server that comes with the operating system.
MySQL although challenging in the current year 2019 not a problem, we have 2 options, brew mariadb still installs without issues and we have the option to download a compatible version from the archived versions that can be found in https://downloads.mysql.com/archives/community/
I opted to download a compatible mysql version for El Capitan.
Next we need to identify what php modules we need for our project, if you’re not sure which ones you’ll need you can try to set the same as the default php version your OSX brings.
After enabling the apache php module in the httpd.conf (google is your friend if you need to find how to or just drop a message and I’ll give a push in the right direction since apache settings is out of scope of this article) , create a php file with phpinfo() function and you can see what are the default php modules loaded.
To compile the new php version we can use as the base for our php configuration what we find phpinfo :
the Configure Command gives us the basics to compile php from source.
Php 7.3 is a little bit different from php 5.5 and one thing we can notice straightway is the –with-openssl option, it will compile if we use the openssl instead of the osx ssl native library.
you can use brew to install openssl and after that we can use the brew openssl for the openssl option. Once we have openssl in place , download the php7.3.* source code , open a terminal and go to the code folder and you can now run the configure command as follow:
./configure –prefix=/usr –with-apxs2=/usr/sbin/apxs –mandir=/usr/share/man –infodir=/usr/share/info –disable-dependency-tracking –sysconfdir=/private/etc –with-libdir=lib –enable-cli –with-iconv=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.Internal.sdk/usr –with-config-file-path=/etc –with-config-file-scan-dir=/Library/Server/Web/Config/php –with-libxml-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.Internal.sdk/usr –with-openssl-dir=/usr/local/include/node/openssl
As you can notice we replace the –-with-openssl option with –with-openssl-dir to the path of brew installed openssl.
I also added –with-apxs2=/usr/sbin/apxs to compile the apache module, today many developers prefer to run php as php-fpm but I goal is to explain the upgrade process and not to customise php installation.
after executing the configure command execute:
$make
$sudo make install
After installing we need to activate the new php module in apache:
find the following line and comment it:
LoadModule php5_module libexec/apache2/libphp5.so
and add the following line if isn’t in the http.conf already:
LoadModule php7_modulelibexec/apache2/libphp7.so
restart your apache and check your phpinfo again:
And here you have it! A fresh new php version in your OSX!
If you find missing any php module that you need you can just compile it and add it to the php engine, just follow the compile php module next…
How to compile php module
When we install php from source, we can select which modules we want to use or not and we do that by compiling the separated modules and adding them to php.ini
compile:
Open a terminal and go to php source code folder, in there you find another folder “ext”, this folder contains the code for each separated module.
As an example let’s say you need the GD library , inside ext you find a gd folder, in the terminal we need to go into the folder and then execute the following list of commands:
$phpize
$./configure
$make
$sudo make install
–phpize prepares the code to be compiled and installed according to the php engine settings.
–configure set variables and macros required to compile the code.
-make and make install obviously is compiling and installing the binary file.
What else do we need ? To tell php to load this module.
just open your php.ini and add the following line:
extension=gd
restart your apache and check phpinfo, there you should now see that GD library is present.
and that’s how you add only the modules you need to use.
When compiling mysqli module I had to use the following configure option:
–with-mysqli=’/usr/local/opt/mysql@5.7/bin/mysql_config’
yes this module requires to know where mysql client library is and mysql_config is what will tell where is what .
Although I make reference to El Capitan, the same steps can be used for any OSX version.