Friday, December 7, 2018

How to Setup Virtual Host in Ubuntu 14.04/16.04 Using Apache

Hi there! Here is another tutorial in setting up virtual hosting. It means hosting several websites in one hosting. This is applicable if you have ssh and root control over your hosting instance.

Let's say you want to host and in just one hosting. All you have to do is follow the instructions below.

You will need to install LAMP first in your instance. LAMP stands for Linux, Apache, Mysql and PHP. And also I will include installation of PHPMyadmin since I have a hard time looking for means on how to make phpmyadmin on the instance on my first setup. Here is the link on How to Install LAMP in Ubuntu 14.04 and 16.04.

Step 1: Create your directory
sudo mkdir -p /var/www/website1

Step 2: Change ownership from root which is the default to ordinary user.
sudo chown -R $USER:$USER /var/www/website1

Step 3: Modify permissions to ensure read access to the general public.
sudo chmod -R 755 /var/www

Step 4: Copy the default configuration 
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/website1.conf

Step 5: Modify default contents of your conf file. I've been using nano as my text editor and I found it easier compare to others.
sudo nano /etc/apache2/sites-available/website1.conf

Add below config above your DocumentRoot config

DocumentRoot /var/www/website1

CTRL + O to save
CTRL + X and then press y to save the file

Step 6: Enable virtual hosting for the website in apache
sudo a2ensite website1.conf

Step 7: Restart Apache service to apply changes
sudo systemctl restart apache2
for 16.04

sudo service apache2 restart
for 14.04

Step 8: Upload your files in /var/www/website1 using FTP or SFTP or File Manager.
Step 9: Point your domain to the IP address of your hosting site.

There you go! Good luck!

How to Setup Virtual Host in Ubuntu 14.04/16.04 Using Apache

No comments:

Post a Comment