How to force reloading php.ini file?

139,577

Solution 1

To force a reload of the php.ini you should restart apache.

Try sudo service apache2 restart from the command line. Or sudo /etc/init.d/apache2 restart

Solution 2

TL;DR; If you're still having trouble after restarting apache or nginx, also try restarting the php-fpm service.

The answers here don't always satisfy the requirement to force a reload of the php.ini file. On numerous occasions I've taken these steps to be rewarded with no update, only to find the solution I need after also restarting the php-fpm service. So if restarting apache or nginx doesn't trigger a php.ini update although you know the files are updated, try restarting php-fpm as well.

To restart the service:

Note: prepend sudo if not root

Using SysV Init scripts directly:

/etc/init.d/php-fpm restart        # typical
/etc/init.d/php5-fpm restart       # debian-style
/etc/init.d/php7.0-fpm restart     # debian-style PHP 7

Using service wrapper script

service php-fpm restart        # typical
service php5-fpm restart       # debian-style
service php7.0-fpm restart.    # debian-style PHP 7

Using Upstart (e.g. ubuntu):

restart php7.0-fpm         # typical (ubuntu is debian-based) PHP 7
restart php5-fpm           # typical (ubuntu is debian-based)
restart php-fpm            # uncommon

Using systemd (newer servers):

systemctl restart php-fpm.service        # typical
systemctl restart php5-fpm.service       # uncommon
systemctl restart php7.0-fpm.service     # uncommon PHP 7

Or whatever the equivalent is on your system.

The above commands taken directly from this server fault answer

Solution 3

You also can use graceful restart the apache server with service apache2 reload or apachectl -k graceful. As the apache doc says:

The USR1 or graceful signal causes the parent process to advise the children to exit after their current request (or to exit immediately if they're not serving anything). The parent re-reads its configuration files and re-opens its log files. As each child dies off the parent replaces it with a child from the new generation of the configuration, which begins serving new requests immediately.

Solution 4

sudo apachectl restart does the job in 2021 running Mac latest Big Sur OS

For Homebrew apache users it's brew services restart httpd

Share:
139,577
Fractaliste
Author by

Fractaliste

French IT engineer. Prefered language : Java Prefered framework : Laravel Prefered solver : Choco Prefered metasyntactic variable : plop Prefered quote : There are 10 kind of people on the world, those who understand binary, and those who don't. If needed, you can contact me on : fractaliste at gmail dot com

Updated on September 25, 2021

Comments

  • Fractaliste
    Fractaliste over 2 years

    I configured a web server last week, it worked fine.

    Today I request its homepage, I see a timezone error, as it should be configured into my php.ini file.

    I try a phpinfo(); on my webserver, it gives me:

    Configuration File (php.ini) Path   /opt/rrh/php/lib 
    

    But no php.ini file loaded.

    I investigate, the php file exists and has very large permissions:

     ls -la /opt/rrh/php/lib   
     -rwxrwxrwx  1 apache root 68448 Nov 22 10:10 php.ini
    

    I try a parse_ini_file("/opt/rrh/php/lib/php.ini"));, it returns no error...

    Of course I restart my server a dozen of time.

    What can I do more to resolve my problem?

    My system:

    1. Redhat 6
    2. Apache 2.4
    3. PHP 5.5.19 with libphp5.so apache module