Results 1 to 6 of 6
-
09-17-2010, 12:31 PM #1
Freshman
- Join Date
- Sep 2010
- Posts
- 19
- Thanks
- 0
- Thanked 1 Time in 1 Post
- Feedback Score
- 0
[Apache] Setting up a simple virtual host
IMPORTANT: Take backups of all the files you edit during this tutorial, follow the steps in this tutorial at your own risk!
This tutorial will go through a very simple way of setting up virtual hosts in apache that is very easy and quick to do..
Step 1 – Edit the default virtual host
First of all you need to edit the default virtual host to tell apache to look look for the domains…
Make a backup of the default virtual host file first!
The default virtual host can be found on Ubuntu in the folder:
Replace the code in the default file for this:Code:/etc/apache2/sites-available/
(Replace the variables in {THESE} to reflect your server configuration)
Step 2: Create the folders for the domains.Code:<Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /domains/*/*/*/web/public_html> AllowOverride All Options IncludesNoExec ExecCGI </Directory> <Directory /home/*/*/*/web/public_html> AllowOverride All Options IncludesNoExec ExecCGI </Directory> <Directory /domains/*/*/*/web/public_html/_vti_bin> AddHandler application/x-suphp-cgi .exe RLimitCPU 40 40 </Directory> <VirtualHost {SERVER IP}:80> ServerName {SERVER NAME} ErrorLog /var/log/apache2/error_log CustomLog /var/log/apache2/sites_access_log ald RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1$1 [R=301,L] VirtualDocumentRoot /domains/%1.1/%1.2/%0/web/public_html # VirtualDocumentRoot only sets the effective document root for each site; # it doesn’t update the DOCUMENT_ROOT environment variable to reflect that # (and Apache developers are adamant this is the correct behaviour). Also # it isn’t possible to set DOCUMENT_ROOT manually, so instead set # VIRTUAL_DOCUMENT_ROOT to what we want DOCUMENT_ROOT to be, then use # suphp-docroot to intercept calls to suPHP and move the value of # VIRTUAL_DOCUMENT_ROOT into DOCUMENT_ROOT: RewriteEngine on RewriteCond %{LA-U:SCRIPT_FILENAME} ^/domains/(.*)/(.*)/(.*)/public_html/[^/]+ RewriteRule ^ – [E=VIRTUAL_DOCUMENT_ROOT:/domains/%1/%2/%3/public_html/] </VirtualHost> RewriteLock “/tmp/rewrite.lock” <VirtualHost *:81> ErrorLog /var/log/apache2/error_log CustomLog /var/log/apache2/sites_access_log ald RewriteEngine on RewriteLogLevel 0 RewriteRule ^/((.)(.)[^/]*)(.*) /home/$2/$3/$1/web/public_html/$4 </VirtualHost>
Run these commands in shell to create the directories required for the domains:
Step 3 – Restart ApacheCode:cd / mkdir domains cd /domains mkdir -p a b c d e f g h i j k l m n o p q r s t u v w x y z mkdir /domains/tmp cd /domains/tmp mkdir -p a b c d e f g h i j k l m n o p q r s t u v w x y z cp -R /domains/tmp/* /domains/a cp -R /domains/tmp/* /domains/b cp -R /domains/tmp/* /domains/c cp -R /domains/tmp/* /domains/d cp -R /domains/tmp/* /domains/e cp -R /domains/tmp/* /domains/f cp -R /domains/tmp/* /domains/g cp -R /domains/tmp/* /domains/h cp -R /domains/tmp/* /domains/i cp -R /domains/tmp/* /domains/j cp -R /domains/tmp/* /domains/k cp -R /domains/tmp/* /domains/l cp -R /domains/tmp/* /domains/m cp -R /domains/tmp/* /domains/n cp -R /domains/tmp/* /domains/o cp -R /domains/tmp/* /domains/p cp -R /domains/tmp/* /domains/q cp -R /domains/tmp/* /domains/r cp -R /domains/tmp/* /domains/s cp -R /domains/tmp/* /domains/t cp -R /domains/tmp/* /domains/u cp -R /domains/tmp/* /domains/v cp -R /domains/tmp/* /domains/w cp -R /domains/tmp/* /domains/x cp -R /domains/tmp/* /domains/y cp -R /domains/tmp/* /domains/z cp -R /domains/tmp/* /home/ cp -R /domains/tmp/* /home/a cp -R /domains/tmp/* /home/b cp -R /domains/tmp/* /home/c cp -R /domains/tmp/* /home/d cp -R /domains/tmp/* /home/e cp -R /domains/tmp/* /home/f cp -R /domains/tmp/* /home/g cp -R /domains/tmp/* /home/h cp -R /domains/tmp/* /home/i cp -R /domains/tmp/* /home/j cp -R /domains/tmp/* /home/k cp -R /domains/tmp/* /home/l cp -R /domains/tmp/* /home/m cp -R /domains/tmp/* /home/n cp -R /domains/tmp/* /home/o cp -R /domains/tmp/* /home/p cp -R /domains/tmp/* /home/q cp -R /domains/tmp/* /home/r cp -R /domains/tmp/* /home/s cp -R /domains/tmp/* /home/t cp -R /domains/tmp/* /home/u cp -R /domains/tmp/* /home/v cp -R /domains/tmp/* /home/w cp -R /domains/tmp/* /home/x cp -R /domains/tmp/* /home/y cp -R /domains/tmp/* /home/z rmdir /domains/tmp/* rmdir /domains/tmp/
Restart apache using this command in ubuntu:
Step 4 – Set up a domainCode:/etc/init.d/apache2 restart
To set up a domain in this configuration, you need to make a directory in the home folder and a symbolic link in the domains folder to it as I will show you below:
If you wanted to use the domain example.com:
You can now place the website files in the public_html folder where the domain is pointed to.Code:mkdir /home/e/x/example mkdir /home/e/x/example/web mkdir /home/e/x/example/web/public_html ln -s /home/e/x/example /domains/e/x/example.com
If you don’t want to do this every time you want to add a domain, you could use the php script that is attached to this post and upload it to a passworded folder on the server to create more domains quickly and easily.
© 04blatca
haynes11
shareurlinks
http://www.mywebforums.net
You may not copy this tutorial without my permission.
Please let me know by replying below if you find anything wrong with this tutorial, Thanks
For more tutorials visit: http://www.mywebforums.net
Thanks
Haynes11
-
02-27-2011, 11:26 PM #2
Sophomore
- Join Date
- Feb 2011
- Posts
- 67
- Thanks
- 0
- Thanked 0 Times in 0 Posts
- Feedback Score
- 0
Hi
What is viral host in apache please explain it and when it will create or what?
-
07-19-2011, 08:41 PM #3
I have to admit this is unusually complex way to setup a virtual host.
-
07-20-2011, 12:22 AM #4
Freshman
- Join Date
- Jul 2011
- Posts
- 3
- Thanks
- 0
- Thanked 0 Times in 0 Posts
- Feedback Score
- 0
I have to agree with that. The virtual host itself is can be simplified alot more, there are numerous options which are not needed or are not correct in the above. For example, you doe not have to have the entire rewrite rules into that virtual host since you have the directive "AllowOverride All", which enables you to place these rewite rules in a spearate .htaccess file. Also, the handler "AddHandler application/x-suphp-cgi .exe" is not needed. Alot more simpler example of a virtual host would be the following:
Code:<VirtualHost *:80> ServerName example . com ServerAlias example . com DocumentRoot /home/www/example . com <Directory /home/www/example . com> Options FollowSymLinks -ExecCGI -Indexes Order Allow,Deny Allow from all AllowOverride All </Directory> </VirtualHost>
-
07-20-2011, 01:19 AM #5
Sophomore
- Join Date
- Jul 2011
- Posts
- 100
- Thanks
- 0
- Thanked 0 Times in 0 Posts
- Feedback Score
- 0
I didn't get you friend.Can you explain it properly and perfectly ?
-
09-11-2011, 08:41 AM #6
Freshman
- Join Date
- Sep 2011
- Posts
- 14
- Thanks
- 0
- Thanked 0 Times in 0 Posts
- Feedback Score
- 0
You can set up Plesk to web server ! it great!
Similar Threads
-
What is Apache?
By antonclovelly in forum Web Development - Programming & CodingReplies: 0Last Post: 05-17-2010, 06:29 AM -
CF 4.5.1 with Apache 2.2.x?
By Abina in forum ColdFusionReplies: 1Last Post: 02-02-2010, 11:23 AM -
Mount Shared Folder from Virtual Host- Server 2008?
By bluewhale in forum Windows ServerReplies: 0Last Post: 01-06-2010, 10:05 AM -
Virtual Keyboard
By JavaScriptBank in forum JavaScript & AJAXReplies: 0Last Post: 11-29-2009, 08:09 PM -
Simple Web Design with Simple Rules
By manik in forum Graphics Design & Web DesignReplies: 3Last Post: 11-06-2008, 01:09 AM


Reply With Quote


