B
B
bitaz2014-08-22 10:46:59
PHP
bitaz, 2014-08-22 10:46:59

Restarting nginx from php - how?

I can't get nginx restart from php (php under apache) in any way.
I tried shell_exec("sudo /etc/init.d/nginx reload"), having previously added this command to /etc/sudoers, but sudo does nothing through shell_exec, everything is ok through the console.
Then I decided to go with the cron + bash method, with the creation of the .go_restart file via php: I
run the script using cron, it works as it should via the console, when launched via cron, the .go_restart file itself is deleted, but nginx does not restart.

if [ -f <...>/.go_restart ];
then
rm -f <...>/.go_restart;
service nginx reload
fi

What's wrong?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
B
bitaz, 2014-08-22
@bitaz

Solved the problem - disabled SElinux for apache, commented out #Defaults requiretty
in /etc/sudoers.
Thanks to all.

A
Alexander Taratin, 2014-08-22
@Taraflex

I'm not very knowledgeable, but why reload and not restart?
service nginx restart

T
tho, 2018-09-05
@tho

The fact is that when you execute the sudo nginx reload command, the system should ask for a password. And there is no way to enter it through shell_exec.
It is solved by adding something like this line to sudoers:
user - the user from which the php script is launched.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question