LoginSignup
0
1

php-fpm + apache環境での環境変数の持たせ方

Last updated at Posted at 2021-04-12

php-fpm環境下でApache httpdのSetEnvで設定された環境変数は、PHPのenv()等では取得できるが、
execで実行されるコマンドには、SetEnvで設定された環境変数が反映されなかったのでfast-実施した回避策を書く!

要約

  • ApacheのSetEnvは使わず/etc/environmentに環境変数を記載して利用する

/etc/environmentの環境変数利用手順

/etc/systemd/system/httpd.serviceを作成

  • 以下内容で作成する
.include /lib/systemd/system/httpd.service

[Unit]
After=network.target remote-fs.target nss-lookup.target httpd-init.service cloud-config.service

[Service]
UMask=002
EnvironmentFile=/etc/environment

/etc/systemd/system/php-fpm.serviceを作成

  • 以下内容で作成する
.include /lib/systemd/system/php-fpm.service

[Unit]
After=syslog.target network.target cloud-config.service

[Service]
UMask=002
EnvironmentFile=/etc/environment
PrivateTmp=false

/etc/php-fpm.d/www.confに1行追加

  • 以下を追記
clear_env = no

あとは/etc/environmentに環境変数を記載していくだけ!

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1