Compiling PHP source code (master) on macOS (BigSur) wasn't very smooth because of mainly unavailable packages on my OS, and because of some Mac restriction on upgrading software or tools.
After cloning the
php/php-src to my localhost, I had to run the
./buildconf script, and then
./configure --enable-debug executable.
Like all software compile processes will be, I ran into some issues/blockers which I'll document about below.
bison(the GNU parser generator) was pinned to 2.3 on my system, and I couldn't upgrade and re-link with
brew. I had to custom install
brew upgrade bison) version > 3.0 which is what php-src needs for parsing PHP.
When I finished installing version 3.7.6 which is above the required version, on trying to link via brew, I get:
Since bison is key-only, we can't update the version shipped by macOS (a bit annoying) but I had to export (see image above) the libraries of the latest install of bison so compilers (in this case GCC) can find them, and then ran the
./configure --enable-debug script again.
This time, with the latest libraries from
bison 3.7.6, it worked.
- The next issue I ran into was a missing package called
re2c(which is used to compile regex to code). This is similar to the issue encountered in bullet 1, so I just installed the package
brew install re2c.
Once I did the above, I ran the
./configure --enable-debug script again and it worked.
re2c is not key-only, so, after installation, the necessary libraries are exported by brew.
- Well, that's not all, I met another issue with
libiconvwhich is a conversion library to convert from/to Unicode.
libiconv using brew as such:
brew install libiconv, and notice in the Caveats info that it's key-only.
After installing, I had to export executables to PATH & libraries so compilers could see these.
On trying to re-run
./configure again, I got hit with another issue which is related to
So, this time, I needed to use an option to run the configurations with:
--with-config=<DIR>, and the command:
./configure --enable-debug --with-iconv=/usr/local/opt/libiconv/.
This worked smoothly, and I made progress
Now I had to compile PHP using
make -j8 (as my computer has 8 cores), wish me luck! ☺️ Hey, it compiled successfully:
NOTE: I first of all ran
make which was using by default only 1 core and this was already taking more than 2 mins. I had to change it to
make -j8 which was using all my CPU's 8 cores at once, and the compile process took less than 40sec.
Now I just have to run
make TEST_PHP_ARGS=-j8 test which ran really fast was it was using all 8 cores at once
All tests ran, and I'm ready to start contributing code to PHP core. Hope this helps you configure, and compile PHP on your macOS.