Understanding the config.m4 Error When Installing PHP Extensions
The error message Cannot find config.m4 is one of the most common stumbling blocks for developers attempting to compile custom PHP extensions, such as the FFmpeg module. It often appears when a user tries to run phpize immediately after installing development packages like php5-dev. While the system reports that tools like autoconf, automake, and libtool are present, the core issue is usually not missing utilities but rather a misunderstanding of what phpize actually does and where it expects to find the configuration data.
When you run phpize, it is not simply checking for installed packages; it is scanning the source directory of a specific PHP extension to generate the necessary build files. The tool looks for a file named config.m4, which contains the macro definitions required to configure the extension against your current PHP installation. If this file does not exist in the top-level directory of the module's source code, phpize cannot proceed.
In many cases, developers assume that installing php-dev or similar packages automatically places a usable config.m4 file in their home directory or system path. This is incorrect. The config.m4 file is intrinsic to the extension you are trying to build, not the PHP core itself. If you downloaded the FFmpeg source code and extracted it, that directory should contain config.m4. However, if you attempted to use a pre-compiled .tar.gz or an RPM package that was intended for another environment, the file might be missing or misplaced.
To resolve this, you must ensure you are working within the correct source tree. The error message explicitly states: "Make sure that you run '/usr/bin/phpize' in the top level source directory of the module." This means your current working directory should contain the config.m4 file provided by the FFmpeg extension vendor or repository. If you cloned the extension from GitHub, navigate into that specific repository first.
cd /path/to/ffmpeg-php-source-directory
phpize
If you are unsure whether the source is complete, verify the presence of the file before invoking phpize:
ls -la config.m4
Another frequent pitfall involves version mismatches. The phpize utility scans your system for PHP headers and configuration data to generate a matching build environment. If you are running a specific version of PHP (e.g., 5.x, as hinted by the php5-dev package in the source material) but the extension source code is designed for a different major version (e.g., PHP 7 or 8), the generated Makefile might fail later, or the tooling might behave unexpectedly. Ensure that the phpize binary corresponds to the PHP installation you intend to extend.
Regarding the php.ini location mentioned in the source material (/usr/local/zend/etc/php.ini), this file is irrelevant to the compilation process itself. The configuration file defines how PHP behaves at runtime, whereas phpize and the Makefile define how the extension is compiled statically or loaded dynamically. You do not need to point phpize to your php.ini; it infers the environment based on the installed headers in /usr/include/php.
If you encounter issues where config.m4 seems missing despite having a valid source directory, check if you have accidentally created a new directory that is empty. The command must be run inside the extracted tarball or git repository of the specific extension, not in your home directory or system root.
Once phpize completes successfully without errors, it will generate a Makefile tailored to your PHP version. At that point, you can proceed with make clean, make, and make install. If you are using a shared library setup (SAPI), the extension will be compiled into .so files ready for loading via zend_extension.
For modern Laravel applications or any production environment managed through containers or package managers like Composer, compiling extensions manually is often unnecessary unless specific legacy support or custom codecs are required. However, understanding this workflow is essential for troubleshooting performance bottlenecks or integrating complex media processing pipelines where the standard PHP FFmpeg extension might not suffice.
