简体   繁体   English

Apache / PHP和Systemd / node可读的环境变量

[英]Environment variables readable by Apache/PHP and Systemd/node

On the same server, I have a apache php application and a nodejs application (started via systemd). 在同一台服务器上,我有一个Apache php应用程序和一个nodejs应用程序(通过systemd启动)。

For systemd/node, I put the following config: 对于systemd / node,我输入以下配置:

[Service]
EnvironmentFile=/etc/environment

For apache, I have put the following line in /etc/apache2/envvars 对于apache,我将以下行放在/etc/apache2/envvars

. /etc/environment

My problem is: 我的问题是:

  • It works in PHP and standalone node if I put export before each variable, but not in node via systemd 如果我将export放在每个变量之前,则它可以在PHP和独立节点中使用,但不能通过systemd在节点中使用
  • It works in node via systemd if I remove the export 如果我删除export它将通过systemd在节点中工作

Is there a way for me to write these variables in a single place that can be used by Apache/PHP and node started via systemd ? 有没有办法在一个地方写这些变量,Apache / PHP可以使用这些变量,并且可以通过systemd启动节点?

You can use the export statement version of your environent file if you change your ExecStart= line to something like: ExecStart=/bin/sh -c ". /etc/environment && exec /PATH/TO/NODEJS/APPLICATION" . 如果将ExecStart=行更改为类似以下ExecStart=/bin/sh -c ". /etc/environment && exec /PATH/TO/NODEJS/APPLICATION"则可以使用环境文件的导出语句版本: ExecStart=/bin/sh -c ". /etc/environment && exec /PATH/TO/NODEJS/APPLICATION" This is kludgy though. 不过这很糊涂。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM