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

How can I create separate configuration files for php (cli) and php-fpm on an arch linux

· 52CE 我爱测

Is it possible to create separate php.ini files for php (cli) and php-fpm, like it is possible on debian and ubuntu with two folders /etc/php/7.0/cli and /etc/php/7.0/fpm ? I will be also cool if I can load independent modules wi…

问题原文

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

Is it possible to create separate php.ini files for php (cli) and php-fpm, like it is possible on debian and ubuntu with two folders /etc/php/7.0/cli and /etc/php/7.0/fpm?

I will be also cool if I can load independent modules with a conf.d directory for each subsystem.

Has anyone an idea how can I configure it separately?

I also tried to use the structure like it is configured in ubuntu 16.04 without success.

已采纳解答

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

I have found a few tweaks to solve my problem.

First: load a separate php.ini files:

A user in a arch linux forum posted this from the man php page:

FILES
   php-cli.ini    The configuration file for the CLI version of PHP.

   php.ini        The standard configuration file will only be used when php-cli.ini cannot be found.

If I creating a /etc/php/php-cli.ini file only this file will be loaded and not /etc/php/php.ini with the php cli command. php-fpm is still loading the /etc/php/php.ini.

Second: load different module configurations:

I have found in the php documentation the PHP_INI_SCAN_DIR environment variable. Therefore I have moved the /usr/lib/systemd/system/php-fpm.service file to /etc/systemd/system/php-fpm.service and added the following configuration to the service file:

[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=notify
Environment="PHP_INI_SCAN_DIR=/etc/php/fpm/conf.d" ; <-- I have added this line
PIDFile=/run/php-fpm/php-fpm.pid
ExecStart=/usr/bin/php-fpm --nodaemonize --fpm-config /etc/php/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target

After restarting/reloading the services, php-fpm loads only the files from /etc/php/fpm/conf.d and no longer from /etc/php/conf.d. This allows me to configure cli and fpm separately.

Perhaps this is not the best solution but I fits to my usecase. If everyone have a better solution, don't hesitate to post your answer!

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

资料来源与适用范围

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

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

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