Multiple php/symfony2 applications on apache 2.4.7 virtual host - php

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.

It was the problem with xcache (http://xcache.lighttpd.net/ticket/337)
Setting opcache.optimization_level=0 solved this problem for me.

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.

Related

localhost 403 Forbidden PHP

Read almost all questions here, but no solution found. This drives me crazy already to do such simple stuff to run PHP on my localhost...
You don't have permission to access this resource.Server unable to
read htaccess file, denying access to be safe
ls -l
-rwxrwxrwx 1 user user 51 sep 27 14:42 .htaccess
ls -l
drwxrwxr-x 2 user user 4096 sep 27 15:17 www
Any help appreciated!
Check if there is an .htaccess file inside the www folder (and its permissions), since Apache looks for one at every directory up to the one where the requested file exists.
I'm coming from an Apache on Windows server background, but in regards to the .htaccess file, you can also put a "AllowOverride None" in your section of your httpd.conf file. At least in Windows, this means nothing can be overridden, therefore no need to look for .htaccess files.
You can also add a line to tell Apache that the "AccessFileName" is blank. Here are the entried I'm speaking of from my config file. I'm running a XAMPP server on Windows.
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride None
Require all granted
</Directory>
AccessFileName ""

mautic throws error php error during installation on aws ubuntu

mautic throws amazing error during installation :
The site is currently offline due to encountering an error. If the problem persists, please contact the system administrator.
so i went into server log which shows :
PHP Warning: include(): Failed opening '/var/www/myfolder/var/cache/prod/middlewares.cache.php' for inclusion (include_path='.:/usr/share/php') in /var/www/myfolder/app/middlewares/MiddlewareBuilder.php on line 82PHP message: PHP Warning - Invalid argument supplied for foreach() - in file /var/www/mauticwp/app/middlewares/MiddlewareBuilder.php - at line 84PHP message: PHP Warning: Invalid argument supplied for foreach() in /var/www/mauticwp/app/middlewares/MiddlewareBuilder.php on line 84PHP message: RuntimeException: Unable to create the "cache" directory (/var/www/myfolder/var/cache/prod). - in file /var/www/myfolder/vendor/symfony/http-kernel/Kernel.php - at line 765'
#NameVirtualHost *:8000
<VirtualHost *:8000>
ServerAdmin webmaster#localhost
ServerName somesubdomain.mydomains.com
ServerAlias www.somesubdomain.mydomains.com
DocumentRoot /var/www/some_directory
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mpm_itk_module>
AssignUserId mauticadmin www-data
</IfModule>
<IfModule mod_fastcgi.c>
AddHandler php7.4-fcgi .php
Action php7.4-fcgi /php7.4-fcgi virtual
Alias /php7.4-fcgi /usr/lib/cgi-bin/php7.4-fcgi-somesubdomain.mydomains.com
FastCgiExternalServer /usr/lib/cgi-bin/php7.4-fcgi-test.com -socket /var/run/php/php7.4-fpm-mautic.ndedges.com.sock -pass-header Authorization
</IfModule>
<Directory /var/www/some_directory>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
<FilesMatch .php$>
# 2.4.10+ can proxy to unix socket
SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost"
</FilesMatch>
</VirtualHost>
within fpm/pool.d/www.mautic.conf. i added
php_admin_value[disable_functions] = exec,passthru,shell_exec,system
php_admin_flag[allow_url_fopen] = off
as I have multiple PHP in the same server. I have Cloudflare configured within WordPress and redirects to HTTPS. but i am unable to use ip and port to use it.
I am completely clueless about what could be the reason.
thx
Most of the time it is Cache and Permission related Issue, In my opinion It has nothing to do with Apache configuration.
Use ps aux to identify which user owns the apache process,
Mostly it is www-data,
Make sure to chown on all directories and sub directories to change ownership to www-data.
Make sure files and directories have proper permissions for www-data, Mautic needs write access to Media, var/cache and var/logs directories.
https://tutorialsjoint.com/install-mautic/ in this tutorial checkout the section "Setting rights and permissions for Mautic Installation".
It'll work the same weather it is nginx or apache as this problem seems to be linux related only.
i also find some error
[mpm_prefork:notice] [pid 1440453] AH00163: Apache/2.4.41 (Ubuntu) mod_fcgid/2.3.9 mpm-itk/2.4.7-04 OpenSSL/1.1.1f configured -- resuming normal operations
<FilesMatch ".php$"> # Apache 2.4.10+ can proxy to unix socket
SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/"
this one did the job. i removed that fpm configuration but it works like a charm. actually, the same settings did not work for him but it worked for me.
ref: https://askubuntu.com/questions/1317077/apache-sethandler-not-working-with-multiple-php-version
maybe due to the apache2 version. but it has a different problem now i can access it through elastic ip and non SSL port but not with the A record.
now mautic is set with SES but i need to set a bounce endpoint with sns topic. and set a cronjob as www-data.
I was able to access with the IP not using the SSL of Cloudflare proxied A record because it doesn't support other than these ports to trust support.cloudflare.com/hc/en-us/articles/… Cloudflare only accept these ports nothing else. After changing those it was immediately turned into grey and secured. –
https://community.cloudflare.com/t/subdomains-are-not-getting-redirected-to-themselves/279745

Updated php now having issues with phpmyadmin

We have an amazon linux server. It was running php 5.3 we wanted to update to 5.6 to see if it would solve an issue with a plugin on our wordpress installation. I installed php 5.6 and am now having issues getting back into phpMyAdmin and our wordpress site which I think isn't loading because of the database problem.
When I go to /phpMyAdmin I get Forbidden
You don't have permission to access /phpMyAdmin on this server.
I've found a few threads on here suggesting things such as placing the following in my phpMyAdmin.conf file:
<Directory /usr/share/phpMyAdmin/>
AddDefaultCharset UTF-8
<IfModule mod_authz_core.c>
# Apache 2.4
<RequireAny>
#Require ip 127.0.0.1
#Require ip ::1
Require all granted
</RequireAny>
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>
I have tried this, also I added Allow from 'my static ip'. I have also restarted httpd still nothing. The other thing that is happening is I'm getting the Amazon Linux AMI Test Page when I go to what should be our wordpress website, I'm not sure if these are the same problem but I assume it is related.
The website in question is calendar.childmags.com.au
I think you have to off the strict mode. For the temporary solution you can use
For all DB:_
SET ##global.sql_mode=''
For current DB:-
SET sql_mode = ''

Symfony 1.4 empty decoratorDirectory setting not being populated

I'm working on a legacy symfony 1.4 project, I setup my local dev environment at my office linux machine Fedora 16 and everything went well. I had to recreate the environment for a macbook machine with Mac OS X Lion.
In the second I get a ton of errors like this
[Mon Mar 04 16:51:58 2013] [error] [client ::1] PHP Fatal error: Uncaught exception 'sfRenderException' with message 'The decorator template "layout.php" does not exist or is unreadable in "".' in /Users/foo/bar/baz/myApp/v2/cache/something/something/config/config_core_compile.yml.php:3875\nStack trace:\n#0 /Users/foo/bar/baz/myApp/cache/something/something/config/config_core_compile.yml.php(3909)
So in that config_core_compile.yml.php file the exception is being thrown in this code
if (!is_readable($this->getDecoratorDirectory().'/'.$this->getDecoratorTemplate()))
{
throw new sfRenderException(sprintf('The decorator template "%s" does not exist or is unreadable in "%s".', $this->decoratorTemplate, $this->decoratorDirectory));
}
Tracking the getDecoratorDirectory method call I got to sfView.class.php around line 175
public function getDecoratorDirectory()
{
return $this->decoratorDirectory;
}
In that same file is where the decoratorDirectory property gets 'calculated/populated'But is being blank, do you any clue of what might be wrong? a symfony setting, an apache config? Anything?
P.S just in case this is my apache vhost
<VirtualHost *:80>
ServerName local.myapp
DocumentRoot /Users/foo/bar/baz/myApp/v2/web
ErrorLog "/private/var/log/apache2/local.myapp-error_log"
CustomLog "/private/var/log/apache2/local.myapp-access_log" combined
<Directory "/Users/foo/bar/baz/myApp/v2/web">
Options FollowSymLinks
AllowOverride All
Allow from All
</Directory>
Alias /sf /Users/foo/bar/baz/myApp/v2/web/lib/vendor/symfony/data/web/sf
<Directory "/Users/foo/bar/baz/myApp/v2/web/lib/vendor/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
EDIT:
Also I have to use perforce the company repos, an older teammate keeps saying he thinks is about encoding, it doesn't make sense to me, but still.
I'm not sure, but some times when I have moved one symfony application to a different server or to a different folder I have had to remove all the cache folder, because symfony use absolute paths sometimes.
Well, try to remove all content on the cache folder. Probably you will need to fix permissions on this folder, because symfony needs to create directories on this folder. (Probably).
Sorry, I dont speak english enought to explain well.

Can't view index.php of Zend Framework 1.0 after setting up Apache/Host requirements?

UPDATE: the following error is coming up in the Apache error logs...
[Sat Dec 08 16:41:39 2012] [error] [client 127.0.0.1]
PHP Fatal error: require_once():
Failed opening required 'Zend/Application.php'
(include_path='/Library/WebServer/Documents/quickstart/library:.:/php/includes:/Users/markmcdonnell/Dropbox/Library/PHP/ZendFramework-1.12.0/library')
in /Library/WebServer/Documents/quickstart/public/index.php on line 18
I'm using Mac OSX 10.8.2 (Mountain Lion) and I'm having problems getting the Zend framework set-up and running (just the basic QuickStart).
I'm using Apache 2.2.22
My localhost files are accessible from /Library/WebServer/Documents
I have PHP 5.3.15 running as well.
I've created a new project via the command line (using the zf.sh file) called 'quickstart' (as per the section on the Zend website recommends) and that is stored here: /Library/WebServer/Documents/quickstart
I've followed both the official Zend website instructions and also an online book about installing Zend: http://www.survivethedeepend.com/zendframeworkbook/en/1.0/creating.a.local.domain.using.apache.virtual.hosts
My php.ini (/private/etc/php.ini) file has been updated to include the path to the library folder inside the ZendFramework directory...
include_path = ".:/php/includes:/Users/<home>/Dropbox/Library/PHP/ZendFramework-1.12.0/library"
I've updated /etc/apache2/httpd.conf so it includes...
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
# Ensure "localhost" is preserved unchanged pointed
# to the default document root for our system.
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Library/WebServer/Documents
</VirtualHost>
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerName quickstart.local
DocumentRoot /Library/WebServer/Documents/quickstart/public
SetEnv APPLICATION_ENV "development"
<Directory /Library/WebServer/Documents/quickstart/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
...I've also updated /etc/hosts so it includes...
127.0.0.1 localhost
127.0.0.1 quickstart.local
I'm restarting Apache using sudo apachectl graceful (I've also used sudo apachectl restart)
So if I try and now access http://localhost/ I see my /Library/WebServer/Documents directory and I can see PHP is running still with no problems. But if I try and access http://quickstart.local/ I just get an empty page?
Can any one advise as to what the problem might be, what I'm missing and what I can do to get the initial 'welcome' page to display.
I'm sure I'm just missing someone small, but it's obviously causing problem enough for the basic page not to show.
Thanks.
Mark
Just for others who may have followed this. The answer by Kamil, above, will work, but opens a security hole outside Apache's security configuration. That's fine as long as you know it and have another layer of security above Apache.
Another way to resolve the problem is to put the ZendFramework somewhere inside the root directory's hierarchy. Like:
DocumentRoot/Library/WebServer/Documents/ZendFramework-1.12.0/library
or
DocumentRoot/Library/WebServer/Documents/quickstart/public/ZendFramework-1.12.0/library
Any path that's inside the root directory of your Apache server.
Maybe a user permissions issue between the Zend files and the Apache process.
Since you can create the project using zf.sh, the Zend files are obviously there. But the fail you get via Apache suggests that the Zend files might not be accessible via the Apache process (that is, the user under which the Apache process runs).
$ chmod 0777 /Users/markmcdonnell/Dropbox/Library/PHP/ZendFramework-1.12.0/library
to test.
You could probably get away with much less expansive permissions - 0644, for example - but I confess I'm terrible at that aspect of it. ;-)

Categories