Reputation: 1112
I'm having a really really weird bug.
I have two vhosts on one machine: staging and production.
They are located in /var/www/staging/ and /var/www/production/. I deploy my Symfony2 project via Capifony (a symfony2 extension of capistrano), so the web dir is in /var/www/staging/current/web/
When I echo __DIR__
in my controller I get
/var/www/production/releases/20130424075147/src/Acme/DemoBundle/Controller
Which is correct. However, if I now get an entity from it's repository (for example)
$object = $this->getDoctrine()->getManager()->getRepository('AcmeDemoBundle:Object')->findOneById(1);
And do echo $object->getUploadRootDir()
(from the cookbook), which uses __DIR__
I suddenly get
/var/www/staging/releases/20130424075333/src/Acme/DemoBundle/Entity/../../../../web/upload/
Somehow, when loading the Object, it switched to the staging environment, instead of production (the two different release folders are just because there's different releases between production and staging).
Is this due to autoloading? A config error in the vhosts?
Below is are my two vhosts
<VirtualHost *:80>
DocumentRoot "/var/www/production/current/web"
ServerName example.com
ServerAlias www.example.com example.com
SetEnv SYMFONY_ENV prod
SetEnv SYMFONY_DEBUG 0
<Directory /var/www/production/current/web>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/staging/current/web"
ServerName staging.example.com
ServerAlias staging.example.com
SetEnv SYMFONY_ENV dev
SetEnv SYMFONY_DEBUG 1
<Directory /var/www/staging/current/web>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</Directory>
</VirtualHost>
Upvotes: 2
Views: 181
Reputation: 1112
The problem was APC.
In app.php I had
$loader = new ApcClassLoader('sf', $loader);
which caused overlapping problems in the apc opcode entries (dixit our sysadmin).
The fix was simple:
$loader = new ApcClassLoader($_SERVER['HTTP_HOST'], $loader);
Upvotes: 1