DEV Community

Compiling php/php-src source on macOS BigSur

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

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.

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

Alt Text


  • 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

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

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


Now I had to compile PHP using make -j8 (as my computer has 8 cores), wish me luck! โ˜บ๏ธ Hey, it compiled successfully:

Alt Text

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

Alt Text

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!

Oldest comments (2)

Collapse
 
xsavitar profile image
๐——๐—ฒ๐—ฟ๐—ถ๐—ฐ๐—ธ ๐—”๐—น๐—ฎ๐—ป๐—ด๐—ถ ๐Ÿฌ

Thank you Manish. I appreciate.

Collapse
 
leslieeeee profile image
Leslie

If you are macOS user, ServBay.dev is a good tool, especially for the beginners. It handles all PHP, MariaDB, PostgreSQL versions, plus Redis and Memcached. Run multiple PHP instances simultaneously and switch easily. This tool has made my PHP dev simpler. Worth a shot!