phpize reports "Cannot find config.m4"

phpize reports "Cannot find config.m4"

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

phpize reports "Cannot find config.m4"

When you execute phpize on macOS, specifically environments like Mountain Lion or modern versions where Xcode command-line tools are installed, a common stumbling block is the error: Cannot find config.m4. This message often appears when attempting to compile external extensions, such as Redis, Memcached, or custom modules. The error handler suggests running /opt/local/bin/phpize from the top-level source directory, but blindly following this advice can lead to further configuration issues if your system isn't set up exactly as implied.

The root cause of this failure is a mismatch between the PHP build environment and the expected location of configuration macros. phpize is not a standalone executable; it is a script generated during the initial build of PHP itself. Its primary job is to bootstrap the compilation process by generating config.m4, which contains the necessary macros for the ./configure script. If phpize cannot locate this file, it usually means one of three things: you are running a version of phpize that doesn't match your installed PHP headers, you are in the wrong directory, or your environment variables are pointing to a non-existent installation path.

On many macOS systems, particularly those using legacy package managers like MacPorts (indicated by paths starting with /opt/local), the tool chain is split across multiple directories. If you have PHP 8.x installed via Homebrew but attempt to compile an extension expecting headers from a different version or a MacPorts installation, phpize will fail because it cannot find the corresponding config.m4 in its search path. The error implies that the script exists but is looking for specific configuration data relative to the PHP source tree associated with that specific binary.

To resolve this, you must ensure that your environment variables point to the correct PHP installation before invoking phpize. Start by identifying which PHP version is currently active and where its headers reside. Run the following command in your terminal:

$(which php-config) --version

If php-config returns a version number but fails when used with phpize, you likely need to regenerate the configuration script using the correct binary path. If you are on a system where Xcode is installed, the default path is often /usr/bin/phpize. However, if you have multiple PHP versions, you must explicitly invoke the one matching your desired extension.

The most robust solution involves regenerating the config.m4 file directly within the source directory of the module you are trying to build. Ensure you have downloaded the source code for both PHP and the extension (e.g., from GitHub). Navigate to the extension's root directory:

cd path/to/extension-source
phpize

If the command still complains about missing config.m4, it is highly probable that your PATH variable is prioritizing a system PHP over the one intended for building. You can verify this by checking which binary is being executed:

ls -l $(which phpize)

If the output points to /opt/local/bin/phpize but your installed PHP is in /usr/local/bin, you face a version mismatch. In this scenario, do not mix binaries from different package managers (Homebrew vs. MacPorts). Choose one ecosystem. If you prefer Homebrew, uninstall or ignore the MacPorts installation and ensure your PATH prioritizes /usr/local/bin.

Once the paths align, run phpize again. This command will now correctly locate the headers and generate the necessary config.m4 file in the current directory. You can verify its existence with ls -la config.m4. Afterward, proceed with ./configure and make, ensuring you pass any specific flags required by your extension.

For developers building extensions for production environments, such as those managing Laravel applications, consistency is key. While LaravelCompany offers resources on deploying robust PHP stacks, the underlying compilation process remains governed by strict build constraints. Always ensure that the phpize binary and the PHP headers reside in the same logical tree or are explicitly linked via environment variables to avoid these configuration dead ends.

Our network