Page 1 of 1

php only showing one virtualhost

Posted: Fri Sep 05, 2008 2:15 pm
by cyjetsu
I am running php on apache. I have setup multiple virtual-hosts on apache and managed to get php scripts working on a test website, but I am having trouble getting apache files to run on all my virtual hosts.

In my php.ini file at the bottom I have added
doc_root = "c:\test"
extension_dir = "C:\php\ext"
extension=php_mysqli.dll.

So when I go to http://lc.test.com/, it successfully runs my php test script in the browser.
However... when I go to my other virtualhost site http://lc.informativesolutions.com/, it actually runs the same script from c:\test, when my index.php file in the informativesolutions directory is a completley different file. Is that normal?

Anyway I want to set up php for all my sites so do I add doc_root and extension dir per virtual host like this:
doc_root = "c:\test"
extension_dir = "C:\php\ext"
extension=php_mysqli.dll.

doc_root = "c:\apple"
extension_dir = "C:\php\ext"
extension=php_mysqli.dll.

doc_root = "c:\tango"
extension_dir = "C:\php\ext"
extension=php_mysqli.dll.

Or do I need to specifiy the name of the virtualhost along with it? Or put php access to virtual hosts somewhere else?

Also in my apache's httpd.conf file I have:
DocumentRoot "C:/test"
<Directory "C:/test">

and Include conf\virtual-hosts.conf where I have setup my virtual hosts.

I am not sure if the docroot and dir entries in the httpd conf is why it isnt working, same as in the php file I am not sure if I should add more entries for each host or if there should only be one.

when viewing normal html files, each virtualhost site displays the correct files for that individual website so I am positive that my virtualhosts directory setup is correct and different for each virtualhost. It is only when viewing php file that it seems to leap from my virtualhost to the test directory.

Re: php only showing one virtualhost

Posted: Fri Sep 05, 2008 2:44 pm
by VladSun
your vhosts.conf file should look like this:

Code: Select all

NameVirtualHost *:80
 
<VirtualHost *:80>
    DocumentRoot "c:/apple"
    ServerName apple.com
    ServerAlias http://www.apple.com
    ErrorLog "logs/apple-error.log"
    CustomLog "logs/apple-access.log" common
</VirtualHost>
 
<VirtualHost *:80>
    DocumentRoot "C:/tango"
    ServerName tango.com
    ServerAlias http://www.tango.com
    ErrorLog "logs/tango-error.log"
    CustomLog "logs/tango-access.log" common
</VirtualHost>
.......................
 

Re: php only showing one virtualhost

Posted: Fri Sep 05, 2008 2:59 pm
by cyjetsu
it does. this is what is i my vhosts file:

NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
ServerName lc.test.com
DocumentRoot "C:\test"
CustomLog logs\lc.test.com.access.log combined
ErrorLog logs\lc.test.com.error.log
</VirtualHost>

<VirtualHost 127.0.0.1:80>
ServerName lc.informativesolutions.com
DocumentRoot "C:\operator1\on-infosol\primary"
CustomLog logs\lc.informativesolutions.com.access.log combined
ErrorLog logs\lc.informativesolutions.com.error.log
</VirtualHost>

NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
ServerName lc.aivdesign.com
DocumentRoot "C:\operator1\on-aivdesign\primary"
CustomLog logs\lc.aivdesign.com.access.log combined
ErrorLog logs\lc.aivdesign.com.error.log
</VirtualHost>

<VirtualHost 127.0.0.1:80>
ServerName lc.onmedias.com
DocumentRoot "C:\operator1\on-onmedias\primary"
CustomLog logs\lc.onmedias.com.access.log combined
ErrorLog logs\lc.onmedias.com.error.log
</VirtualHost>

<Directory C:\operator1>
Order Deny,Allow
Allow from all
</Directory>


I have html files in all my site directories except test, so when I go to lc.onmedias.com, or lc.aivdesign.com, it shows those website files..... but if I rename index.html to index.php and go to that site(lc.onmedias.com), the browser shows the php test output from the file in C:\test which is also index.php when it should be taking index.php from C:\operator1\on-onmedias\primary, as it does correctly take index.html from that virtual host directory.

Re: php only showing one virtualhost

Posted: Fri Sep 05, 2008 3:17 pm
by cyjetsu
I fixed it simply by removing doc_root = "c:\test" from my php.ini file. I was told to add that during php setup, not sure why becuase php seems to work a whole lot better without it.