Custom file extension in PHP and Apache....
Results 1 to 7 of 7

Thread: Custom file extension in PHP and Apache....

  1. #1

    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 =)

  2. #2
    Senior Member
    Join Date
    Jan 2002
    Posts
    121
    * Alex wonders why no one replied to his tut

    hehe well heres a response, nice info alex
    what is love but contempt for hate?

  3. #3
    Ahhhh,
    Thanks indolent

  4. #4
    Junior Member
    Join Date
    Mar 2002
    Posts
    10
    Alex another great tut.... keep it up man

  5. #5
    Senior Member
    Join Date
    Jul 2002
    Posts
    154
    You can also do that in .htaccess, but doing it that way is much more simple.

  6. #6
    Great tutorial dude! Yeah, when you were teaching us that in IRC, I was like so happy. It is a great tutorial that, IMO, is a cool subject. Good Job! -- Jason Copeland

    P.S : Keep up the great tutorials

  7. #7
    Kwiep
    Join Date
    Aug 2001
    Posts
    924
    Well, if you want a reply, you get one !!! The tut is very cool (and useless to most, but who cares ) and well I already told you this... Good tut !!!
    Double Dutch

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •