Make file extension to be interpreted by PHP Make file extension to be interpreted by PHP php php

Make file extension to be interpreted by PHP


It seems as if the FastCGId module doesn't know how to execute your script - the FcgidWrapper directive seems to be missing (as your PHP script doesn't have a Shebang).

Depending on your distribution you have to set it up manually or you can adjust the existing directive which already handles .php files to also handle .test files (Usually this should be done using the "SetHandler fcgid-script" directive and setting/duplicating the FcgidWrapper directive).

Adjusted example (taken from https://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#examples):

<FilesMatch "\.test$">    AddHandler fcgid-script .test</FilesMatch>Options +ExecCGIFcgidWrapper /usr/bin/php5-cgi .test

More information and examples: https://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#examples and http://tltech.com/info/php-on-fcgid/

Other problems could be based on permissions, e.g. if you're using suexec that the fastcgid process cannot write to the logs or cannot execute the wrapper script. Here it would be really helpful if you could state if normal .php files are executed properly.


Try to use this in your htaccess file

AddType application/x-httpd-php .test

See this Stack Overflow question: Problem with Executing CGI Scripts on Apache.


Tested and verified to work:

Because you mentioned you are using Webmin, I tailored my answer for Webmin. You can do this by editing Apache's configuration through shell as well.

I will note that it is generally preferable to edit Apache's configuration, and in this case probably unavoidable, as I do not believe you can make this sort of edit in .htaccess. Although there may be a hack I'm unfamiliar with, a server admin would probably want to keep this locked inside of apache configuration. Thoughts of .htaccess files with rogue file extensions flying around on a per-directory basis not only sounds slow, but also highly insecure.

Steps

I installed Apache on Ubuntu 14.04 through VirtualBox. I added Webmin and FastCGI.

I took the following steps:

  1. Log into Webmin, go to your Virtual Host.
  2. Click on Edit Directives
  3. Add the following at the bottom:

<Directory />    #Your SetHandler script here     #(@MrTux's script works here but NOT IN .htaccess)        Require all granted</Directory>
  1. Click Save
  2. Click "Apply Changes" at the top.
  3. You're done!

I will note that SetHandler passes some headers, so if you declare this in .htaccess there is a chance that headers have already been sent which is what is triggering your error. Again, .htaccess is not the preferred way to set rules if you have control over your system. In this case it would probably cause security issues anyway.