In this post i am going to explain how to setup virtual host on your Cloud server. Most of developer prefer to use cloud server because you are free to do whatever you like test lots of thing scale your mobile and web application, dedicated IP’s and most important for every startup its cost very less like 5$/per month. In my last posts i explain how to set apache on server now in this post we are going to add domain to our VPS.
Set Up Apache Virtual Hosts
Step 1. Login to your server using terminal or putty.
Step 2. Create directory inside var/www/html/mydomain.com
Step 3. Now we need to give permission to our directory, so run below command in terminal
sudo chown -R $USER:$USER /var/www/html/mydomain.com
we also make sure we are able to read and edit file so we can give permission using this command
sudo chmod -R 755 /var/www/html
Step 4. Create index.html page inside /var/www/html/mydomain.com/index.html which is our landing page.
Step 5. Create virtual host file by copying default virtual file
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/mydomain.com.conf
Step 6. Now we need to edit copied config file and define some parameter in it
to open and edit this
sudo nano /etc/apache2/sites-available/mydomain.com.conf
file type below command
<VirtualHost *:80> <Directory /var/www/html> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> # These line which we add to config ServerAdmin anehkumar@gmail.com ServerName mydomain.com ServerAlias www.mydomain.com DocumentRoot /var/www/html/mydomain.com ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
After adding server details and location of site we need to enable virtual host file using this command
sudo a2ensite mydomain.com.conf
After running this we need to restart or server and go to browser and type your website url in address bar to check
sudo service apache2 restart
If you follow every step then you see your website page live 🙂 .