phpize Can't find PHP headers in /usr/include/php
When you encounter the error Can't find PHP headers in /usr/include/php while running phpize, it is almost always a symptom of a missing or incorrectly named development package. This specific scenario frequently arises on CentOS and RHEL-based systems where the packaging strategy differs slightly from what a developer might expect based on Debian or Ubuntu conventions.
In your case, you confirmed that php5-devl is installed and pecl commands function correctly. However, phpize still fails to locate headers in /usr/include/php. This discrepancy points directly to the fact that the development files are likely installed under a different directory path than the one hardcoded into the phpize script or expected by the build system. On CentOS 6 systems with PHP 5.x, the development headers are often located in a versioned subdirectory rather than the root include path.
Diagnosing the Header Location
The most reliable way to resolve this without guessing is to inspect the actual installation of your PHP source and header files. You can determine the correct include path by checking where the php.h file resides. Run the following command:
find /usr -name "php.h" 2>/dev/null
If the output returns something like /usr/include/php5/php.h, then your system expects headers in a versioned directory. The error message explicitly looks for /usr/include/php, which suggests a mismatch between the installed package structure and the build tool's expectations.
Aligning phpize with Your System
To fix this, you do not necessarily need to install additional packages if php5-devl is already present. Instead, you often need to tell phpize where to look. You can do this by setting the PHP_SRC_DIR environment variable before running the command. If your headers are indeed in a versioned directory like /usr/include/php5, try:
export PHP_SRC_DIR=/usr/include/php5
phpize
Alternatively, you can explicitly pass the path to the PHP source or header location if phpize supports specific flags for your build environment. However, on CentOS 6 with PHP 5.4, a common workaround involves ensuring that the symlink structure matches what the build system expects. Sometimes, creating a symbolic link from the expected location to the actual location resolves the issue immediately:
ln -s /usr/include/php5 /usr/include/php
After creating this link, re-run phpize. This approach bridges the gap between the hardcoded path in the phpize script and your actual filesystem layout.
Understanding the Trade-offs
While linking directories works effectively for resolving immediate build errors, it is worth noting that relying on symlinks can sometimes obscure package management issues. If you ever need to uninstall or upgrade PHP, having multiple paths pointing to the same headers might complicate dependency resolution. The preferred long-term solution is often to ensure the development package matches the exact version of the PHP binary you are targeting.
If you are compiling extensions like Xdebug, verify that the phpize script being used corresponds to the PHP version you intend to extend. Mixing binaries and headers from different versions (e.g., PHP 5.4 binary with PHP 5.3 headers) will inevitably lead to compilation failures or runtime errors where functions declared in headers do not match the compiled binary.
Final Verification
Once phpize completes successfully, you should proceed to configure and build your extension. Ensure that your configure options align with your production environment settings, particularly regarding FPM configuration if you are deploying via php-fpm. Always review the generated Makefile for any hardcoded paths that might still reference the wrong include directory.
If you continue to face issues, double-check that no conflicting PHP installations exist on your system using rpm -qa | grep php. Consistency in package versions is critical when dealing with low-level build tools like phpize. For modern Laravel applications or complex PHP environments, ensuring a clean, version-matched development stack remains the most robust strategy for extension development.