Jump to Navigation

089 - Virtual Hosting using Apache2 on ubuntu/linux

Virtual Hosting allow web servers to host more than one website on a sing machine. This is how sharing hosting works.
This allows you to access to your local repository using addresses such as http://mysite.com instead of http://localhost/~myuser/www/ : ) .
If you have installed webmin in your server, it might be easy to setup apache vitrual host.

1. Prepare for your configuration file.

# cd /etc/apache2/sites-available
# sudo cp default mysite

2. Edit you configuration file.

sudo vi /etc/apache2/sites-avairable/mysite

3. Change all parameters in order to fit your website and save it.

Example :

<VirtualHost *:80>
DocumentRoot "/var/www/mysite"
ServerName mysite
ServerAdmin webmaster@localhost
  <Directory />
    Options FollowSymLinks
  AllowOverride All
  </Directory>
  <Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
  </Directory>
    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  <Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
  </Directory>
    ErrorLog /var/log/apache2/error.log
    LogLevel warn
    CustomLog /var/log/apache2/access.log combined
    Alias /doc/ "/usr/share/doc/"
  <Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
  </Directory>
  <Directory "/var/www/mysite">
    allow from all
    Options +Indexes
  </Directory>
</VirtualHost>

4. Enable virtual host.

# cd /etc/apache2/sites-available
# sudo a2ensite mysite

 

Site mysite installed; run /etc/init.d/apache2 reload to enable.

# sudo /etc/init.d/apache2 reload
# sudo /etc/init.d/apache2 restart

5. You can get access to http://mysite.com/

6. If you want to disable mysite (debian specific command).

# sudo a2dissite

 



Main menu 2

Story | by Dr. Radut