I am trying to get Sulu (minimal) running on a vagrant box. For performance reasons, I define custom paths for the log and cache directories in order to get them out of the synced vagrant folder:
In /app/AbstractKernel.php
:
public function getCacheDir()
{
if (in_array($this->environment, array('dev', 'test'))) {
return '/run/shm/website/cache/' . $this->environment;
}
// Sulu default
return dirname($this->rootDir) . DIRECTORY_SEPARATOR
. 'var' . DIRECTORY_SEPARATOR
. 'cache' . DIRECTORY_SEPARATOR
. $this->getContext() . DIRECTORY_SEPARATOR
. $this->environment;
}
public function getLogDir()
{
if (in_array($this->environment, array('dev', 'test'))) {
return '/run/shm/website/log';
}
if ( in_array($this->environment, array('prod'))) {
return '/var/log/website';
}
// Sulu default
return dirname($this->rootDir) . DIRECTORY_SEPARATOR
. 'var' . DIRECTORY_SEPARATOR
. 'logs' . DIRECTORY_SEPARATOR
. $this->getContext();
}
We do this for all our symfony projects, and it's more or less standard practice.
Unfortunately, this breaks the console cache:clear
command:
./bin/console cache:clear --env=dev
(...)
// Clearing the admin cache for the dev environment with debug true
PHP Warning: Uncaught Symfony\Component\Debug\Exception\ContextErrorException: Warning: require(/dev/shm/website/cache/dev/ContainerTd6tmmi/removed-ids.php): failed to open stream: No such file or directory in /dev/shm/website/cache/dev/ContainerTd6tmmi/adminDevDebugProjectContainer.php:1930
Stack trace:
#0 /dev/shm/website/cache/dev/ContainerTd6tmmi/adminDevDebugProjectContainer.php(1930): require()
#1 /vagrant/website/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php(184): ContainerTd6tmmi\adminDevDebugProjectContainer->getRemovedIds()
#2 /vagrant/website/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(667): Symfony\Component\DependencyInjection\Container->set('kernel', Object(AdminKernel))
#3 /vagrant/website/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(137): Symfony\Component\HttpKernel\Kernel->initializeContainer()
#4 /vagrant/website/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(154): Symfony\Compone in /dev/shm/website/cache/dev/ContainerTd6tmmi/adminDevDebugProjectContainer.php on line 1930
PHP Fatal error: ContainerTd6tmmi\adminDevDebugProjectContainer::getRemovedIds(): Failed opening required '/dev/shm/website/cache/dev/ContainerTd6tmmi/removed-ids.php' (include_path='.:/usr/share/php') in /dev/shm/website/cache/dev/ContainerTd6tmmi/adminDevDebugProjectContainer.php on line 1930
10:36:33 CRITICAL [php] Fatal Compile Error: ContainerTd6tmmi\adminDevDebugProjectContainer::getRemovedIds(): Failed opening required '/dev/shm/website/cache/dev/ContainerTd6tmmi/removed-ids.php' (include_path='.:/usr/share/php') ["exception" => Symfony\Component\Debug\Exception\FatalErrorException { …}] []
In adminDevDebugProjectContainer.php line 1930:
Compile Error: ContainerTd6tmmi\adminDevDebugProjectContainer::getRemovedIds(): Failed opening required '/dev/shm/website/cache/dev/ContainerTd6tmmi/removed-ids.php' (include_path='.:/usr/shar
e/php')
cache:clear [--no-warmup] [--no-optional-warmers] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>
This looks like a Symfony-internal issue, but I don't get this with any other Symfony installations, so I believe it is related to / caused by Sulu.
Interestingly, the issue only appears with the admin console - ./bin/websiteconsole cache:clear --env=dev
seems to work fine (at least for now).
Just for the sake of it, I tried reverting the directory paths back to their original location, but then I run into this issue.
So - any hints on how to run Sulu on a vagrant box? 😃