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

systemd - private temp directories and permissions

· 52CE 我爱测

When setting up private temporary directories, I'm faced with some annoying problems. Whenever the service (php-fpm in this case) stops, the temporary directory is wiped. Not quite as I want, because PHP expects to find the direc…

问题原文

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

When setting up private temporary directories, I'm faced with some annoying problems. Whenever the service (php-fpm in this case) stops, the temporary directory is wiped. Not quite as I want, because PHP expects to find the directories /tmp/sessions and /tmp/uploads at minimum.

Currently, I have a script that "bootstraps" the creation and permissions of these directories, so that if I restart php-fpm, I can re-create them in a jiff.

However, this "directory-creation" script does not solve my problems after all. PHP complains about "Permission Denied" when writing to these folders. Even if permissions are set to wide open. If I manually create /tmp/test, PHP is not able to write to that directory. If I create the directory from within the php-fpm process (e.g. via a HTTP request), then PHP is suddenly able to write there. This makes somewhat sense, that the owner of the private temporary directory (php-fpm), is the one that can do CRUD operations there.

So how can one really "bootstrap" a private temporary directory? It would be nice if the directories got created by systemd itself, or php-fpm when it first starts, but I haven't found a way of doing this.

My last option is to ditch the private temporary directories, but this is really something I don't want to do.

Any thoughts?

已采纳解答

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

By help from Aaron the permission issue was resolved by setting the correct SELinux security context. The "bootstrapping" of private temp space was solved using a custom post-start script in the systemd configuration (/etc/systemd/system/php-fpm.service):

.include /lib/systemd/system/php-fpm.service

[Service]
ExecStartPost=/bin/php -f /opt/www/create_tmp_dirs.php

The script itself is responsible for creating directories under /tmp (which gets written to the private tmp space), setting correct permissions and ownerships, and of course the correct security context.

When I created the directories manually, the security context was set to user_tmp_t whilst the correct context should be httpd_tmp_t.

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

资料来源与适用范围

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

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

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