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
Related
I'm testing file upload between client and server.
But file upload not working because below error.
Unable to move '/tmp/phpxQHW5q' to '/var/www/html/mri_image/test.jpg' in /var/www/html/server_form.php on line 49, referer: http://192.168.1.12/client_form.php
I have searched this problem at stackoverflow.
Most solution is permision problem.
So, tmp and mri_image folder own by apache and changed mod 755.
Then, not working i want to your help
For reference, my os is CentOS 7, php version is 7.3
I had an issue recently with Apache and PHP trying to write to /tmp, but stating that the script failed with an error "No such file or directory"
Centos 7 uses systemd, which has an awesome feature (PrivateTmp) that breaks Apache/PHP access to /tmp folders (particularly in cases where the files need to be shared to other processes/seen by others. This feature works by creating a sort of "virtual" /tmp directory for each process, so a file seen by Apache wouldn't be seen by PHP, etc.
First, copy the httpd.service and php-fpm.service files from /usr/lib/systemd/system/ to /etc/systemd/system using the commands below.
cp /usr/lib/systemd/system/httpd.service /etc/systemd/system/. && cp /usr/lib/systemd/system/php-fpm.service /etc/systemd/system/.
After copying those into place, edit each copy of the files in the new location and change the line with PrivateTmp=true to PrivateTmp=false using vi, or your preferred text editor.
vi /etc/systemd/system/httpd.service
vi /etc/systemd/system/php-fpm.service
After those changes, you need to restart systemd, as well as php-fpm and apache.
Restart systemd:
sudo systemctl daemon-reload
Restart apache:
sudo systemctl restart httpd
Restart php-fpm:
sudo systemctl restart php-fpm
I want to remove output_buffering and want to make change to memory_limit by editing etc/php.ini file
But none of my changes are taking effect.
After editing etc/php.ini file as a super user. I've restarted httpd.service using following command
sudo systemctl restart httpd.service
I am using centOS 8
[root#backend adminuser]# cat /etc/*release
CentOS Linux release 8.0.1905 (Core)
NAME="CentOS Linux"
VERSION="8 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="8"
CentOS Linux release 8.0.1905 (Core)
CentOS Linux release 8.0.1905 (Core)
php-common packages are as below
[root#backend adminuser]# rpm -qc php-common
/etc/php-zts.d/20-bz2.ini
/etc/php-zts.d/20-calendar.ini
/etc/php-zts.d/20-ctype.ini
/etc/php-zts.d/20-curl.ini
/etc/php-zts.d/20-exif.ini
/etc/php-zts.d/20-fileinfo.ini
/etc/php-zts.d/20-ftp.ini
/etc/php-zts.d/20-gettext.ini
/etc/php-zts.d/20-iconv.ini
/etc/php-zts.d/20-phar.ini
/etc/php-zts.d/20-sockets.ini
/etc/php-zts.d/20-tokenizer.ini
/etc/php.d/20-bz2.ini
/etc/php.d/20-calendar.ini
/etc/php.d/20-ctype.ini
/etc/php.d/20-curl.ini
/etc/php.d/20-exif.ini
/etc/php.d/20-fileinfo.ini
/etc/php.d/20-ftp.ini
/etc/php.d/20-gettext.ini
/etc/php.d/20-iconv.ini
/etc/php.d/20-phar.ini
/etc/php.d/20-sockets.ini
/etc/php.d/20-tokenizer.ini
/etc/php.ini
For SSE Script I want to make output_buffer as null or Off like my another server but its not taking any change. I tested by changing php.ini as a root user and restarted httpd services.
I am assuming you are using php-fpm
Following command worked for me.
Connect via terminal and Make sure you are Super(Root) user
sudo su
Now run following command
sudo systemctl restart php-fpm.service
Note : Test by making small change like increasing or decreasing memory_limit in php config file and run above command and review change using phpinfo()
You don't mention whether you're using mod_php or php-fpm. Running sudo systemctl restart httpd.service only helps for mod_php. If you're using php-fpm, you need sudo systemctl restart php-fpm.service instead.
Changing etc/php.ini does not work any more.
You need to add your own .ini file now under "/etc/php.d" and restart php
confirm the path from phpinfo. Look for
"Scan this dir for additional .ini files /etc/php.d"
create file (30 prefix to file name is like priority or how late to load):
sudo vi /etc/php.d/30-user.ini
Add entries like:
max_execution_time=200
post_max_size=100M
upload_max_filesize=100M
Restart PHP (restarting Apache does not help)
Check the service (if not present ..restarting Apache should work: sudo systemctl restart httpd )
sudo systemctl status php-fpm
Resart the service
sudo systemctl restart php-fpm
I am using PHP-FPM with default settings. My server is running the latest Arch Linux.
I issue command sudo systemctl restart php-fpm and it takes five minutes to restart and get back to the prompt.
Is there a known solution to this problem?
This is caused by the way the systemctl script for PHP-FPM was created. I too had this exact same problem. Here is how I've resolved it.
First find your start-up script, if you don't know you can do systemctl status php-fpm and you'll see something like: /etc/systemd/system/php.service
Now edit this file and it should look like this:
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=notify
PIDFile=/run/php-fpm/php-fpm.pid
PrivateTmp=true
ExecStart=/usr/bin/php-fpm --nodaemonize --pid /run/php-fpm/php-fpm.pid
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
Change it to this:
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
ExecStart=/usr/bin/php-fpm --nodaemonize
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
[Install]
WantedBy=multi-user.target
One the file is changed run this command to refresh systemctl -> systemctl daemon-reload
Now restart FPM. I'd recommend to shutdown FPM first before making changes to this file. Once the changes are made FPM will start/stop/restart instantly.
Now I don't know why as of just yet, but sometimes after I've made this change it would appear that FPM still takes forever to start/stop/restart. So I just went ahead and rebooted my machine and from then on it was instant. So I'm guessing something was hanging that I haven't found yet but a reboot resolved that. I know you shouldn't have to reboot, but until I can find where exactly it's hanging this did the trick for now.
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
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/