Compiling php/php-src source on macOS BigSur
Tags: php, php8, macos, terminal
Published: 2021-05-27 09:47:07

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.
<hr>

* `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 `bison` (using `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:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l6hw6u4vb5kx6v76bb48.png)

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.
<hr>

* 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.

NOTE: `re2c` is not key-only, so, after installation, the necessary libraries are exported by brew.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hs3r31t6olxee4dnu7yo.png)
<hr>

*  Well, that's not all, I met another issue with `libiconv` which is a conversion library to convert from/to Unicode.

I installed `libiconv` using brew as such: `brew install libiconv`, and notice in the Caveats info that it's key-only.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kuysmvbtste0fv1ik0jc.png)

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 `libiconv` 👇🏽

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jmd4qx1drqd2y5lvxzoi.png)

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

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i5g7o45dip44monmskjf.png)
<hr>

Now I had to compile PHP using `make -j8` (as my computer has 8 cores), wish me luck! ☺️ Hey, it compiled successfully:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rmg4cpus66t7o5b7p6yj.png)

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.
<hr>

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

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ozvzc3dbmz3rmrtfa8jc.png)

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.

Thank you!