douyinlai2169 2019-03-09 20:59
浏览 105
已采纳

如何使用symfony环境dev和prod

This may seem a dumb question, I need my symfony 3 app to behave different in production than it does in my local machine. I know there is an entry point for each env, app.php and app_dev.php

I don't want to change the application web/.htaccess file because it's followed by git, I was expecting an 'env' var or something similar in app/config.yml but there is also a config.yml and a config_dev.yml, so it has to be another place where I can define if I am working with prod or dev env.

Documentation says that I need to setup my apache server to use either web/app.php or web/app_dev.php, and this is my question. I'm using apache 2.4 and I tried using the following directive:

<VirtualHost *:8000>
    <directory>
        ...
        DirectoryIndex app_dev.php
    </directory>
</VirtualHost>

I restarted apache, but when I type localhost:8000 in my browser, it keeps using the default app.php, I need my apache server to use app_dev.php, I don't want to use the built-in server because it gets buggy after a while.

Can anyone please help me with the apache configuration to use the dev env?

  • 写回答

1条回答 默认 最新

  • duangangmo0583 2019-03-09 21:14
    关注

    I think you have the following problems: regardless of which DirectoryIndex you define, the server also picks ups some settings from .htaccess. Could it be possible that you have another reference to app.php in there, like RewriteRule ^(.*)$ app.php [QSA,L]?

    Then you could do the following: move that exact setting from .htaccess to your server configuration, both locally and on the production server. Then you can keep all other settings independent from your enviroment.

    If this does not help yet, please share the content of .htaccess.

    Another way of solving could be to use a recent Symfony version and put everything that might change between environments in the .env file. Don't put it under version control, as this file might contain sensitive information. Then have a look at the current basics: you no longer have a app.php and app_dev.php, as the changes were only little. A common index.php is used, and it reads all current settings from .env

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动