mod_php broken after system upgrade

Hi everyone, I looked for an answer to this problem, but couldn’t find it anywhere. If I’ve missed another post with the solution, please direct me there.

I recently upgraded from Ubuntu 10.04LTS (lucid) to 12.04 LTS (Precise) following the instructions found here:
http://www.virtualmin.com/documentation/system/os/ubuntu-lucid-to-precise

Now, however, I cannot get php pages to serve up correctly using mod_php. Here is a copy of my php5.conf file:


<FilesMatch “.ph(p3?|tml)$”>

SetHandler application/x-httpd-php

</FilesMatch>
<FilesMatch "\.phps$">

SetHandler application/x-httpd-php-source

</FilesMatch>
# To re-enable php in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
 <Directory /home/*/public_html>
      php_admin_value engine Off
  </Directory>
</IfModule>

As you can see, I’ve commented out the SetHandler lines as instructed. However, if I do this, and set my site to use mod_php (via Server Configuration -> Website Options) my php files do not get shown in the browser, but instead they want to be downloaded, as I am prompted with a save file box. If I change my site to use CGI Wrapper or FCGId, they are served fine.

If I leave the SetHandler lines uncommented, then my site is forced to use mod_php, no matter how I set things in Website Options.

Does anyone have any idea why this might be? It’s not a big deal, as it’s a private server, hosting only my sites, so I can choose just to leave the SetHandler lines uncommented for the time being. But I would like to try to figure out what’s going on and how to fix it so it works correctly.

Thanks.

Howdy,

Hmm, I seem to recall that the mod_userdir stuff can cause that problem if it’s enabled.

Try commenting out these lines in your php5.conf file:

php_admin_value engine Off

And then restart Apache:

/etc/init.d/apache2 restart

After that, does mod_php work for you?

-Eric

Thanks Eric,

With a php5.conf file that now looks like this:


<FilesMatch “.ph(p3?|tml)$”>

SetHandler application/x-httpd-php

</FilesMatch>
<FilesMatch "\.phps$">

SetHandler application/x-httpd-php-source

</FilesMatch>
# To re-enable php in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.

<Directory /home/*/public_html>

php_admin_value engine Off

If I enable mod_PHP via Website Options, my browser tries to download the php file. If I change to CGI Wrapper or FCGId, they are served fine.

Any other ideas? I can’t figure this one out. When I set my site to use mod_PHP in Website Options, what files are changed? Maybe if I can find that out I can further troubleshoot the issue.

I’ve done some additional troubleshooting, and have discovered the following:

When I use Website Options to choose to run PHP in a cgi wrapper, the file, /etc/apache2/sites-available/—.conf is edited to have these lines (address of my site/directory replaced throughtout by —):

<Directory /home/—/public_html>
Action application/x-httpd-php5 /cgi-bin/php5.cgi
AddType application/x-httpd-php5 .php5
AddType application/x-httpd-php5 .php

<Directory /home/—/cgi-bin>
allow from all

SuexecUserGroup “#1003” “#1002
RemoveHandler .php
RemoveHandler .php5

And if I set it to run PHP as FCGId, then the file is edited to include this:
<Directory /home/—/public_html>
Options Indexes IncludesNOEXEC FollowSymLinks +ExecCGI
allow from all
AllowOverride All
AddHandler fcgid-script .php
AddHandler fcgid-script .php5
FCGIWrapper /home/—/fcgi-bin/php5.fcgi .php
FCGIWrapper /home/—/fcgi-bin/php5.fcgi .php5

<Directory /home/—/cgi-bin>
allow from all

SuexecUserGroup “#1003” “#1002
RemoveHandler .php
RemoveHandler .php5
IPCCommTimeout 31
FcgidMaxRequestLen 1073741824

But when I set it to run as mod_php then the file looks like this:
<Directory /home/—/public_html>
Options Indexes IncludesNOEXEC FollowSymLinks +ExecCGI
allow from all
AllowOverride All

<Directory /home/—/cgi-bin>
allow from all

SuexecUserGroup “#1003” “#1002

So it seems to me that since it doesn’t set AddType directives for mod_php in my server’s .conf file, virtualmin thinks that the file handler directive should be set in another file. I think it wants to rely on the SetHandler lines in the php5.conf file, but they have been commented out by direction. (I have learned that SetHandler overrides all AddHandler or AddType directives, which is why it prevents the above changes from being effective if changed to CGI or FCGId in Website Options.)

This can be fixed by adding the line “AddType application/x-httpd-php .php” into the virtual server’s .conf file when mod_php is chosen in website options. Maybe a virtualmin developer can do this.

Howdy,

On Debian 6 and Ubuntu 12.04, it’s necessary (as you did) to comment out those to SetHandler lines in the php5.conf file.

Once you do that, you should be able to swap between FCGI, CGI, and mod_php – no special config is required, and you shouldn’t have to add any tweaks to your Apache config.

I think you’re seeing some interference from something… I’m not quite sure what, though my guess is an Apache module. I would have guessed that userdir stuff. That didn’t seem to help you though.

You could always try disabling userdir altogether, just to see if it helps (with a2dismod userdir).

I think I ran into the issue you’re seeing before, and I unfortunately don’t recall the cause. So it may take a little troubleshooting to figure this out :slight_smile:

I appreciate that one of the workarounds is to add a few lines into the Apache config… that is indeed working around the problem, but there’s likely another root cause somewhere, as those lines shouldn’t be necessary.

-Eric

Thanks for your comments. I did some more digging and here’s what I found. I already had the userdir module disabled.

However, in the MIME Type settings for Apache, there is the type “application/x-httpd-php5” that associates with .php files.

I changed the type to “application/x-httpd-php” and everything works perfectly. I can change back and forth between mod_php, CGI, and FCGId using Website Options without any problems.

My guess is that this is a leftover setting from when I had multiple PHP versions installed, as I also had similar lines for PHP 3 and 4. Since I only have one version of PHP installed on my system, there is no need to specify which version is running and therefore the system only sees “php” and not “php3”, “php4”, or “php5”.

Ah, super, I’m glad you figured it out! Thanks for letting us know how you got it working!

-Eric

Eric,

Do you know why virtualmin doesn’t allow me to delete mime types when in the MIME TYPES section of the Apache Webserver module? I can add and edit, but not delete.

Hmm, I’m not sure :slight_smile:

I might suggest filing a bug report / feature request regarding that, using the support link above.

It’s possible it’s just an oversite, as I don’t think Mime Types is a common thing folks end up tweaking.

-Eric