Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've got a problem with configuring apache to run only files with .php extension through FastCGI. Sample VirtualHost configuration :

<VirtualHost 192.168.0.185:80>
    ServerName host1.example.com
    DocumentRoot /home/www/host1.example.com/WWW/

    SuexecUserGroup host1 www

    <Directory "/home/www/host1.example.com/WWW/">
        AllowOverride All
        Options +ExecCGI
        AddHandler fcgid-script .php
        FcgidWrapper /home/www/host1.example.com/fcgi/php5.fcgi
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

The problem is, that it also runs files like whats.new.in.php.6.html (basically every file containing .php followed by the dot) as fastcgi instead serving it as static content. I've tried changing AddHandler to

AddHandler fcgid-script .php$

With no luck - php files were not interpreted and served as plain text.

Is there a way to prevent this?

share|improve this question

2 Answers 2

One idea would be to remove the dollar sign. The AddHandler option takes the extension, not a regular expression or glob. So the correct line would be in your original

# With or without the leading dot, mod_mime doesn't care
AddHandler fcgid-script .php

As to why its flagging html files as executable, I have no idea--there could be a flag somewhere setting it, perhaps in a default configuration. However, as a workaround, you can REMOVE the handler for .html files by using the following, so that they will be treated as normal text/html files.

RemoveHandler .html
share|improve this answer
    
Please read carefully. This is what I have and it is still executing if there is .php in the file name followed by the dot. Dollar sign was my first guess but failed so I'm still using the line without dollar. –  dev-null-dweller Nov 25 '10 at 22:54
    
I blame the travel time and the tryptophan. :) Updated my answer to actually answer your question. –  Andrew M. Nov 25 '10 at 23:32
    
Does not work, besides there is no handler for HTML files. HTML was only example, it applies to all extensions: test.php.gif, test.php.txt etc. are all treated as fastcgi scripts, so even if removing handler would work, there is no way to define all possible extensions to remove handler. –  dev-null-dweller Nov 26 '10 at 8:30
up vote 0 down vote accepted

Ok, I managed to solve this. Instead of AddHandler I used AddType with handler name:

AddType fcgid-script .php

And now it works only for *.php files.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.