Page 1 of 1

PHP won't interpret files placed in an arbitrary directory

Posted: Wed Jul 16, 2008 6:03 am
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

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

Posted: Wed Jul 16, 2008 4:29 pm
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.

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

Posted: Tue Aug 05, 2008 9:34 am
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. :)

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

Posted: Tue Aug 05, 2008 4:15 pm
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.