mod_rewrite under PHP 5.4 as php-fpm

Jan_E

Verified User
Joined
Apr 29, 2011
Messages
130
Location
Amsterdam, NL, EU
I just had a hard time getting drupal 7 to work under PHP 5.4 as php-fpm. My options.conf:
Code:
php1_release=5.3
php2_release=5.4
php1_mode=mod_php
php2_mode=php-fpm
...
apache_ver=2.4
mod_ruid2=yes
secure_htaccess=no
harden-symlinks-patch=no
Drupal 7 normally rewrites every URL in the .htaccess with something like:
Code:
  # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteCond %{REQUEST_URI} !=/phpinfo.php
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
After a lot of debugging I found out that inside mod_rewrite with PHP 5.4 as php-fpm the %{REQUEST_FILENAME} and %{REQUEST_URI} are different. When requesting /index.php these variables have the following values inside mod_rewrite:

# http://vps2.arsetlabor.co.uk/index.php
# %{REQUEST_FILENAME} = /home/arsetlabor/public_html/index.php54
# %{REQUEST_URI} = /fastcgiphp54arsetlabor/index.php

Arsetlabor is the user.

So now my working drupal 7 .htacces starts with:
Code:
<IfModule mod_fastcgi.c>
        <FilesMatch "\.(inc|php|php3|php4|php44|php5|php52|php53|php54|phtml|phps)$">
                SetHandler php54-fcgi
        </FilesMatch>
</IfModule>
and ends with
Code:
<IfModule mod_rewrite.c>
  RewriteEngine on

  # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
  # php-fpm
  # http://vps2.arsetlabor.co.uk/index.php
  # %{REQUEST_FILENAME} = /home/arsetlabor/public_html/index.php54
  # %{REQUEST_URI} = /fastcgiphp54arsetlabor/index.php
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteCond %{REQUEST_URI} !=/phpinfo.php
  RewriteCond %{REQUEST_URI} !=/fastcgiphp54arsetlabor/phpinfo.php
  RewriteCond %{REQUEST_URI} !=/fastcgiphp54arsetlabor/index.php
# uncomment to debug with Opera's (not) Enable Automatic Redirection
# RewriteRule ^(.*)$ /index.php?q=$1&rf=%{REQUEST_FILENAME}&ru=%{REQUEST_URI} [R=301,L]
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

</IfModule>
The different values for REQUEST_FILENAME and REQUEST_URI inside mod_rewrite will probably fail in a lot more frameworks than just Drupal 7. Is there a generic solution to make mod_rewrite in php-fpm work just like mod_rewrite in mod_php?

I am now going to try PHP 5.4 as suphp to see if that makes it easier.
 

Jan_E

Verified User
Joined
Apr 29, 2011
Messages
130
Location
Amsterdam, NL, EU
Hmmm. PHP 5.3 as mod_php and PHP 5.4 as suphp fails competely, even after a build all d and build rewrite_confs:
Code:
Starting httpd: httpd: Syntax error on line 37 of /etc/httpd/conf/httpd.conf: Syntax error on line 1 of /etc/httpd/conf/extra/httpd-phpmodules.conf: Cannot load /usr/lib/apache/mod_suphp.so into server: /usr/lib/apache/mod_suphp.so:
undefined symbol: ap_log_rerror
...
...
I had to rebuild suphp to get it working. Why did not ./build all d do that?

Anyway, suphp works without tweaking .htaccess/mod_rewrite. Just add this at the beginning of the .htaccess:
Code:
<IfModule mod_suphp.c>
        <FilesMatch "\.(inc|php|php3|php4|php44|php5|php52|php53|php54|phtml|phps)$">
                SetHandler x-httpd-php54
        </FilesMatch>
</IfModule>
And probably that can also be added to a custom httpd.conf.

Now there is still the mod_rewrite with php-fpm to be solved.
 
Last edited:

smtalk

Administrator
Staff member
Joined
Aug 22, 2006
Messages
9,362
Location
LT, EU
Hmmm. PHP 5.3 as mod_php and PHP 5.4 as suphp fails competely, even after a build all d and build rewrite_confs:
Code:
Starting httpd: httpd: Syntax error on line 37 of /etc/httpd/conf/httpd.conf: Syntax error on line 1 of /etc/httpd/conf/extra/httpd-phpmodules.conf: Cannot load /usr/lib/apache/mod_suphp.so into server: /usr/lib/apache/mod_suphp.so:
undefined symbol: ap_log_rerror
...
...
I had to rebuild suphp to get it working. Why did not ./build all d do that?

Anyway, suphp works without tweaking .htaccess/mod_rewrite. Just add this at the beginning of the .htaccess:
Code:
<IfModule mod_suphp.c>
        <FilesMatch "\.(inc|php|php3|php4|php44|php5|php52|php53|php54|phtml|phps)$">
                SetHandler x-httpd-php54
        </FilesMatch>
</IfModule>
And probably that can also be added to a custom httpd.conf.

Now there is still the mod_rewrite with php-fpm to be solved.
About suPHP - you had an old version already installed, so it did not rebuild it. However, I added a check for that in "./build all", so it would rebuild it in case it's not compatible with current version of apache. Thank you for the report. About php-fpm, you should add something like:
Code:
RewriteCond %{REQUEST_URI} !^/fastcgiphp54arsetlabor
 

Jan_E

Verified User
Joined
Apr 29, 2011
Messages
130
Location
Amsterdam, NL, EU
About suPHP - you had an old version already installed, so it did not rebuild it. However, I added a check for that in "./build all", so it would rebuild it in case it's not compatible with current version of apache. Thank you for the report.
CB 2.0 would not even let me ./build suphp until I put a # at the second line of options.conf. It quitted with some error message about php[n]_release or php[n]_mode. See the separate thread.

About php-fpm, you should add something like:
Code:
RewriteCond %{REQUEST_URI} !^/fastcgiphp54arsetlabor
You do not really want to change drupal's .htaccess. Too many chances of errors when installing updates and the like. And besides that I do not trust mod_rewrite anymore if it uses other values for REQUEST_FILENAME and REQUEST_URI. The REQUEST_URI inside mod_rewrite is not even the same as the one in PHP's environment.
 
Last edited:

mrtomcruise

Banned User
Joined
Apr 18, 2013
Messages
1
PHP 5.4 ships with a built-in webserver for development. This server allows you to run silex without any configuration. However, in order to serve static files, you'll have to make sure your front controller returns false in that case.........



__________
mrtomcruise
 

Aries86

Banned User
Joined
May 2, 2013
Messages
1
That's okay, there will be another one along in a while and that will save opening another thread.
 

Magician

Verified User
Joined
Jan 31, 2010
Messages
124
Location
EU / PL
About php-fpm, you should add something like:
Code:
RewriteCond %{REQUEST_URI} !^/fastcgiphp54arsetlabor
You do not really want to change drupal's .htaccess. Too many chances of errors when installing updates and the like. And besides that I do not trust mod_rewrite anymore if it uses other values for REQUEST_FILENAME and REQUEST_URI. The REQUEST_URI inside mod_rewrite is not even the same as the one in PHP's environment.
As Jan_E wrote - there is bad idea to modify default .htaccess for project. Is there any other way to work mod_rewrite standard way in php-fpm? Martynas, someone?
 

smtalk

Administrator
Staff member
Joined
Aug 22, 2006
Messages
9,362
Location
LT, EU
This problem is already solved, however, there is another one that apache developers haven't fixed yet. We will probably release our own patch for that or will not support PHP-FPM+Apache as stable.
 

Magician

Verified User
Joined
Jan 31, 2010
Messages
124
Location
EU / PL
This problem is already solved, however, there is another one that apache developers haven't fixed yet. We will probably release our own patch for that or will not support PHP-FPM+Apache as stable.
Martynas - thank you for response. I didn't try on new server php-fpm because have this topic problem recently. I assume if I switch to php-fpm on new install DA + CB 2.0 mod_rewrite should works ok?

When decision about support php-fpm by relase own patch will be made? And for now what consequences are when using php-fpm without patch?
 

smtalk

Administrator
Staff member
Joined
Aug 22, 2006
Messages
9,362
Location
LT, EU
Martynas - thank you for response. I didn't try on new server php-fpm because have this topic problem recently. I assume if I switch to php-fpm on new install DA + CB 2.0 mod_rewrite should works ok?

When decision about support php-fpm by relase own patch will be made? And for now what consequences are when using php-fpm without patch?
It took me 6 hours of debugging, but I found the code which caused it and I made a fix for it in apache source code (created a patch for it). New DA pre-release binaries should be ready soon (with template changes, putting RewriteRule in Directory context) and the patch will be uploaded to DA fileservers too. Hooray, PHP-FPM+Apache should finally be ready now in CB 2.0, and there are no other known bugs for it, so probably we could get CB 2.0 final by the time PHP 5.5 final is ready.
 

smtalk

Administrator
Staff member
Joined
Aug 22, 2006
Messages
9,362
Location
LT, EU
Latest pre-release of DA (Compile time: May 13 2013 or later) and latest CustomBuild 2.0-RC4 (latest version is always on files1.directadmin.com) have the fixes/patches included.
 

Magician

Verified User
Joined
Jan 31, 2010
Messages
124
Location
EU / PL
I`ve licence from my VPS provider. Any info when all fixes/patches will be available fol all users?
 

smtalk

Administrator
Staff member
Joined
Aug 22, 2006
Messages
9,362
Location
LT, EU
They already are available, however, some of rewrite rules do not work properly, so php-fastcgi is still recommended instead of php-fpm.
 

thesilentman

Verified User
Joined
Jun 17, 2003
Messages
51
Hi Martynas,

any news on when the functionality for use with php-fpm will be working properly? PHP-FPM is a lot more preferable than simple php-fastcgi.

Thanks :)
 
Top