【发布时间】:2018-09-02 01:15:01
【问题描述】:
我目前正在使用 Raspbian 9 在 RaspberryPi 上设置 Web 服务器,并希望在其上部署高效的 Symfony4 网页。
对于这种情况,我在 Apache2 中创建了一个 vHost 文件,其中包含所需的环境变量。但是当我正在执行“composer install --no-dev”(因为我不想使用 dotenv)时,我收到了错误“PHP 致命错误:未捕获的 RuntimeException:APP_ENV 环境变量未定义。您需要为配置定义环境变量或添加“symfony/dotenv”作为 Composer 依赖项以从 .env 文件加载变量。"
在 Symfonys 公共文件夹中创建 test.php 文件并查询“echo $_SERVER['APP_ENV']”时,我得到了正确设置的“prod”变量。
感谢您的帮助!
附加匿名虚拟主机文件:
<VirtualHost *:80>
ServerName gate.keeper
ServerAlias www.gate.keeper
DocumentRoot /var/www/gk3/public
<Directory /var/www/gk3/public>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeeScript assets
# <Directory /var/www/gk3>
# Options FollowSymlinks
# </Directory>
# optionally disable the RewriteEngine for the asset directories
# which will allow apache to simply reply with a 404 when files are
# not found instead of passing the request into the full symfony stack
<Directory /var/www/gk3/public/bundles>
<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
</Directory>
ErrorLog /var/log/apache2/gk3_error.log
CustomLog /var/log/apache2/gk3_access.log combined
# optionally set the value of the environment variables used in the application
SetEnv APP_ENV "prod"
SetEnv APP_SECRET "secret"
SetEnv DATABASE_URL "mysql://user:password@localhost:3306/db_name"
</VirtualHost>
【问题讨论】:
标签: php apache deployment environment-variables symfony4