Amid working on a web development project, I came across an opportunity to try PHP 8 and I decided to go ahead with it.
I run MAMP as local server environment and luckily, MAMP 6.3 release came precompiled with PHP 8 yet lacking support to vital extensions such as GD extension for image processing which is likely to be needed whenever there is image processing implementation.
Therefore, as I researched how to install the extension online and found some sources which were not as elaborative and clear as it should, and due to the substantial amount of time it took from me to find how, I decided to save other people whom may come across similar situation, the time, and wrote this, as my first Computer Science related publication in regards and as tutorial on how to compile PHP extensions in Unix-based OS, covering issues the user might come across and I will elaborate on how I managed to resolve.
Firstly MAMP comes with several versions of precompiled php installations located in the directory e.g. in macOS environment of:-
Note the MAMP operating PHP it can be different than the OS local installed PHP, that could be newer or older, and it will be in many cases, and this could cause conflict during extensions compilation process due to php-config along other php binaries being possibly older or newer.
Such binaries are needed by the Make process for the extension compilation, and they will be located using OS environment variables, which might be pointing to such newer or older php versions which may be lacking some methods or support to a programming convention, that was introduced in newer php releases, and will result in compatibility issues, and in make process a failure and before applying this tutorial instructions, it’s important to find out current local php version installed in the operating system and the MAMP one, as per 6.3 release it’s php 8.0.0 for MAMP, and note my unix-based OS environment, its macOS Big Sur.
Run following to find OS local php version in terminal:-
If it’s newer or older, then note you will have to point to the location of several libraries during make process, Sometimes you will have to install some of which libraries and I will list them later, and it’s depending on your own IDEs in the OS environment.
Firstly, if you want to reduce compatibility issues as much as possible during compiling, then it’s better to upgrade or downgrade OS local PHP version to be matching MAMP version using the following steps, note to replace x.x to the desired PHP version:-
- Install homebrew
- brew install firstname.lastname@example.org
- brew link email@example.com
- Restart terminal session
Then, start compiling and installing extensions process via following steps, and note I will be compiling and installing GD extension in MAMP operating server with PHP of version 8.0.0 and 8.0.6 for operating system.
- Download MAMP PHP version source from https://www.php.net/releases/
- In terminal, go to the extensions in following directory:-
- In case, running in both OS and MAMP environments the same php version, then run directly following command in terminal
- Otherwise, locate the binary in MAMP directory
- Configure the make file, using following command:-
./configure --with-freetype --with-jpeg
- Note, if MAMP runs different php version than OS version then you will likely need to point to MAMP php-config binary as part of configure command using following:-
./configure --with-freetype --with-jpeg --with-php-config=/Applications/MAMP/bin/php/php8.0.0/bin/php-config
- Compile the extension via make
- Note, at the bottom of the terminal output, the gd.so location will be printed, usually in modules directory, and copy to following directory, depending on your MAMP php version, change the path:-
- Update php.ini file with extensions in conf directory
- In php.ini, gd extension must be added or uncommented in the dynamic extension section as following
- Save the php.ini file
- Restart MAMP
- Go to http://localhost/MAMP/?language=English, then phpInfo from tools menu option and search for GD section, it should say enabled.
- Horray! you should be able to have GD extension supported in the server now.
Also, note I read somewhere GD extension can be installed as package dependancy using composer yet I’ve not tested it.
composer require "ext-gd:*"
Also, following are the libraries which I had to install manually during compiling along the way and depending on your OS environment, you might have them already yet I will include all the instructions in following section and if compilation fails, it will tell which header is missing, and require installing its library in the system and likely XPM, Freetype libraries will be needed and are included below. Also, note you will need to switch to admin user session in terminal in order to successfully install libraries via make and brew commands:-
pkg-config, installed via Homebrew
brew install pkg-config
freetype installed via Homebrew
brew install freetype
Python docwriter package, installed via python pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python3 get-pip.py pip install docwriter
pthread-stubs library, installed via git clone and make
git clone https://gitlab.freedesktop.org/xorg/lib/pthread-stubs.git cd pthread-stubs ./autogen.sh make make install
libxau library, installed via git clone and make
git clone https://gitlab.freedesktop.org/xorg/lib/libxau.git cd libxau ./autogen.sh make make install
libxcb library, installed via git clone and make
git clone https://gitlab.freedesktop.org/xorg/lib/libxcb.git cd libxcb ./autogen.sh make make install
xorgproto library, installed via git clone and make
git clone git://anongit.freedesktop.org/git/xorg/proto/xorgproto cd xorgproto ./autogen.sh make make install
xextproto library, installed via git clone and make
git clone https://gitlab.freedesktop.org/xorg/proto/xextproto.git cd xextproto ./autogen.sh make make install
xtrans library, installed via Homebrew
brew install xtrans
libx11 library, installed via git clone and make
git clone https://gitlab.freedesktop.org/xorg/lib/libx11.git cd libx11 ./autogen.sh make make install
xorg-proto-x11proto library, installed via git clone and make
git clone https://github.com/freedesktop/xorg-proto-x11proto.git cd xorg-proto-x11proto ./autogen.sh make make install
libXpm library, installed via git clone and make
git clone https://github.com/freedesktop/libXpm.git cd libXpm ./autogen.sh make make install
xcb-proto library, installed via Homebrew
brew install xcb-proto
xorg-macros library, installed via git clone and make
git clone https://github.com/freedesktop/xorg-macros.git cd xorg-macros ./autogen.sh make make install
JPEG library, installed via Homebrew
brew install jpeg
Lastly, installing the extension, shouldn’t be a difficult task yet when ones work completely in different area and then switches to compiling libraries and extensions, it can become difficult, particularly when it comes to mindset switching and given the OS environment is not ready for such development and figuring which libraries are missing and how to install and themselves may require other libraries, and can take sometime and publishing such tutorial I think certainly it may at least come handy to some which I’ve seen, going through similar situation throughout the research, thus I hope it to be useful for others as it’s and an encouraging mean for me to publish more tutorials and researches, surrounding Computer Science.
Any questions, please don’t hesitate to drop me an email at firstname.lastname@example.org.
Let the power of learning to prevail.