EC2 -To install multiple sites on ubuntu web server

$EC2 -To install multiple sites on ubuntu web server


Hosting multiple domains from one IP address using Apache
Creating virtual hosts in Apache makes it possible to host multiple websites from a single IP address.
My old netbook has discovered new life as a Linux home server. A combination of name-based virtual hosting in Apache + Debian squeeze allows me to host multiple websites running behind a single static IP address I obtained from my ISP.
This is my setup ...
Step 0 - Install Apache
$ sudo apt-get install apache2
$ /etc/init.d/apache2 start

Confirm the web server is up-and-running by navigating to localhost ... You should now see:
It works!

This is the default web page for this server.

The web server software is running but no content has been added, yet.

Apache's default page is located at /var/www/index.html. Enabling Apache to host multiple domains requires giving each website:

* its own directory to hold files
* a virtual host configuration

Step 1 - Website directoryCreate a directory for the website and grant ownership to USERNAME ...
$ sudo mkdir /var/www/aashishmittal
$ sudo chown USERNAME:USERNAME /var/www/aashishmittal

Step 2 - Virtual hostCreate a new virtual host configuration for the website by copying Apache's default configuration to the new sitename ...
$ sudo cd /etc/apache2/sites-available/
$ sudo cp 000-default.conf aashishmittal.conf

Edit the newly-created configuration to match the new website settings ...
<VirtualHost *:80>
ServerName www.aashishmittal.com
    ServerAlias *.aashishmittal.com
    ServerAdmin admin@aashishmittal.com

    DocumentRoot /var/www/aashishmittal
    ...

create log folder inside aashishmittal

ErrorLog /var/www/aashishmittal/log/error.log
     CustomLog /var/www/aashishmittal/log/access.log combined

....

Enable the new site in Apache ...
$ sudo a2ensite SITENAME
$ sudo  service apache2 reload

If you want to be able to view the website on the same localhost it is being served from ... modify /etc/hosts by adding a testing domain to the localhost address ...
127.0.1.1       test.*sitename*

... and another ... and another ...
Copy the steps for each additional website ... giving each site a unique name and virtual host configuration.
Step 3 - Extra: Web-enabled user directoryCreate a folder in a user's home directory with contents made available over the web ...
$ mkdir /home/USERNAME/public_html

Configure Apache to allow outside access to the folder by editing /etc/apache2/mods-available/userdir.conf ...
<IfModule mod_userdir.c>
UserDir public_html
UserDir disabled root
UserDir enabled USERNAME

Enable the userdir module and reload Apache ...
$ sudo a2enmod userdir
$ sudo /etc/init.d/apache2 restart


Navigate to http://localhost/~USERNAME_ to view the contents of /home/USERNAME/public_html ... Outside your LAN a user would travel to http://YOUR_IP_ADDRESS/~USERNAME.

Imporatant Links

http://manpages.ubuntu.com/manpages/trusty/man8/a2ensite.8.html

Reactions: