|
PHP Training Schedule | |||||||||||||
|
||||||||||||||
|
now@nyphp
Hot Threads » [OT] Managed hosting on the east coast? » [OT] Managed hosting on the east coast? » talk Digest, Vol 33, Issue 2
Resources
About NYPHP
Site Tools
|
NYPHP - PHundamentalsVirtual Hosting Setup - Windows 98/XP & Linux with ApachePROBLEM:You'd like to have two (or more) client projects located within the DocumentRoot directory (/var/www/html or whatever directory you may use for DocumentRoot) of your Linux server but you want to keep their files separate. So you place the files in separate subdirectories (/var/www/html/myproj1 and /var/www/html/myproj2). But you run into an interesting problem. In "myproj1" your web pages have a link to the project's home page and this home page is normally located, not in /var/www/html/myproj1 but in /var/www/html. That is, it is normally located in your default DocumentRoot directory. You could set all of the home page links to refer to this subdirectory but when you move your code from your development server to your client's server, all links referring to the "home" page will refer to the "myproj1" subdirectory and not the default DocumentRoot (see Note 1). One way to handle this problem and to have all of your page links work correctly is to set up virtual hosts. Virtual hosts will resolve all of the different path issues and you can develop your project as if it were the only project on your server. You'll have eliminated the need to worry about your home page being in a subdirectory of DocumentRoot. Therefore, different projects will be in their own subdirectories under /var/www/html and the links will work correctly both on your development server and on your client's server. The solution provided below assumes that you want to set up virtual hosting within a networked office and that your working environment (that is, your development environment) consists of:
SOLUTION:1. Make sure you have administrative rights on Windows XP and superuser (a/k/a "root") access on the Linux server. 2. You will need to change two files:
3. In the "hosts" file the first line (localhost) already exists. Add one or more lines with the IP address of your Linux box and the name you want to use to access the project. For example, since my Linux box has an IP address of 192.168.1.111, I added the line "192.168.1.111 myproj1" and then added "192.168.1.111 myproj2" for the second project. (see Note 2) 127.0.0.1 localhost 192.168.1.111 myproj1 192.168.1.111 myproj2 4. In httpd.conf you set the following:
<VirtualHost 192.168.1.111:80>
DocumentRoot /var/www/html
ServerName linux
</VirtualHost>
<VirtualHost 192.168.1.111>
DocumentRoot /var/www/html/myproj1
ServerName myproj1
</VirtualHost>
<VirtualHost 192.168.1.111>
DocumentRoot /var/www/html/jeff
ServerName myproj2
</VirtualHost>
Note that the name of the subdirectory for "myproj2" does not match the subdirectory name. The DocumentRoot
is just the actual path to the files whereas the ServerName is the name you would use in your browser to
access the files. (see Note 3)
Safety Note: You may want to make a backup copy of your httpd.conf file in case you make a serious error. You
can use the command "cp httpd.conf httpd.conf.bak" to make a copy of the configuration file.
TESTING:Create two different PHP files (or regular HTML files) and place one in the directory /var/www/html/myproj1 and the other in the directory /var/www/html/jeff. If you set up everything correctly, you should be able to see the first web document using the URL http://myproj1 and the second web document using the URL http://myproj2. Basic Definitions:
DocumentRoot: the default directory used by Apache to serve web documents. When a web browser points to a
domain, whether it is accessed by a domain name such as "http://www.mydomain.com" or by an IP address such as
"http://192.168.1.111," Apache will send back to the web browser the document it finds in the DocumentRoot
directory.
Notes:
1- We are assuming that your client's server does not have virtual hosts set up.
Contributors to this note include the following:
If you see an error, or have a suggestion for an improvement, please let us know and Contact Us. |
|
|||||