Click to See Complete Forum and Search --> : [RESOLVED] php on two apache vurtualhost sites


Dave Liebman
07-19-2006, 03:49 PM
I'm pretty new to forums, so here goes...

I'm using apache on a win32 system and I'm using php. I have two virtual sites, but can get php to run on only one of them. I can set the php document root only to one of the two virtual sites. If I want php to run on both sites, do I duplicate php, or what(??) It's php5, and apache 2. Maybe there's some simple solution I don't know about. Any help would be helpfull.

tsinka
07-19-2006, 04:26 PM
Hi,

please post httpd.conf and php.ini as attachment (in a zip file). You don't need to install php twice.

Thomas

MarkR
07-20-2006, 03:18 AM
You don't need to set the PHP document root at all. If you set the handler up outside of any virtual host, it should just work in all defined virtual hosts (unless any of them modifies any php settings, e.g. php_flag engine off)

Mark

Dave Liebman
07-20-2006, 08:42 AM
Well, here's the php.ini file and part of the httpd.conf file. As you will see, I'm not actually serving the site to the whole internet. It only exists on my machine... I use IP# 127.0.0.1 I hope this is not discouraging.

tsinka
07-20-2006, 02:46 PM
I'd suggest to install PHP as apache module. Besides that think about installing xampp (http://www.xampp.org). This package comes with almost everything you need (incl. apache, mysql, php and much more).

The steps to install PHP as module (assuming that you want to install php 5.x to C:\PHP).

1. copy at least php5ts.dll to the <apache>\bin directory
2. depending on the PHP extensions you want to enable you might need to copy some of the other dlls from C:\PHP to the <apache>\bin directory. There's a text file in the PHP directory that contains a list of the extensions and depending dlls.
3. copy php.ini to <apache>\bin and make sure to set at least the extension_dir variable in php.ini (C:\php\ext)
4. Edit httpd.conf and remove all the lines you added to enable php.
5. Then add the following line to httpd.conf at the end of the LoadModule block:
LoadModule php5_module C:\PHP\php5apache2.dll
6. Add the following line to httpd.conf:
AddType application/x-httpd-php .php

Then restart apache. Create a script in the document root directory that contains


<?PHP
phpinfo();
?>


and check if that script works.

About the virtual hosts. Modify the virtual host blocks so that the heads contain the ip address, like e.g.


NameVirtualHost 127.0.0.1:80
...
...
<VirtualHost 127.0.0.1:80>
ServerName www.mydomain1.com
DocumentRoot C:\sites\www.mydomain1.com\htdocs
....
</VirtualHost>

<VirtualHost 127.0.0.1:80>
ServerName www.mydomain2.com
DocumentRoot C:\sites\www.mydomain2.com\htdocs
....
</VirtualHost>


In order to test the virtual hosts modify the file <windows>\system32\drivers\etc\hosts and add (or modify) the following line:

127.0.0.1 www.mydomain1.com www.mydomain2.com

(just add the two strings to the 127.0.0.1 line if it already exists)

Then close and reopen the web browser and try to access the two different virtual hosts.

Thomas

Dave Liebman
07-21-2006, 01:25 PM
Thanks much. I'll try all. Thanks again. - Dave Liebman

tsinka
07-21-2006, 01:32 PM
Do you use apache 2.0.x or apache 2.2.x ?

In case of apache 2.2.x you can download a php dll at www.apachelounge.com (http://www.apachelounge.com/download/)

Thomas

Dave Liebman
07-21-2006, 02:30 PM
That's Great! Everything works fine. (I think it's Apache 2.0) Here's a question, does the php work on the second site now (when it didn't before) because I changed php over to a module, or because I modified the virtualhost section of the httpd.conf (??) Other than this final question I think I'm totally satisfied... thanks so much. -Dave Liebman

tsinka
07-21-2006, 02:36 PM
I don't know exactly why that happened. Maybe because doc_root was set in php.ini.

Thomas

Dave Liebman
07-23-2006, 08:52 AM
Thank you. I downloaded xampp. It seems to work well. I may have questions regarding xampp in the future, but none now. You've been a tremendous help. -Dave Liebman