Why does PHP-FPM take 5 minutes to restart on my server? - php

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.

Related

CentOS Linux release 8.0.1905 not taking change of php.ini

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

Php7.2-fpm.sock not created on reboot. Restarting php7.2-fpm doesn not work properly on raspberrypi with nginx

I am trying to make a webserver on my raspberryPI to run laravel application. I installed php7.2 and nginx. Everything was working well, I was able to see default Laravel page on my computer, so the webserver worked. Unfortunately, after rebooting raspberry the file php7.2-fpm.sock is not created and running sudo service php7.2-fpm restart does not work. It doesnt show any errors, just freezes and I have to click ctrl+c. What is interesting, after a while the above command starts working, the file php7.2-fpm.sock is created and the server works. How can I fix this bug? I need webserver to start automatically after booting raspberryPI.
My /etc/php/7.2/fpm/pool.d/www.conf file:
listen = /var/run/php/php7.2-fpm.sock

Why is PHP not recompiling with nginx?

PHP is not recompiling properly.
I have PHP 7.2 installed on Nginx using php-fpm on Centos 7. I am recompiling php with more options using ./configure, make clean, make, make test and make install.
Everything works well and no errors are thrown, except the updated php
compile is not being reflected on the phpinfo(); table. If you see the
"Build Date" it is not changing. The "Configure Command" is also not updating after recompiling.
Why could php not be recompiling and the "Build Date" not updating, and the "Configure Command" also not reflecting my changes?
I have restarted nginx, restarted php-fpm, and still no change. I can edit the php.ini file without problems as well and they do update, but the php itself is not updating after I recompile and add more options (--with-openssl). I even restarted the server. PHP files are served fine.
Can anybody help?
I just figured it out after about half a day.
The reason the new php recompile was not being recognized was because I needed to manually copy the new updated php-fpm program to the /usr/local/bin directory, like this:
cp sapi/fpm/php-fpm /usr/local/bin
And that fixed it. So basically php WAS being recompiled correctly, but that was not seen by the system because php-fpm was not manually copied to the directory nginx uses to pull php-fpm from. The file must be overwritten while php-fpm is turned off.
Bonus Tip
This is my command to reload php, php-fpm and nginx after recompiling:
# gracefully stop the php-fpm process
pkill -15 php-fpm
# copy the new recompiled php-fpm to the executable directory
cp -f sapi/fpm/php-fpm /usr/local/bin
# start php-fpm
/usr/local/bin/php-fpm
# signal nginx to reload
nginx -s reload
All in one line:
pkill -15 php-fpm && cp -f sapi/fpm/php-fpm /usr/local/bin && /usr/local/bin/php-fpm && nginx -s reload

Brew + PHP 7 + XDebug Not showing

I have problem with x-debug in brew, if i type php -v show me this :
But when in .php file i use phpinfo(); then there is no x-debug extension. so because of this i am not able to debug file in phpstorm.
You have to restart your php-fpm service in mosts cases.
find if fpm-service is running by this :
lsof -i -P
Example : PID 901
Use :
kill 901
Restart PHP-FPM Service :
sudo php70-fpm start
or You can direct use sudo php70-fpm restart but i found some issue while running this so mostly i use to kill first then start again.

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

Categories