Forum Moderators: coopster

Message Too Old, No Replies

Apache and Multiple Site Developments

Best Practice or Suggestions

         

ukgimp

10:33 am on Feb 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello

I have a number of sites using apache and php. Problems start to occur when I wish to do full development stuff with databases, includes etc. Fine, I can set one site to root so that all the includes and paths work OK. But how do you do with multiple sites.

Subdomains sound a possibility but not on my local development machine (windows running apache)

How do you handle such things. Would or do aliases work.

Regards

dcrombie

10:52 am on Feb 6, 2004 (gmt 0)



I have an alias directory set up in httpd.conf that all our sites can include from. Without that I'd have lost control years ago ;)

ukgimp

11:00 am on Feb 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How do you go about doing that. Are there any oline tutorials on setting this sort of thing up?

Cheers

dcrombie

12:51 pm on Feb 6, 2004 (gmt 0)



I'm using Darwin (Mac OS X) so it's going to be a bit different. In httpd.conf I have:

<IfModule mod_php4.c>
php_value include_path .:/path/to/shared/directory
</IfModule>

ukgimp

2:24 pm on Feb 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



dc

How does that work. Little lost on that one.

dcrombie

2:35 pm on Feb 6, 2004 (gmt 0)



You put in the path to a directory somewhere on the site that you want to store PHP files in (eg. database code libraries, common include files, ...).

Then in a PHP file anywhere on the server you can jsut "include" any file in that directory as if it was in the current directory.

Make sense?

ukgimp

3:28 pm on Feb 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This has the potential to be quite cool, if I can get is working. I seem to be partway there. I have the following in my httpd.conf

Alias /ban/ "F:/ban/"
<Directory "F:/ban/">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from localhost 127.0.0.1
DirectoryIndex index.php
</Directory>

As you mentioned the includes are causing problems.

Do I need to use the following in some way?

<IfModule mod_php4.c>
php_value include_path .:/path/to/shared/directory
</IfModule>

On a related theme as well, will I have to alter my rewrite rules to include the extra folder?.

isitreal

5:11 pm on Feb 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I believe this is what you're looking for, at the end of your httpd.conf file there is the following. You probably just have the localhost one, all you have to do is add more, following this syntax. The allowoverride makes it so apache doesn't use the htaccess files you might be running on your real server, so you can have exact duplicates of your site code. You can put anything site specific into each sites information. Servername is the address you type in your browser to reach your site (IE has some problems with this sometimes). You also have to go in and add all the sites' names into your:
c:\win [or winnt]\system32\drivers\etc\hosts

that would look like this:
127.0.0.1 localhost site1 site2

and so on for each site, use only one line, no commas, no linebreak for all your sites, save that back into that directory, then add the following, remember that you have to restart apache each time you make a change to the httpd.conf file before it takes affect.

NameVirtualHost 127.0.0.1:80

##LOCALHOST##
<VirtualHost 127.0.0.1:80>
ServerName localhost
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "c:/program files/apache group/apache2/htdocs"
</VirtualHost>

## site 1 ##
<VirtualHost 127.0.0.1:80>
ServerName site1
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "c:/websites/site1"
<Directory "c:/websites/site1">
AllowOverride None
</Directory>
php_value include_path ".;c:/websites/site1/includes"
DirectoryIndex index.php index.html index.htm
</VirtualHost>

## site2 ##
<VirtualHost 127.0.0.1:80>
ServerName site2
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "c:/websites/site2"
<Directory "c:/websites/site2">
AllowOverride None
</Directory>
php_value include_path ".;c:/websites/site2/includes"
DirectoryIndex index.html index.htm
</VirtualHost>

ukgimp

10:27 am on Feb 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



is it real

Thanks for that. I will have to play.

What I have been finding problematic is my links. When I got to the folder [localhost...] all the pages work fin but the links take it back to root, which is a bit of a nause.

Cheers

ukgimp

10:44 am on Feb 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have been playing but I get problems with absolute links going back to the root, rather than the alias, The only way I can get things to work is to change the main config:

DocumentRoot "C:/myfolder/subfolder/"

which means a restart of the server each time I wish to changes sites.

Cheers