How to restart php fpm

How to restart php fpm

Как вы перезапустите php-fpm?

Мне нужно перезагрузить мой php.ini, и в диалоге помощи нет ничего о его перезапуске.

Примечание : добавьте, sudo если не root

Использование сценариев SysV Init напрямую:

Использование скрипта сервисной обертки

Использование Upstart (например, Ubuntu):

Использование systemd (более новые серверы):

Или любой другой эквивалент в вашей системе.

Для Mac OS X это то, что я делаю:

Сделайте скрипт /usr/local/etc/php/fpm-restart :

Как правило, все service php5-fpm restart будет в порядке, на современном распространении.

Но иногда это терпит неудачу, говоря вам restart: Unknown instance: (или тому подобное).

Теперь, если вы не любите перезагружать свой сервер, просто убейте процессы и начните все сначала (отредактировано здесь):

Это должно работать:

Для Mac OSX brew services restart php56 работал для меня.

У меня была проблема с перезапуском php7-fpm, потому что я не знал, как именно была названа служба. Эта функция дала мне ответ:

service php7.0-fpm restart

php-fpm перезапустится, если вы отправите сигнал USR2 основному процессу:

Затем создайте файл /etc/php-fpm.pid и убедитесь, что php-fpm имеет разрешение на его изменение:

Теперь, когда в следующий раз запустится php-fpm, вы сможете получить его pid и перезапустить его так:

Или вы можете объединить их в одну команду:

Can’t start or stop php-fpm on Ubuntu

I’m trying to install php-fpm for the first time on Ubunutu. I have installed it via

It looks like it is running, so I tried to stop it by executing:

This appears to do nothing. No error message is given on the command line and when I run ps again, the same process exists. I am able to get it to stop if I run:

The first time I ran this command I got an error about not being able to find a directory, but the process did stop. When I start and stop the service again, it seems to work fine and I don’t get an error message about a missing directory.

Can someone explain to me why the /etc/init.d/php5-fpm method does not work? All of the tutorials I’ve seen use this method to start and stop php5-fpm.

3 Answers 3

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

Quick answer. you don’t use the init.d scripts to control (stop / start /status etc) of php-fpm because it’s controlled by the newer ‘upstart’. Use the following service command to stop and restart etc. I think it’s a bit of a ‘bug’ that it quietly exits without stating that it’s now controlled by upstart.

More detailed look at this problem, that leads to above explanation.

I see exactly the same problem on Ubuntu 14.04, you can stop / start / get status of php5-fpm using the service commands: I.E these work fine :-

BUT the /etc/init.d/php5-fpm command has no effect :-

Note nothing is returned, and the process is not stopped. Similarly for status and start versions, nothing is returned and the process is unaffected.

I found the line that it exits the init.d script on. init_is_upstart :

Surely it should state an error message here. like ‘Use service commands to stop/start php-fpm’.

I had similar problem that relates to php5-fpm on Ubuntu 14.10. I have configured php5-fpm for one of the virtual hosts and when trying to browse the site i got the 503 Service Unavailable. Every time I tried

I got in the syslog the following:

What I tried then is to check if my php5-fpm configuration for this virtual host pool is actually working. It was configured to listed on a TCP port with the following configuration in /etc/php5/fpm/pool.d/www.conf I have correctly instructed the pool to listed as follows:

I tried restarting few more times with the service command and since it did not work I decided checking the startup scripts. I edited the /etc/init/php5-fpm.conf and I noticed that I already have the latest bug-fixed version of the line «reload signal USR2». Then I noticed the following line:

I executed it in the shell and noticed the following:

Restart PHP-FPM from a PHP script

I am running a LEMP stack and wish to write a simple control panel for it.

So, I want to be able to restart php-fpm from a php script. To achieve this, this is what I did.

Created a binary wrapper in c like this php-shell.c:

This program was compiled like this:

I have then added nginx user to sudo visudo like this:

Then I executed the command in a php script like this:

As soon as I run this script php script, I get 502 Gateway Error and it appears all php-fpm processes has been killed off and it does not start back up.

How to restart php fpm. Смотреть фото How to restart php fpm. Смотреть картинку How to restart php fpm. Картинка про How to restart php fpm. Фото How to restart php fpm

1 Answer 1

Congratulations! You are on the path to giving unrestricted root access to anyone who can make your nginx server run arbitrary code. You had better be sure that every single CGI script and php page and anything else that might be used to execute arbitrary code is secure.

Your C wrapper is equivalent to configuring sudo to allow nginx to run any command at all as root.

DON’T do it like that.

Write individual shell script (or whatever) wrappers for specific commands and then grant sudo access only to those wrapper scripts. For example, /usr/local/sbin/restart-nginx.sh which does nothing but service nginx restart and give nginx sudo access to that script.

The simpler and less complicated each individual script, the better. Safest of all is to take no user input at all, not from the command-line and not from environment variables.

How To Use a Bash Script To Restart Linux Server Services

Use a script to restart critical Linux services such as the web or database server. Restart nginx, apache2, MySQL or PHP-fpm automatically.

If you manage your own WordPress web server then you have undoubtedly come across many situations where your web apache, nginx, MySQL or PHP-fpm services have stopped.

Sometimes the reason is unknown and things just crash from time to time.

Using the Linux crontab service we can write a simple bash script to test to see if these services have stopped and restart them.

You can use whatever editor you are comfortable with.

Here’s the command line code to create the file in nano:

sudo nano /opt/launch-crashed-services.sh

Here is the bash script.

Change the service names to the ones you are running, e.g. “apache2” or whatever PHP version you are running.

The script uses the service status command to output the status of a particular service such as mysql.

We then run this through grep looking for the phrase “active (running)”.

If this is not found, we ask the system to restart the service.

Save the file to /opt/launch-crashed-services.sh

Then ensure that it is runnable from the command line using:

sudo chmod +x /opt/launch-crashed-services.sh

Scheduling Service Restarts Using Crontab

It would be a pain to have to SSH into our server every time a service crashes to run the script.

Instead we can call the script directly from a crontab service and have it running as frequently as we need it to.

Edit your root crontab list using:

It’s important to use the root crontab using the command above and not to edit your own user profile crontab, otherwise, it will not work properly.

Add the following line to the bottom of the root crontab list:

*/1 * * * * /opt/launch-crashed-services.sh > /dev/null 2>

This will run the script every minute but you can change that for whatever works for your server.

Now if a critical service crashes, the server will attempt to restart it.

how restart or reload nginx using php

i change nginx conf file with php next i want restart nginx. but can not restart nginx

To do exec(«service nginx restart») I need acces to php-fpm as root, so i go to /usr/local/etc/php-fpm.conf

and change it to:

and next enter service php-fpm restart

and this means it can’t be run as root.

So how can I restart or reload nginx using php?

How to restart php fpm. Смотреть фото How to restart php fpm. Смотреть картинку How to restart php fpm. Картинка про How to restart php fpm. Фото How to restart php fpm

How to restart php fpm. Смотреть фото How to restart php fpm. Смотреть картинку How to restart php fpm. Картинка про How to restart php fpm. Фото How to restart php fpm

2 Answers 2

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

I need acces to php-fpm as root

OMG NO

If you really must expose this functionality via a webserver then do it via sudo. Similarly any changes to your system config should be via sudo.

BTW: one crucially important thing missing from your script is ignore_user_abort(). When (if) nginx is restarted by PHP the connection to the browser will be lost. By default, PHP will terminate at this point.

NB

I am using Centos, so some of the file names, paths, and commands I use may be slightly different for you.

Security

Make php run as root

Edit

Источники информации:

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *