Results 1 to 6 of 6
  1. #1
    haynes11 is offline Freshman
    Join Date
    Sep 2010
    Posts
    19
    Thanks
    0
    Thanked 1 Time in 1 Post
    Feedback Score
    0

    Cool [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:
    Code:
    /etc/apache2/sites-available/
    Replace the code in the default file for this:
    (Replace the variables in {THESE} to reflect your server configuration)
    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>
    Step 2: Create the folders for the domains.
    Run these commands in shell to create the directories required for the domains:
    Code:
    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/
    Step 3 – Restart Apache

    Restart apache using this command in ubuntu:
    Code:
    /etc/init.d/apache2 restart
    Step 4 – Set up a domain

    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:
    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
    You can now place the website files in the public_html folder where the domain is pointed to.
    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

  2. #2
    prptl709 is offline Sophomore
    Join Date
    Feb 2011
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Feedback Score
    0

    Question Hi

    What is viral host in apache please explain it and when it will create or what?

  3. #3
    jcourtenay's Avatar
    jcourtenay is online now Guardian
    Join Date
    Jan 2011
    Location
    Wirral, UK
    Posts
    3,665
    Thanks
    22
    Thanked 19 Times in 19 Posts
    Feedback Score
    0

    Default

    I have to admit this is unusually complex way to setup a virtual host.
    Free web space from Worlditsme, offering free web hosting packages and free php hosting

  4. #4
    dzhorov is offline Freshman
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Feedback Score
    0

    Default

    Quote Originally Posted by jcourtenay View Post
    I have to admit this is unusually complex way to setup a virtual host.
    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>

  5. #5
    garathnormanmtts is offline Sophomore
    Join Date
    Jul 2011
    Posts
    100
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Feedback Score
    0

    Default

    I didn't get you friend.Can you explain it properly and perfectly ?

  6. #6
    kenjipro is offline Freshman
    Join Date
    Sep 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Feedback Score
    0

    Default

    You can set up Plesk to web server ! it great!

Similar Threads

  1. What is Apache?
    By antonclovelly in forum Web Development - Programming & Coding
    Replies: 0
    Last Post: 05-17-2010, 06:29 AM
  2. CF 4.5.1 with Apache 2.2.x?
    By Abina in forum ColdFusion
    Replies: 1
    Last Post: 02-02-2010, 11:23 AM
  3. Mount Shared Folder from Virtual Host- Server 2008?
    By bluewhale in forum Windows Server
    Replies: 0
    Last Post: 01-06-2010, 10:05 AM
  4. Virtual Keyboard
    By JavaScriptBank in forum JavaScript & AJAX
    Replies: 0
    Last Post: 11-29-2009, 08:09 PM
  5. Simple Web Design with Simple Rules
    By manik in forum Graphics Design & Web Design
    Replies: 3
    Last Post: 11-06-2008, 01:09 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •