php.ini is nonexistent Loaded Configuration File (none)
If you compile PHP from source without specifying a custom configuration directory, Apache serves up an empty phpinfo() output. This is normal behavior for a default build, but it often catches developers off guard when they try to enable PEAR or adjust runtime settings and find no php.ini file in the expected location.
The core issue isn't that PHP is broken; it's that you're looking for a file that doesn't exist by default. When Apache runs PHP compiled from source, it expects to find an initialization file at the path defined during compilation or via environment variables. If that file is missing, PHP generates its configuration dynamically at runtime, which is why phpinfo() reports "Loaded Configuration File (none)" and "Scan this dir for additional .ini files (none)".
To fix this, you don't necessarily need to recompile PHP unless you've already lost the original build artifacts. Instead, you can create a custom configuration file manually.
Creating the Missing Configuration File
The most direct solution is to generate a php.ini file in the directory where Apache expects it. Based on your setup, that directory is /usr/local/apache2/php/lib. You can create this file by copying the default distribution version and then editing it:
# Locate the default php.ini from your PHP installation source
cp /path/to/php-source/ext/skel/main/php.ini-production \
/usr/local/apache2/php/php.ini
If you don't have access to the original source distribution, you can still create an empty php.ini file in that directory. However, note that an empty file will result in default values for all directives. This is generally fine for enabling PEAR or making minor tweaks, but it won't override system-wide defaults unless you explicitly set them.
Verifying the Configuration Path
Once you've created the file, verify that Apache picks it up by restarting the server and checking phpinfo() again:
/usr/local/apache2/bin/httpd -k restart
curl http://localhost | grep -A 5 "Configuration File"
You should now see something like:
Configuration File (php.ini) Path /usr/local/apache2/php/lib
Loaded Configuration File /usr/local/apache2/php/php.ini
Scan this dir for additional .ini files /usr/local/apache2/php/conf.d
Additional .ini files parsed none
Understanding the Runtime Behavior
PHP will run without a php.ini file, but it will use built-in defaults. These defaults may differ from your local development environment or production server settings. For example, memory limits, error reporting levels, and extension loading behaviors might not match what you expect. This is why many developers prefer to always have an explicit php.ini in placeâto ensure consistency across environments.
If you're enabling PEAR, you also need to make sure the PEAR channel configuration file (pear.conf) is present and correctly configured. PEAR often has its own separate configuration directory, typically /usr/local/etc/pear.ini, but this depends on how it was installed.
Avoiding Common Pitfalls
One common mistake is assuming that placing a php.ini file in the root of your web server document root will be loaded by Apache when running PHP as an Apache module. That's not how Apache works. The configuration file must be located at the path specified during the compilation of PHP or via the PHPRC environment variable.
Another pitfall is relying solely on .ini files in the conf.d directory without checking whether they're being scanned. In your original output, "Scan this dir for additional .ini files (none)" indicates that no such directory was configured during compilation. To fix this, you can either recompile PHP with a custom --with-config-file-path option or manually create the directory and symlink it if needed.
If you're working with Laravel or any other framework that relies on specific PHP settings, always ensure your php.ini is explicitly configured to avoid unexpected behavior in production environments. For more guidance on managing PHP configurations in complex deployments, resources like LaravelCompany can provide additional insights into best practices for server configuration.
Final Steps
After creating and validating the php.ini, test your setup by running a simple script that outputs ini_get('display_errors') to confirm that settings are being read correctly. If everything is working as expected, you're ready to install PEAR or make any other necessary adjustments to your PHP environment.