简体   繁体   中英

Multiple php/symfony2 applications on apache 2.4.7 virtual host

I'm forcing a really strange issue since I was forced to move a few of my symfony2 applications to a new server with Ubuntu 14.04 and Apache2 2.4.7.

There are 4 different symfony2 applications at the same server, configured with virtual hosts. Each has its own domain, account in the system, and configuration.

The strange thing that happens is, that once i restart the apache2 server (or reload the configuration) only one of those 4 sites would work, and that would be the first one typed in the browser. All other pages generate this kind of errors:

[Tue Sep 09 10:30:27.437009 2014] [:error] [pid 16400] [client XXX.XXX.XXX.XXX:44531] PHP Fatal error:  Class 'Avalanche\\Bundle\\ImagineBundle\\AvalancheImagineBundle' not found in /home/user1/project/app/AppKernel.php on line 27

or

[Tue Sep 09 10:41:47.794413 2014] [:error] [pid 16398] [client XXX.XXX.XXX.XXX:44947] PHP Fatal error:  Class 'Project2\\CoreBundle\\Project2Bundle' not found in /home/user2/project2/app/AppKernel.php on line 19

The very strange thing is that it happens only to all the sites that haven't been visited as the first one after apache2 restart/reload.

All the sites have a proper, as I suppose, virtual host configuration:

<VirtualHost *:80>
    ServerAdmin me@server.com
    ServerName project1.nl 
    ServerAlias www.project1.nl
    DocumentRoot "/home/user1/project1/web"
    DirectoryIndex app.php
    <Directory "/home/user1/project1/web">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/project1-error.log
    CustomLog ${APACHE_LOG_DIR}/project1-access.log combined
</VirtualHost>

Does anyone have an idea where to start looking? I've checked multiple configurations of virtual hosts, php-fpm configuration, configuration of every single application, but I couldn't find a way out.

这是xcache的问题( http://xcache.lighttpd.net/ticket/337 )设置opcache.optimization_level = 0为我解决了这个问题。

Here is one of our vhost setup which works for sf2

ServerName demo.example.fr
ServerAlias demo.example.fr
ServerAdmin admin@example.fr

DocumentRoot /var/www/vhosts/demo.example.fr/httpdocs/web/
<Directory /var/www/vhosts/demo.example.fr/httpdocs/web/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ /app.php [QSA,L]
    </IfModule>
</Directory>

like you will notice , we don t setup directory index , only a url rewriting with mod_rewrite

There are some things in your configuration.

In Apache 2.4 you have to define the options with + or - .

Options -Indexes +FollowSymLinks +MultiViews

You don't need the DirectoryIndex because its rewritten in your .htaccess file.

I hope you have enabled all your configurations with a2ensite otherwise all other vhost files are not loaded.

The next thing is to clear the complete Symfony2 cache folder and clear your APC cache if you use it. Sometimes APC cache some objects and you have some strange errors.

I have spent two days trying to figure out this exact same problem after upgrading to Ubuntu 14.04 and Apache 2.4.7.

What solved it for me was disabling xcache because it was caching the files of the first application called after a php app/console cache:clear or php composer.phar update which resulted in sometimes getting the application A and sometimes application B.

I figured that out once I tried to debug symfony2 by adding var_dump instructions at various steps in application A. When I got inside $kernel->handle() (called from app.php), I could not get any output regardless of what I tried. I suspected that AppKernel of application B was called but when I tried to modify that one, it did not change the result. This is when I realised that the file was cached somewhere. I hadn't paid any attention to that because I did not install apc but apparently xcache was enabled.

I suppose this issue arises because the namespace and the class names are exactly the same in both symfony2 applications...

I will try to see if it's possible to add a prefix per application for xcache to know that they are different.

TLDR: Disable xcache because with apache2's original configuration, it cannot discriminate between both applications and mixes up the cache.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM