document root for multiple sites
Posted by: sonam (---.net.t-com.hr)
Date: September 20, 2006 02:10PM

Hi,
I am new on Wamp server, and I need help with start. I am instal all features, and server runing OK. Then, I am copy my old project to www folder and it is not work properly. I am using php comand:

<?php include_once $_SERVER["DOCUMENT_ROOT"] . "/folder/page.php"; ?>

where is "document root" my project folder. But server use "WWW" like "Document Root" not folder with my project. How and where I can change document root folder, and how I can define different root folders for different sites (if I work on two sites at once ).

Thanks,
Sonam

Options: ReplyQuote
Re: document root for multiple sites
Posted by: sonam (---.adsl.net.t-com.hr)
Date: September 22, 2006 08:32PM

Can someone to help me!



Sonam

Options: ReplyQuote
Re: document root for multiple sites
Posted by: CyberSpatium (67.170.181.---)
Date: September 23, 2006 04:27PM

use include_once ("/folder/page.php"winking smiley;

Options: ReplyQuote
Re: document root for multiple sites
Posted by: sonam (---.adsl.net.t-com.hr)
Date: September 23, 2006 08:10PM

Thanks,
I understand this moment, but I must (for my scripts) to use

$_SERVER["DOCUMENT_ROOT"]

because this script use same file for different pages in different folders. I must find out how to set up server, not my scripts what work properly when I put on internet server.



Sonam

Options: ReplyQuote
Re: document root for multiple sites
Posted by: CyberSpatium (67.170.181.---)
Date: September 23, 2006 09:37PM

huh?

Options: ReplyQuote
Re: document root for multiple sites
Posted by: caley (70.55.151.---)
Date: September 24, 2006 07:33AM

You can change your DocumentRoot in the httpd.conf file. Left click the wamp server icon in your tray and select Config files then httpd.conf ctrl "f" to find DocumentRoot ..... then make your change if you need to. Then restart apache... but you might not need to change your DocumentRoot.....

Because you're working on multiple sites i would simply suggest you change your code from:

<?php include_once $_SERVER["DOCUMENT_ROOT"] . "/folder/page.php"; ?>

to this

<?php include_once $_SERVER["DOCUMENT_ROOT"] . "/project/folder/page.php"; ?>

Won't that work?

Options: ReplyQuote
Re: document root for multiple sites
Posted by: caley (70.55.151.---)
Date: September 24, 2006 07:38AM

For your second project you would obviously have to use:

<?php include_once $_SERVER["DOCUMENT_ROOT"] . "/project2/folder/page.php"; ?>

if /wamp/www/ is your current DocumentRoot then just make sure /project/ and /project2/ are in the /www/ directory and use the above changes to your code.

hope that helps....

Options: ReplyQuote
Re: document root for multiple sites
Posted by: roms (---.fbx.proxad.net)
Date: September 24, 2006 10:02AM

Otherwise, if you need differnt documentroot for different porjets, you'll have to configure virtualhosts for your projects, see the apache documentation.



Romain

Options: ReplyQuote
Re: document root for multiple sites
Posted by: sonam (---.adsl.net.t-com.hr)
Date: September 24, 2006 08:51PM

Quote

Because you're working on multiple sites i would simply suggest you change your code from:

<?php include_once $_SERVER["DOCUMENT_ROOT"] . "/folder/page.php"; ?>

to this

<?php include_once $_SERVER["DOCUMENT_ROOT"] . "/project/folder/page.php"; ?>

Won't that work?


In that case I must for any page to change code before I upload this page on Internet. Hard work!


Quote

Otherwise, if you need differnt documentroot for different porjets, you'll have to configure virtualhosts for your projects, see the apache documentation.

Can you give me link or some more information I cannot find it.



Sonam

Options: ReplyQuote
Re: document root for multiple sites
Posted by: CyberSpatium (67.170.181.---)
Date: September 25, 2006 09:32AM

to be able to use multiple document roots you need to setup virutalhost. to do this you need a your own domain name. if you do not have your own domain name, you can get a free subdomain like yoursitehere.dyndns.org from dyndns.com.

if you have your own domain name, then signup for an account at zoneedit.com to setup your dynamic dns which will allow you to tie your domain name to your wamp server ip address. if you do not have your own domain, then skip zoneedit.com and signup for dynamic dns at dyndns.com and get your subdomain.

if you have your own domain name, you will need to login to your account where you registered your domain name and change the nameservers to zoneedits nameservers for you domain to work. also, you will need to setup and A type dns record in your zoneedit domain admin panel to tie your domain name to your wamp server ip address. setup two A records:

yourdomin.com A your.ip.address.here
www.yourdomain.com A your.ip.address.here

if you do not have your own domain name and are using the subdomains from dyndns.com, then login to your dyndns.com account and setup your subdomian to point to your ip address. I have never used dyndns myself, so I am not sure exacly how they do things there.

now you need to setup virtualhost in apache. here are some links all related to virtualhost and dynmic dns.


Official Apache documentation:

An In-Depth Discussion of Virtual Host Matching
[httpd.apache.org]

VirtualHost Examples
[httpd.apache.org]

Name-based Virtual Host Support
[httpd.apache.org]


DynDNS.com:

What is Dynamic DNS
[www.dyndns.com]

Can I have multiple hostnames/domains pointing to the same IP? Can they return different web sites?
[www.dyndns.com]


ZoneEdit FAQs:

How can I host multiple web sites on one IP Address?
[www.zoneedit.com]

What is Dynamic DNS
[www.zoneedit.com]

What is an "A" record?
[www.zoneedit.com]

How can I check to see if DNS is working?
[www.zoneedit.com]

Options: ReplyQuote
Re: document root for multiple sites
Posted by: sonam (---.adsl.net.t-com.hr)
Date: September 25, 2006 07:16PM

Thanks CyberSpatium,
but I don't need virtual host for on line different sites. I just want to use my localhost for different sites and every site must to have their root folder. For example:

localhost:99 is pointed on APACHE folder www/project1
localhost:101 is pointed on APACHE folder www/project2

OR

localhost/project1 is pointed on APACHE folder www/project1
localhost/project2 is pointed on APACHE folder www/project2


I find something in APACHE config and I try to do alias but it is not working. Here is this few lines from config:

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "C:/wamp/www"
Alias /fenix/ "C:/wamp/www/fenix/"



Sonam

Options: ReplyQuote
Re: document root for multiple sites
Posted by: CyberSpatium (67.170.181.---)
Date: September 25, 2006 11:54PM

ok, no problem then, this is really easy.

you can store you website files anywhere on your server using this method. you do not have to place them in your wamp\www folder. what i do is crete a folder called users in my c:\wamp\www folder, and store my sites there. that way all the websites are stored in one main folder. if you follow my instructions below, we are going to be setting up 3 websites. so, open up your c:\wamp\www\users folder and create a new folder with the name of your first website. for this example I am using website1. now open up that new folder you created and create two folders there, one called logs, the other public_html. the logs folder is where we will instruct apache to store all error and access logs for this website. the public_html folder is here you will put all your website files (html, php, css, images, etc). here is now the file structure should look:

c:\wamp\www\users\website1
c:\wamp\www\users\website1\logs
c:\wamp\www\users\website1\public_html

now repeat those steps to setup your other two sites when you are done, that file structure should look like

c:\wamp\www\users\website2
c:\wamp\www\users\website2\logs
c:\wamp\www\users\website2\public_html

c:\wamp\www\users\website3
c:\wamp\www\users\website3\logs
c:\wamp\www\users\website3\public_html

for the next step you will need to know your ip address. if you dont know it, use myipaddress.com.

now open up your httpd.conf file in notepad. find
Listen 80

below it add:
Listen 81
Listen 8080

now search for this:
#NameVirtualHost *:80

change it to this:
NameVirtualHost your.ip.address.here:80
NameVirtualHost your.ip.address.here:81
NameVirtualHost your.ip.address.here:8080

<VirtualHost your.ip.address.here:80>
ServerName localhost
DocumentRoot c:\wamp\www\users\website1\public_html
ErrorLog c:\wamp\www\users\website1\logs\error.log
CustomLog c:\wamp\www\users\website1\logs\access.log common
<Directory c:\wamp\www\users\website1\public_html>
Options Indexes FollowSymLinks Includes
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Directory>
</VirtualHost>

<VirtualHost your.ip.address.here:81>
ServerName localhost
DocumentRoot c:\wamp\www\users\website2\public_html
ErrorLog c:\wamp\www\users\website2\logs\error.log
CustomLog c:\wamp\www\users\website2\logs\access.log common
<Directory c:\wamp\www\users\website2\public_html>
Options Indexes FollowSymLinks Includes
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Directory>
</VirtualHost>

<VirtualHost your.ip.address.here:8080>
ServerName localhost
DocumentRoot c:\wamp\www\users\website3\public_html
ErrorLog c:\wamp\www\users\website3\logs\error.log
CustomLog c:\wamp\www\users\website3\logs\access.log common
<Directory c:\wamp\www\users\website3\public_html>
Options Indexes FollowSymLinks Includes
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Directory>
</VirtualHost>



ok, so now when you access your website with your browser, [localhost] will access website1. [localhost] will access website2. [localhost] will access website3

for security reasons, the way I have set this up is fof your websites to be only accessible by you. if however you wish to allow others to access your websites like a few friends or coworkers, you can change a setting to allow them to allow certain people then add their ip address to the allow list. for example, change

Order deny,allow
Deny from all
Allow from 127.0.0.1

to

Order deny,allow
Deny from all
Allow from 127.0.0.1
Allow from friends.ip.address.here

for your friends to be able to access your website, they will need your ip address. when they access [your.ip.address.here], they see site 1. when they access [your.ip.address.here], they see website2. if they access [your.ip.address.here] they see website3.

for each person you want to allow, add their ip address to the allow list. you can also allow anyone to access your websites (although for security reasons i advise you do not do this since wamp is not designed to be used as a production server) by changing this

Order deny,allow
Deny from all
Allow from 127.0.0.1

to this:

Order Allow,Deny
Allow from all



Post Edited (09-26-06 00:02)

CyberSpatium
----------------------
WAMP Forum Admin

Web Development for Newbie's Blog - Check out my new blog. It is for web developers, and especially tailored for the web development newbie. If you are not fluent in “geek speak”, then this incredible resource is just you. And even if you are a web development pro, this is a great resource to check out some of the latest web development tips, news, tutorials, codes and more.

Options: ReplyQuote
Re: document root for multiple sites
Posted by: sonam (---.adsl.net.t-com.hr)
Date: September 26, 2006 05:57PM

Thank you very much CyberSpatium,
I am save your post and will try to set up my server leter becuse I am little bit bussy.



Sonam

Options: ReplyQuote
Re: document root for multiple sites
Posted by: logisch (---.dip.t-dialin.net)
Date: November 02, 2006 02:45PM

see [www.chebucto.ns.ca]

as you can find there, 81 is already registered - but no one knows its purpose anyomre.

annother quite good reference is the linux file /etc/services.

in general ports byond above some value of 8000 are mostly unused
and are recomended for local testing.

for outside world offers, port 80 is the standard.
using something else might raise conflicts with firewalls,
decrease the general usability and possibly gives you
a false feeling of "security trough obscurity".
you will only trick a few computer illiterates but surely none of scripts from the script kiddies.

Options: ReplyQuote


Sorry, only registered users may post in this forum.