I know the risks about running php-fpm as root. However there are situations where one would need to do it, like appliances, accessing operating system resources or even for testing purposes.
I have tried to change the user and group of php-fpm.d/www.conf to root when I restart the php-fpm process it raise an error:
Starting php-fpm: [26-Jun-2014 00:39:07] ERROR: [pool www] please specify user and group other than root
[26-Jun-2014 00:39:07] ERROR: FPM initialization failed
[FAILED]
What should I do. Anyone help?
By default the web server and php-fpm runs with the user called www-data. It is often required that we need to run php-fpm on different users for different websites. Running each site with its own uid/gid is more secure and easier to deal with.
What do you need to run PHP as root? You will need to use visudo and edit the sudoers file. The visudo command is available on all UNIX and Linux systems. It provides a safe of editing the /etc/sudoers file.
PHP-FPM, on the other hand, runs outside the NGINX environment by creating its own process. Therefore when a user requests a PHP page the nginx server will pass the request to PHP-FPM service using FastCGI. The installation of php-fpm in Ubuntu 18.04 depends on PHP and its version.
See:
# php-fpm --help
...
-R, --allow-to-run-as-root
Allow pool to run as root (disabled by default)
Just adding -R
(like this ans. suggests) to your command may not work. It depends how your running the command to start php-fpm
.
If you're using service php-fpm restart
and it's using /etc/init.d instead of systemctl
(see here), then you'll have to add -R to the DAEMON_ARGS
variable located in the /etc/php/<phpversion>/fpm/php-fpm.conf
script. (This variable is used in the do_start()
function. See here).
If it's using systemctl
then you'll have to edit the script used by systemctl
which should be located in /lib/systemd/system/<phpversion>-fpm.service
. Append -R
to the ExcecStart
variable. Then run systemctl daemon-reload
and systemctl start php<version>-fpm
(See here)
I used the following questions/answers/resources to help me compile this solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With