Do I need to restart Apache after changing the php.ini file? - php

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?

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

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

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
Trouble changing upload_max_filesize on nginx

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

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/

Related

php.ini not updating after changes

Followed a few tutorials but it just doesn't update.
I restarted the server many times with sudo service apache2 restart and sudo apachectl restart
I ran php --ini to check all the files being loaded
I checked each file to see if it is being overwritten
I made another override and checked if its being loaded
Used the phpinfo() function to check if its being updated
I'm using PHP Version 5.5.9-1ubuntu4.21
Its a virtual machine in virtualbox
the change that I'm trying to make is for php to allow more inputs in a post.
I don't know if I should post here or in Super User
Chances are you are modifying the php.ini of the CLI instead of the one for apache. It should be under:
/etc/php/$VERSION/apache2/php.ini
Then restart apache.

Does the installation of a PHP extension require a restart or reload of PHP-FPM?

In my specific case I work with a CentOS 7 environment with both PHP-FPM 5.4 and 7.1 installed. I recently installed php-pecl-imagick and was wondering if a reload or restart was in order to make use of the service, or not at all. (and if httpd needed to be restarted/reloaded) The PHP manual doesn't seem to give an answer on this, and I've seen different recommendations in installation manuals.
You need to restart the apache service after PHP extensions are installed / uninstalled. If you have SSH communication, you can try the command below.
service http restart
// service (service name) restart

How to force reloading php.ini file?

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:
Redhat 6
Apache 2.4
PHP 5.5.19 with libphp5.so apache module
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
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
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.
sudo apachectl restart does the job in 2021 running Mac latest Big Sur OS
For Homebrew apache users it's brew services restart httpd

will "service httpd reload" reload new php.ini settings?

I'm trying to enable shorthand in PHP via setting this:
short_open_tag = 1
I then execute:
service httpd reload
however the changes do not take effect. do I need to do "service apache2 reload" instead? or does "service httpd reload" normally work to load new php.ini settings?
Thanks!
You need to
service apache2 reload
as php.ini settings changes require apache/nginx or whatever server to be reloaded
depends on the distro
Fedora based is "service httpd restart"
Debian based is "service apache2 restart"
Not sure on the other distro's
Using CentOS and Apache 2.4 you could use the following command to reload the apache configuration including php.ini
apachectl graceful

Trouble changing `upload_max_filesize` on nginx

I've see a few other similar questions on here, but most of the answers are Apache specific (dealing with their .htaccess file) and I'm using nginx.
I'm having trouble making my change to the upload_max_filesize in php.ini stick. I'm using nginx, php5 and wordpress on Debian.
When I run phpinfo() I see the following output:
Loaded Configuration File /etc/php5/cgi/php.ini
I then go to the relevant .ini file, change a few values, and then restart nginx. When I fire up a phpinfo() plugin I got for wordpress, it reports the values as unchanged.
I'm at a loss because phpinfo() reports that it is loading config values from the file that I've changed, but it doesn't report the changes.
You might be using FAST CGI:
[webserver] <----> [fcgi daemon]
`- [php]
If you restart the webserver, PHP is not restarted, so still has the old ini values because it didn't reload the ini file.
Restarting the fcgi daemon solves that issue, PHP will be restarted, re-reading the ini.
Some fcgi daemons have a command that reloads the child processes more gracefully. Depends on what you use.
For me the problem was a syntax error in the custom php.ini file, which I found after checking the error logs.
This might help the ones that are using php -i from the terminal to check php.ini settings.
In my case, I increased the upload_max_filesize from 2M to 20 MB by editing /etc/php/7.3/apache2/php.ini and restarted the apache by apachectl restart command.
I used php -i command from the Debian terminal to see the changes are in effect but upload_max_filesize was still 2M.
Then I realized settings readings came from /etc/php/7.3/cli/php.ini because I was using php -i from the terminal instead of phpinfo() function in a web page.
$ sudo service php7.4-fpm restart
Resolved my problem. change the php version to the one you using.

Categories