Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run php-fpm as root

Tags:

linux

php

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?

like image 836
Ryker.Wang Avatar asked Jun 25 '14 09:06

Ryker.Wang


People also ask

What user does PHP-FPM run as?

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.

Does PHP run as root?

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.

How does PHP-FPM work with nginx?

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.


2 Answers

See:

# php-fpm --help
...
 -R, --allow-to-run-as-root
               Allow pool to run as root (disabled by default)
like image 147
ex-nerd Avatar answered Oct 04 '22 16:10

ex-nerd


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.

  1. https://serverfault.com/a/189961
  2. https://serverfault.com/q/788669
  3. https://stackoverflow.com/a/52919706/9530790
  4. https://serverfault.com/a/867334
  5. https://www.geeksforgeeks.org/what-is-init-d-in-linux-service-management/
like image 27
shmuels Avatar answered Oct 04 '22 14:10

shmuels