Custom file extension in PHP and Apache....
Ok, In this pretty much useless tutorial ill show you guys how to make any file extension work with PHP in Apache.... Would you like that index.yourname? ;)
Ok, First for the Windows Users.... Im assuming that you have Apache with PHP up and running.... If not check out Apache [http://httpd.apache.org] and PHP [http://php.net] for help....
Ok, Open your httpd.conf [C:\Program Files\Apache Group\Apache\conf\] by default and go all the way to the bottom.... If you installed PHP correctly you should see:
Code:
ScriptAlias /php/ "X:/path/to/php/"
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php4
AddType application/x-httpd-php .phtml
Action application/x-httpd-php "/php/php.exe"
Now we need to add our own custom handler... For this example I'll Add index.ac1d as a file for PHP to parse....
Code:
ScriptAlias /php/ "X:/path/to/php/"
AddType application/x-httpd-php .php
AddType application/x-httpd-php .ac1d
AddType application/x-httpd-php .php4
AddType application/x-httpd-php .phtml
Action application/x-httpd-php "/php/php.exe"
Ok, Now that we have that set up we need to edit DirectoryIndex to read index.ac1d as the index file for each directory on your server =)
Before
Code:
<IfModule mod_dir.c>
DirectoryIndex index.html index.php
</IfModule>
...and After
Code:
<IfModule mod_dir.c>
DirectoryIndex index.ac1d index.html index.php
</IfModule>
Now, Go to your webservers root Directory [htdocs] and make a index.yourfileext with the following contents:
PHP Code:
<?php
echo "w00t! PHP works with the custom extension!";
?>
If that works, You got it.... If not go back and see what you did wrong ;)
For Linux users:
First of all install apache_devel, php, and mod_php.... Then add this line to the end of the loading scripts in httpd.conf (If you have not already done so)
Code:
LoadModule php4_module modules/libphp4.so
Then somewhere below that add the following
Code:
AddModule mod_php4.c
<IfModule mod_php4.c>
AddType application/x-httpd-php .php
AddType application/x-httpd-php .yourext
AddType application/x-httpd-php .php4
AddType application/x-httpd-php .phtml
</IfModule>
Change the DirectoryIndex as with the Windows Part of this tutorial, Make the file.... And your done =)