PHP won't interpret files placed in an arbitrary directory

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
Imyself
Forum Newbie
Posts: 2
Joined: Wed Jul 16, 2008 5:38 am

PHP won't interpret files placed in an arbitrary directory

Post by Imyself »

Hi

I've got my website folder in "My documents" folder and I'm trying to set up Apache to run the php files there through the php interpreter.

It all works fine when I put my website folder into c:\www\vhosts\localhost, but that's not what I want.

So that's what I did:

I created the my_website.conf file in C:\www\Apache22\conf\extra\vhosts\localhost
It contains:

Code: Select all

 
Alias /my_website "C:\Documents and Settings\I\My Documents\my_website"
 
<Directory "C:\Documents and Settings\I\My Documents\my_website">
    Options All
    AllowOverride All
    order allow,deny
    allow from all
</Directory>
 
Now, this file is included from within C:\www\Apache22\conf\extra\httpd-vhosts.conf, which contains this bit:

Code: Select all

 
<VirtualHost *:80>
    DocumentRoot /www/vhosts/localhost/
    ServerName localhost
 
    Include conf/extra/vhosts/localhost/*.conf      # <----------- The bit that counts
</VirtualHost>
 
However, when I go to localhost/my_website in my browser, I see the raw content of the index.php file that is inside of the "my_website" folder. This means that the website folder is found and accessible but it's not going through the php interpreter at this occasion.

My php set-up works otherwise. .. and yes I did restart apache

Any advice would be appreciated

Cheers!
Michael
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: PHP won't interpret files placed in an arbitrary directory

Post by jaoudestudios »

There is a much easier way.

I am assuming you are using WAMP?

If I remember correctly (have not used windows in ages). In the http.conf file you can specify the root of your web directory. Apache will always compile that directory when http://LOCAHOST/ is typed in.
Imyself
Forum Newbie
Posts: 2
Joined: Wed Jul 16, 2008 5:38 am

Re: PHP won't interpret files placed in an arbitrary directory

Post by Imyself »

If I remember correctly (have not used windows in ages). In the http.conf file you can specify the root of your web directory. Apache will always compile that directory when http://LOCAHOST/ is typed in.
Thanks, but unfortunately, that didn't work either - had exactly the same effect - raw text unprocessed by php.

I fould a solution though.

In my apache distribution, I found these lines inside of my httpd.conf file:

Code: Select all

# mod_php5
Include conf/extra/suite-php5.conf
This is what I found inside of the included file (suite-php5.conf):

Code: Select all

LoadFile "/www/php5/php5ts.dll"
LoadModule php5_module /www/php5/php5apache2_2.dll
 
<IfModule php5_module>
 
    PHPIniDir "/www/php5"
 
    <Directory "/www/vhosts/*/">                       # <----------- The only directories to be processed by php
        AddType text/html .php .phps
        AddHandler application/x-httpd-php .php
        AddHandler application/x-httpd-php-source .phps 
    </Directory>
 
</IfModule>
So, I edited the file by adding an additional <Directory> section:

Code: Select all

LoadFile "/www/php5/php5ts.dll"
LoadModule php5_module /www/php5/php5apache2_2.dll
 
<IfModule php5_module>
 
    PHPIniDir "/www/php5"
 
    <Directory "/www/vhosts/*/">
        AddType text/html .php .phps
        AddHandler application/x-httpd-php .php
        AddHandler application/x-httpd-php-source .phps 
    </Directory>
 
    <Directory "C:\Documents and Settings\I\My Documents\my_website">   # <----------- I added this section ---v
        AddType text/html .php .phps
        AddHandler application/x-httpd-php .php
        AddHandler application/x-httpd-php-source .phps
    </Directory>                                                     # <------------End of the added bit ---^
 
</IfModule>
 
That solved it. Now my website is dynamically generated by php instead of just being served as unprocessed php code. :)
Doug G
Forum Contributor
Posts: 282
Joined: Sun Sep 09, 2007 6:27 pm

Re: PHP won't interpret files placed in an arbitrary directory

Post by Doug G »

I'd avoid putting web files in your user profile directory on a windows computer. Windows has features that could mess up your site later. For example, you may decide to encrypt your profile in the future or privacy-protect your profile, either would cause your web server to lose access to the files.
Post Reply