Does PHP Reload php.ini on Every Request or Require Apache Restart?


2 views

When modifying PHP configuration through php.ini, developers often wonder whether changes take effect immediately or require a web server restart. The behavior depends on your PHP installation mode:

In traditional Apache setups using mod_php, PHP configuration is loaded only once when Apache starts. Any changes to php.ini require an Apache restart to take effect:

# Restart Apache on Ubuntu/Debian
sudo systemctl restart apache2

# Restart Apache on CentOS/RHEL
sudo systemctl restart httpd

With PHP-FPM (FastCGI Process Manager), the behavior differs. While PHP-FPM loads php.ini at startup, you can reload it without restarting the entire service:

# Reload PHP-FPM configuration
sudo systemctl reload php-fpm

To verify if your changes took effect, create a test script:

<?php
phpinfo();
?>

Compare the "Loaded Configuration File" path and your modified settings.

For development environments where frequent configuration changes occur, consider these alternatives:

# Per-directory configuration using .htaccess
php_value memory_limit 256M

# Runtime configuration in PHP scripts
ini_set('max_execution_time', 300);

While reloading php.ini on every request would offer flexibility, it would create significant overhead. The current design balances flexibility with performance by loading configuration at startup.


When modifying PHP's configuration through php.ini, the reload behavior depends on your SAPI (Server API) implementation:

  • Apache module (mod_php): Requires Apache restart (graceful reload may work)
  • PHP-FPM: Requires pool restart (sudo service php-fpm reload)
  • CLI: Reads php.ini on each invocation

PHP loads its configuration during initialization. For web server environments:

// Apache module example (httpd.conf)
LoadModule php_module modules/libphp.so
PHPIniDir "/etc/php.ini"

The configuration becomes part of the parent process memory space. This explains why changes require a service restart.

Check current settings without restarting:

<?php
// View effective settings
phpinfo(INFO_CONFIGURATION);

// Check specific value
echo ini_get('memory_limit');
?>

For zero-downtime configuration updates:

  1. Use PHP-FPM with separate worker pools
  2. Implement blue-green deployment patterns
  3. Consider .user.ini files for per-directory settings
  • Verify correct php.ini path with php --ini
  • Check for multiple PHP installations
  • Confirm no .htaccess overrides exist
  • Inspect Apache error logs for configuration errors