我有完全一样的问题。为了解决这个问题,我只是源自
/etc/environment内部
/etc/apache2/envvars。
内容
/etc/environment:
export MY_PROJECT_PATH=/var/www/my-projectexport MY_PROJECT_ENV=productionexport MY_PROJECT_MAIL=support@my-project.com
内容
/etc/apache2/envvars:
# Load all the system environment variables.. /etc/environment
现在,我可以在Apache Virtual Host配置文件和PHP中使用这些变量。
这是Apache虚拟主机的示例:
<VirtualHost *:80> ServerName my-project.com ServerAlias www.my-project.com ServerAdmin ${MY_PROJECT_MAIL} UseCanonicalName On documentRoot ${MY_PROJECT_PATH}/www # Error log. ErrorLog ${APACHE_LOG_DIR}/my-project.com_error.log LogLevel warn # Access log. <IfModule log_config_module> LogFormat "%h %l %u %t "%m %>U%q" %>s %b %D" clean_url_log_format CustomLog ${APACHE_LOG_DIR}/my-project.com_access.log clean_url_log_format </IfModule> # documentRoot directory <Directory ${MY_PROJECT_PATH}/www> # Disable .htaccess rules completely, for better performance. AllowOverride None Options FollowSymlinks Includes Order deny,allow Allow from All Include ${MY_PROJECT_PATH}/config/apache/inc.mime-types.conf Include ${MY_PROJECT_PATH}/config/apache/inc.cache-control.conf # Rewrite rules. <IfModule mod_rewrite.c> RewriteEngine on Rewritebase / # Include all the common rewrite rules (for http and https). Include ${MY_PROJECT_PATH}/config/apache/inc.rewriterules-shared.conf </IfModule> </Directory></VirtualHost>这是如何使用PHP访问它们的示例:
<?phpheader('Content-Type: text/plain; charset=utf-8');print getenv('MY_PROJECT_PATH') . "n" . getenv('MY_PROJECT_ENV') . "n" . getenv('MY_PROJECT_MAIL') . "n";?>


