php fpm redirect errors

Discussion in 'ISPConfig 3 Priority Support' started by arraken, Mar 5, 2014.

  1. arraken

    arraken Member

    Hi!

    I have a problem with using php-fpm with websites that are installed in a subfolder.

    When I install for example a standard Drupal website in the folder "../web/main/", and set the redirect type to L, and the redirect path to /main/, it works fine with the php-module FAST-CGI. But as soon as i use PHP-FPM, I get an "Internal Server Error". The error log shows the classic redirect-error:

    Code:
    [Wed Mar 05 08:25:11 2014] [error] [client 1.2.3.4] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
    This happens with both the default php 5.3, and the additional php 5.5.7 version.

    My vhost looks like this with PHP-FPM enabled:

    Code:
    <Directory /var/www/example.tld>
                    AllowOverride None
                    Order Deny,Allow
                    Deny from all
    </Directory>
    
    <VirtualHost *:80>
                                            DocumentRoot /var/www/clients/client1/web16/web
    
                    ServerName example.tld
                    ServerAlias www.example.tld
                    ServerAdmin [email protected]
    
                    ErrorLog /var/log/ispconfig/httpd/example.tld/error.log
    
                    Alias /error/ "/var/www/example.tld/web/error/"
                    ErrorDocument 400 /error/400.html
                    ErrorDocument 401 /error/401.html
                    ErrorDocument 403 /error/403.html
                    ErrorDocument 404 /error/404.html
                    ErrorDocument 405 /error/405.html
                    ErrorDocument 500 /error/500.html
                    ErrorDocument 502 /error/502.html
                    ErrorDocument 503 /error/503.html
    
                    <IfModule mod_ssl.c>
                    </IfModule>
    
                    <Directory /var/www/example.tld/web>
                                    Options FollowSymLinks
                                    AllowOverride All
                                    Order allow,deny
                                    Allow from all
                    </Directory>
                    <Directory /var/www/clients/client1/web16/web>
                                    Options FollowSymLinks
                                    AllowOverride All
                                    Order allow,deny
                                    Allow from all
                    </Directory>
    
    
    
    
                    # suexec enabled
                    <IfModule mod_suexec.c>
                            SuexecUserGroup web16 client1
                    </IfModule>
                    # Clear PHP settings of this website
                    <FilesMatch "\.ph(p3?|tml)$">
                                    SetHandler None
                    </FilesMatch>
                    <IfModule mod_fastcgi.c>
                                    <Directory /var/www/clients/client1/web16/cgi-bin>
                                                    Order allow,deny
                                                    Allow from all
                                </Directory>
                    AddHandler php5-fcgi .php
                    Action php5-fcgi /php5-fcgi
                                    Alias /php5-fcgi /var/www/clients/client1/web16/cgi-bin/php5-fcgi-*-80-example.tld
                    FastCgiExternalServer /var/www/clients/client1/web16/cgi-bin/php5-fcgi-*-80-example.tld -idle-timeout 300 -host 127.0.0.1:9025 -pass-header Authorization
                    </IfModule>
    
                    RewriteEngine on
                    RewriteCond %{HTTP_HOST}   ^example\.tld$ [NC]
                    RewriteCond %{REQUEST_URI} !^/webdav/
                    RewriteCond %{REQUEST_URI} !^/main/
                    RewriteRule   ^/(.*)$ /main/$1  [L]
                    RewriteCond %{HTTP_HOST}   ^www\.example\.tld$ [NC]
                    RewriteCond %{REQUEST_URI} !^/webdav/
                    RewriteCond %{REQUEST_URI} !^/main/
                    RewriteRule   ^/(.*)$ /main/$1  [L]
    
                    # add support for apache mpm_itk
                    <IfModule mpm_itk_module>
                            AssignUserId web16 client1
                    </IfModule>
    
                    <IfModule mod_dav_fs.c>
                    # Do not execute PHP files in webdav directory
                            <Directory /var/www/clients/client1/web16/webdav>
                                    <ifModule mod_security2.c>
                                            SecRuleRemoveById 960015
                                            SecRuleRemoveById 960032
                                    </ifModule>
                                    <FilesMatch "\.ph(p3?|tml)$">
                                            SetHandler None
                                    </FilesMatch>
                            </Directory>
                            DavLockDB /var/www/clients/client1/web16/tmp/DavLock
                            # DO NOT REMOVE THE COMMENTS!
                            # IF YOU REMOVE THEM, WEBDAV WILL NOT WORK ANYMORE!
          # WEBDAV BEGIN
                            # WEBDAV END
                    </IfModule>
    
    
    </VirtualHost>
    
    and like this with fast-cgi enabled:

    Code:
    <Directory /var/www/example.tld>
                    AllowOverride None
                    Order Deny,Allow
                    Deny from all
    </Directory>
    
    <VirtualHost *:80>
                                            DocumentRoot /var/www/example.tld/web
    
                    ServerName example.tld
                    ServerAlias www.example.tld
                    ServerAdmin [email protected]
    
                    ErrorLog /var/log/ispconfig/httpd/example.tld/error.log
    
                    Alias /error/ "/var/www/example.tld/web/error/"
                    ErrorDocument 400 /error/400.html
                    ErrorDocument 401 /error/401.html
                    ErrorDocument 403 /error/403.html
                    ErrorDocument 404 /error/404.html
                    ErrorDocument 405 /error/405.html
                    ErrorDocument 500 /error/500.html
                    ErrorDocument 502 /error/502.html
                    ErrorDocument 503 /error/503.html
    
                    <IfModule mod_ssl.c>
                    </IfModule>
    
                    <Directory /var/www/example.tld/web>
                                    Options FollowSymLinks
                                    AllowOverride All
                                    Order allow,deny
                                    Allow from all
                    </Directory>
                    <Directory /var/www/clients/client1/web16/web>
                                    Options FollowSymLinks
                                    AllowOverride All
                                    Order allow,deny
                                    Allow from all
                    </Directory>
    
    
    
    
                    # suexec enabled
                    <IfModule mod_suexec.c>
                            SuexecUserGroup web16 client1
                    </IfModule>
                    # Clear PHP settings of this website
                    <FilesMatch "\.ph(p3?|tml)$">
                                    SetHandler None
                    </FilesMatch>
                    # php as fast-cgi enabled
            # For config options see: http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html
                    <IfModule mod_fcgid.c>
                                    IdleTimeout 300
                                    ProcessLifeTime 3600
                                    # MaxProcessCount 1000
                                    DefaultMinClassProcessCount 0
                                    DefaultMaxClassProcessCount 100
                                    IPCConnectTimeout 3
                                    IPCCommTimeout 360
                                    BusyTimeout 300
                    </IfModule>
                    <Directory /var/www/example.tld/web>
                                    AddHandler fcgid-script .php .php3 .php4 .php5
                                    FCGIWrapper /var/www/php-fcgi-scripts/web16/.php-fcgi-starter .php
                                    Options +ExecCGI
                                    AllowOverride All
                                    Order allow,deny
                                    Allow from all
                    </Directory>
                    <Directory /var/www/clients/client1/web16/web>
                                    AddHandler fcgid-script .php .php3 .php4 .php5
                                    FCGIWrapper /var/www/php-fcgi-scripts/web16/.php-fcgi-starter .php
                                    Options +ExecCGI
                                    AllowOverride All
                                    Order allow,deny
                                    Allow from all
                    </Directory>
    
                    RewriteEngine on
                    RewriteCond %{HTTP_HOST}   ^example\.tldt$ [NC]
                    RewriteCond %{REQUEST_URI} !^/webdav/
                    RewriteCond %{REQUEST_URI} !^/main/
                    RewriteRule   ^/(.*)$ /main/$1  [L]
                    RewriteCond %{HTTP_HOST}   ^www\.example\.tldt$ [NC]
                    RewriteCond %{REQUEST_URI} !^/webdav/
                    RewriteCond %{REQUEST_URI} !^/main/
                    RewriteRule   ^/(.*)$ /main/$1  [L]
    
                    # add support for apache mpm_itk
                    <IfModule mpm_itk_module>
                            AssignUserId web16 client1
                    </IfModule>
    
                    <IfModule mod_dav_fs.c>
                    # Do not execute PHP files in webdav directory
                            <Directory /var/www/clients/client1/web16/webdav>
                                    <ifModule mod_security2.c>
                                            SecRuleRemoveById 960015
                                            SecRuleRemoveById 960032
                                    </ifModule>
                                    <FilesMatch "\.ph(p3?|tml)$">
                                            SetHandler None
                                    </FilesMatch>
                            </Directory>
                            DavLockDB /var/www/clients/client1/web16/tmp/DavLock
                            # DO NOT REMOVE THE COMMENTS!
                            # IF YOU REMOVE THEM, WEBDAV WILL NOT WORK ANYMORE!
          # WEBDAV BEGIN
                            # WEBDAV END
                    </IfModule>
    
    
    </VirtualHost>
    
    If I don't put the website in a subfolder, both php-versions work. The rewrite problem only occurs with php-fpm and the site in a subfolder.
     
    Last edited: Mar 5, 2014
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    The vhosts you posted had both fastcgi enabled, not php-fpm. You can see that e.g. in the comment line:

    # php as fast-cgi enabled

    In general, I wont put a site in a subfolder. as son as this site starts to use a .htaccess file, e.g. for search egine friendly URL's, you will get rewrite problems as the apache redrect to the main folder interferes with the redirect rules in the .htaccess file.
     
  3. arraken

    arraken Member

    Hi Till,

    Sorry, I posted the wrong vhost file for the php-fpm version. I have updated my post now. Can you take a look at it?

    Some of my customers want to use subfolders, and as far as I tested, the rewrites also work with clean-urls and .htaccess files, at least with Drupal. However, it only works with fast-cgi and not php-fpm, which I would rather use.
     
  4. arraken

    arraken Member

    Some additional Information:
    If I set apache log-level to debug, I get the following results in the error.log:

    Code:
    [Wed Mar 05 13:09:58 2014] [debug] core.c(3112): [client 1.2.3.4] r->uri = /main/index.php
    [Wed Mar 05 13:09:58 2014] [debug] core.c(3118): [client 1.2.3.4] redirected from r->uri = /php5-fcgi/main/index.php
    [Wed Mar 05 13:09:58 2014] [debug] core.c(3118): [client 1.2.3.4] redirected from r->uri = /main/index.php
    [Wed Mar 05 13:09:58 2014] [debug] core.c(3118): [client 1.2.3.4] redirected from r->uri = /php5-fcgi/main/index.php
    [Wed Mar 05 13:09:58 2014] [debug] core.c(3118): [client 1.2.3.4] redirected from r->uri = /main/index.php
    [Wed Mar 05 13:09:58 2014] [debug] core.c(3118): [client 1.2.3.4] redirected from r->uri = /php5-fcgi/main/index.php
    [Wed Mar 05 13:09:58 2014] [debug] core.c(3118): [client 1.2.3.4] redirected from r->uri = /main/index.php
    [Wed Mar 05 13:09:58 2014] [debug] core.c(3118): [client 1.2.3.4] redirected from r->uri = /php5-fcgi/main/index.php
    [Wed Mar 05 13:09:58 2014] [debug] core.c(3118): [client 1.2.3.4] redirected from r->uri = /main/index.php
    [Wed Mar 05 13:09:58 2014] [debug] core.c(3118): [client 1.2.3.4] redirected from r->uri = /php5-fcgi/index.php
    [Wed Mar 05 13:09:58 2014] [debug] core.c(3118): [client 1.2.3.4] redirected from r->uri = /index.php
    [Wed Mar 05 13:09:58 2014] [debug] mod_deflate.c(615): [client 1.2.3.4] Zlib: Compressed 779 to 435 : URL /main/index.php
    
     
  5. till

    till Super Moderator Staff Member ISPConfig Developer

    Try to edit the vhost file, after you enabled php-fpm and change the lines:

    Code:
    RewriteEngine on
                    RewriteCond %{HTTP_HOST}   ^example\.tld$ [NC]
                    RewriteCond %{REQUEST_URI} !^/webdav/
                    RewriteCond %{REQUEST_URI} !^/main/
                    RewriteRule   ^/(.*)$ /main/$1  [L]
                    RewriteCond %{HTTP_HOST}   ^www\.example\.tld$ [NC]
                    RewriteCond %{REQUEST_URI} !^/webdav/
                    RewriteCond %{REQUEST_URI} !^/main/
                    RewriteRule   ^/(.*)$ /main/$1  [L]
    to:

    Code:
    RewriteEngine on
                    RewriteCond %{HTTP_HOST}   ^example\.tld$ [NC]
                    RewriteCond %{REQUEST_URI} !^/webdav/
                    RewriteCond %{REQUEST_URI} !^/main/
                    RewriteCond %{REQUEST_URI} !^/php5-fcgi/
                    RewriteRule   ^/(.*)$ /main/$1  [L]
                    RewriteCond %{HTTP_HOST}   ^www\.example\.tld$ [NC]
                    RewriteCond %{REQUEST_URI} !^/webdav/
                    RewriteCond %{REQUEST_URI} !^/main/
                    RewriteCond %{REQUEST_URI} !^/php5-fcgi/
                    RewriteRule   ^/(.*)$ /main/$1  [L]
    and restart apache.
     
  6. arraken

    arraken Member

    Ok, it seems I solved this:

    In the vhost file, I had to apply the following redirect rule "RewriteCond %{REQUEST_URI} !^/php5-fcgi/". This was discussed in connection with subdomains here:

    http://bugtracker.ispconfig.org/index.php?do=details&task_id=2932

    Apparently the same problem arises with php-fpm and subfolders. The working rewrite block in my vhost file looks like this now:

    Code:
    RewriteEngine on
                    RewriteCond %{HTTP_HOST}   ^example\.tld$ [NC]
                    RewriteCond %{REQUEST_URI} !^/webdav/
                    RewriteCond %{REQUEST_URI} !^/main/
                    [B]RewriteCond %{REQUEST_URI} !^/php5-fcgi/[/B]
                    RewriteRule   ^/(.*)$ /main/$1  [L]
                    RewriteCond %{HTTP_HOST}   ^www\.example\.tld$ [NC]
                    RewriteCond %{REQUEST_URI} !^/webdav/
                    RewriteCond %{REQUEST_URI} !^/main/
                    [B]RewriteCond %{REQUEST_URI} !^/php5-fcgi/[/B]
                    RewriteRule   ^/(.*)$ /main/$1  [L]
    The problem with this solution is, that ispconfig of course overwrites the changes i made in the vhost file manually. How can this be solved?
     
  7. arraken

    arraken Member

    Haha, sorry, I didn't see you already replied to my post with the same solution I found! :)

    So the only question remaining is: how can I make the changes in the vhost file permanent, so they don't get overwritten by ispconfig?
     
  8. till

    till Super Moderator Staff Member ISPConfig Developer

    You could e.g. remove the redirect on the redirect tab of the website in ispconfig and then insert the redirect rule block in the apache directives field of the website instead.
     

Share This Page