73

If I make a change to a setting in the php.ini file - do I need to restart Apache in order for it to take effect?

George Chalhoub
  • 14,968
  • 3
  • 38
  • 61
simbro
  • 793
  • 1
  • 5
  • 9

5 Answers5

80

Depends, actually. Depends on how you use php inside that webserver:

  • using php as module inside the http server: you have to restart the http server process
  • using php as cgi backend: you do not have to restart the http server process or anything else
  • using php fastcgi: you have to restart the fastcgi daemon, not the http server
  • using php-fpm: you have to restart the fpm server process, not the http server process
arkascha
  • 41,620
  • 7
  • 58
  • 90
  • 11
    PHP-FPM you need to restart to avoid configuration inconsistency. Some workers will lay dormant and keep the old configuration, while new workers will get the new configuration. – Leigh Oct 15 '12 at 09:12
  • Maybe I should be asking a new question, but how do I _know_ how PHP is used? – osullic Jan 14 '20 at 16:04
  • @osullic Certainly go and as your question, that is what this site is for, isn't it? ;-) But _before_ asking... what do you actually mean by "PHP is used"? Sounds trivial at first, but is it? How would you say that assertion is true for a given http server, when? – arkascha Jan 14 '20 at 23:11
  • How would someone, who has inherited a php/apache project, go about determining this set up? – scrollout May 03 '22 at 17:15
  • 1
    @scrollout Depends on your setup, actually. Let's have a chat: https://chat.stackoverflow.com/rooms/244443/do-i-need-to-restart-apache-after-changing-the-php-ini-file – arkascha May 03 '22 at 17:34
15

On Debian 8 I had to restart PHP-FPM (and Apache) The above answers are correct, but here are the commands so you won't have to googling them.

Restart Apache :

/etc/init.d/apache2 restart

Restart php5-fpm :

sudo service php5-fpm restart
Kaizoku Gambare
  • 3,143
  • 3
  • 29
  • 41
  • 2
    This actually depends on the distribution you are using, the required commands differ. – arkascha Jun 18 '19 at 22:12
  • 1
    I found [this answer](https://serverfault.com/a/189961/243621) that shows php-fpm restart based on the PHP version you are running. – Shadoath Jan 05 '20 at 23:35
7

That depends on the SAPI you're using. If you're using PHP as an Apache module for example, you need to restart apache so that the php.ini values take effect.

If you're using FCGI, you need to restart the FCGI daemon for the PHP script that you want to see the values changed. Compare with

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836
4

It depends on what OS and version you are running.

I am running Apache/2.4.29 under Ubuntu.

PHP Version 7.2.24.

I restart apache with the following command and the restart is needed after modifying the php.ini file:

sudo service apache2 restart
lcompare
  • 917
  • 12
  • 10
-1

Not sure about Apache but on Windows with IIS a restart is not required.

Either way, considering the myriad of different configurations out there with PHP, an easy way to check is to load your phpinfo.php file in a browser and confirm the value of a setting, then change that setting in php.ini and reload phpinfo.php to see if it's picking up your change.

If you don't know what I mean by "phpinfo.php" check this page: https://blogtimenow.com/knowledge-base/create-phpinfo-php-file-page/

Vincent
  • 1,741
  • 23
  • 35
  • 1
    although its not helpful with apache, saying that it is not needed in iis is ONLY correct if the ini-file is monitored by iis – mech Feb 06 '23 at 14:39