Skip to main content

How to fix common issues when installing PHP from source on macOS

·2 mins

If you want to install PHP from the source code, you can follow the official documentation from the PHP Git repository.

However, you may encounter the following issues when trying to build the project (when running ./configure) even though you installed the required dependencies as follows:

brew install autoconf bison re2c libiconv libxml2 sqlite

Issue with bison
#

macOS ships with bison version 2 whilst PHP requires bison version 3.

You may run into the following issue:

checking for bison version... 2.3
configure: error: bison 3.0.0 or later or newer is required to generate PHP parsers
(excluded versions: none).

To fix this, add the following to your ~/.zshrc file:

export PATH="/opt/homebrew/opt/bison/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/bison/lib $LDFLAGS"

Issue with libxml-2.0
#

If you run into the following issues where the wrong version of libxml is used:

checking whether to build with LIBXML support... yes
checking for libxml-2.0 >= 2.9.4... no
configure: error: in '/Users/maxime/Projects/php/php-src':
configure: error: The pkg-config script could not be found or is too old.  Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
path to pkg-config.

Alternatively, you may set the environment variables LIBXML_CFLAGS
and LIBXML_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

To get pkg-config, see <http://pkg-config.freedesktop.org/>.
See 'config.log' for more details

Then, add the following to your ~/.zshrc file:

export LIBXML_LIBS="-L/opt/homebrew/opt/libxml2/lib $LIBXML_LIBS"
export LIBXML_CFLAGS="-I/opt/homebrew/opt/libxml2/include $LIBXML_CFLAGS"

Note than only adding the libxml2 binaries to my PATH was not enough:

export PATH="/opt/homebrew/opt/libxml2/bin:$PATH"

Issue with sqlite3
#

If you run into the following issues where the wrong version of sqlite3 is used:

checking whether to enable the SQLite3 extension... yes
checking for sqlite3 >= 3.7.17... no
configure: error: in '/Users/maxime/Projects/php/php-src':
configure: error: The pkg-config script could not be found or is too old.  Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
path to pkg-config.

Alternatively, you may set the environment variables SQLITE_CFLAGS
and SQLITE_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

To get pkg-config, see <http://pkg-config.freedesktop.org/>.
See 'config.log' for more details

Then, add the following to your ~/.zshrc file:

export SQLITE_LIBS="-L/opt/homebrew/opt/sqlite3/lib $SQLITE_LIBS"
export SQLITE_CFLAGS="-I/opt/homebrew/opt/sqlite3/include $SQLITE_CFLAGS"