Changing cache_dir and log_dir with Symfony2

前端 未结 7 2044
感动是毒
感动是毒 2021-02-19 13:50

Because of deployment constraints, I would like to have the log and cache directories used by my Symfony2 application somewhere under /var/... in my file system. For this reason

7条回答
  •  故里飘歌
    2021-02-19 14:24

    No accepted answer, and a really old question, but I found it with google, so I post here a more recent way to change the cache directory, and the logs directory, (source here)

    • remember, short syntax for arrays require php 5.4
    • you can select the env to modify, and manage different cache and logs directories if you want

      public function getCacheDir()
      {
          if (in_array($this->environment, ['prod', 'test'])) {
          return '/tmp/cache/' .  $this->environment;
      }
      
      return parent::getCacheDir();
      }
      
      public function getLogDir()
      {
          if (in_array($this->environment, ['prod', 'test'])) {
          return '/var/log/symfony/logs';
      }
      
      return parent::getLogDir();
      }
      

提交回复
热议问题