大网数据广告活动
服务器运维问答

Correct web user for PHP-FPM under Nginx

· 52CE 我爱测

I've always been accustomed to running PHP under Nginx as the www-data user, for everything: php service, cron, CLI, etc. Recently though, after reading up on firstly this article and then this article , I'd like to know how nece…

问题原文

原帖链接 · maGz · CC BY-SA 3.0

I've always been accustomed to running PHP under Nginx as the www-data user, for everything: php service, cron, CLI, etc. Recently though, after reading up on firstly this article and then this article, I'd like to know how necessary it is to run these services using a different user? This is for a single Magento 2 application on the server.

Is it sufficient to create a new user:

adduser magento2user
passwd magento2user

usermod -a -G www-data magento2user

Then in php /usr/local/etc/php-fpm.d/www.conf:

[www]  
user = magento2user
group = magento2user
...
listen.owner = www-data
listen.group = www-data

And then finally:

chown -R magento2user:www-data /var/www/html

My confusion is coming from this on the Magento 2 DevDocs:

We recommend two users if you run your own Magento server: one to transfer files and run command-line utilities, and a separate user for the web server software. When possible, this is preferable because it’s more secure.

Instead, you have separate users:

• The web server user, which runs the Magento Admin (including Setup Wizard) and storefront.

• A command-line user, which is a local user account you can use to log in to the server. This user runs Magento cron jobs and command-line utilities.

So by this, should PHP-FPM be run as www-data, but the files be owned by magento2user who belongs to the www-data group?


EDIT after Simon Greenwood's answer below

If I run ps aux | grep nginx | grep -v grep I get the following output:

1 www-data   0:00 nginx: master process nginx -g daemon off;
7 www-data   0:00 nginx: worker process

... so I don't think I need an entry in 'etx/nginx/nginx.conf that reads user www-data

已采纳解答

原帖链接 · Simon Greenwood · CC BY-SA 3.0

I would tend to recommend running nginx as the system user, so www-data in your case, and php-fpm as a non-privileged user, which can be the same as the shell user. You don't have to have your non-privileged user in the www-data group as nginx passes requests to php-fpm. for execution. The setup suggested by the Magento docs assumes apache and mod_php, which would require the permissions setup as described above.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-12-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。