How to run php-fpm as root
2 mins read

How to run php-fpm as root


How to run php-fpm as root

Last updated

How to run php-fpm as root -In certain conditions, we need to run PHP-FPM as root so that PHP-FPM users can execute files with Root permissions.

To do this (this example uses Ubuntu/Debian OS and PHP8.1), give permission to PHP-FPM so that it can be run using Root by adding the following lines to the file /lib/Systemd/System/PHP8.1- fpm.Service.

--allow-to-run-as-root

For more details, default service configuration in PHP8.1 as follows

[Unit]
Description=The PHP 8.1 FastCGI Process Manager
Documentation=man:php-fpm8.1(8)
After=network.target

[Service]
Type=notify
PIDFile=/run/php/php8.1-fpm.pid
ExecStart=/usr/sbin/php-fpm8.1 --nodaemonize --fpm-config /etc/php/8.1/fpm/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target

Be the following

[Unit]
Description=The PHP 8.1 FastCGI Process Manager
Documentation=man:php-fpm8.1(8)
After=network.target

[Service]
Type=notify
PIDFile=/run/php/php8.1-fpm.pid
ExecStart=/usr/sbin/php-fpm8.1 --allow-to-run-as-root --nodaemonize --fpm-config /etc/php/8.1/fpm/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target

After that, restart the Daemon System by running the following command

 sudo systemctl daemon-reload

Next, change the user and group in the PHP-FPM pool to root. PHP-FPM configuration files by default will be inside the directory.

/etc/php/8.1/fpm/pool.d/

If there has been no change, then the file name is default.conf. Edit the file and change the user and group to root as follows:

listen = 127.0.0.1:16004
user = root
group = root
listen.allowed_clients = 127.0.0.1
pm = ondemand
pm.max_children = 250
pm.process_idle_timeout = 10s
pm.max_requests = 100
listen.backlog = 65535
pm.status_path = /status
request_terminate_timeout = 7200s
rlimit_files = 131072
rlimit_core = unlimited
catch_workers_output = yes

Next, restart PHP-FPM by running the following command:

systemctl restart php8.1-fpm

Finished. That way, PHP-FPM now has root access so that it can make changes to files with Root permissions.

IdSysadmin

Average ranking: 0 reviews



Game Center

Game News

Review Film
Rumus Matematika
Anime Batch
Berita Terkini
Berita Terkini
Berita Terkini
Berita Terkini
review anime

Gaming Center