How To Setup Virtual Web Hosting And Host Multiple Sites On One Server ? [ In Two Minute ]
Learn how to setup virtual web hosting for multiple domains to be server from one single server.
Hey guys, welcome back to Intelligent computing, previously i posted HOW TO SETUP YOUR AWS AND LAMP TO RUN YOUR FIRST PHP APP? Followed by HOW TO SETUP AND CONFIGURE LAMP ON UBUNTU SERVER? And its great piece of article to setup aws and deploy php web app/site on root of apache.
But if you are having a pretty robust server and/or you planning to deploy multiple websites on single server under multiple domains, you need to step ahead and create virtual hosts in apache2 settings, which i’ll explain how you can proceed and get your new site up and running on same server in few minutes.
If you are running all application in codeigniter, you can setup all application in single codeigniter installation[ Read How i use Codeigniter to Manage Multiple Versions of app and switch in seconds?]
This procedure i am explaining is for ubuntu with apache2 so everything going to be accordingly.
Web Root : /var/www/html/
Apache2 : /etc/apache2/
Site configurations : /etc/apache2/sites-available/
Setting up sites in directory
First of all you need to make sure your website/web app resides somewhere in web root directory, suppose you’ve directory called sites
/var/www/html/sites/ |
And you have 2 sites in it with folder site1.com and site2.com
/var/www/html/sites/site1.com/ /var/www/html/sites/site2.com/ |
Pointing your domain to server
You can simply put IP address of server in your DNS setting which will start pointing your domain to server where you are about to host your websites/web app.
It might take 30 minute to 1 hour to complete this process, you can check this as follow
This will show your server’s IP address once it’s updated.
Now let’s proceed to virtual host creation.
Create virtual host configuration
- Copy /etc/apache2/sites-available/000-default.conf to /etc/apache2/sites-available/site1.com.conf
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/site1.com.conf |
- Open /etc/apache2/sites-available/site1.com.conf with your favourite editor in full admin/sudo mode and edit.
sudo vi /etc/apache2/sites-available/site1.com.conf |
- Edit file and change following lines and replace with yours configuration
ServerAdmin youremail@hostname.com DocumentRoot /var/www/html/sites/site1.com/ ErrorLog ${APACHE_LOG_DIR}/site1_error.log CustomLog ${APACHE_LOG_DIR}/site1_access.log combined |
These 4 lines are clear
● Your email address for webmaster
● Document root for your website folder
● Error log name to identify error of your site
● Access log file name to identify log for your site
You are almost done.
Enable site configuration
Now you need to enable this configuration to enable site on your machine.
For this you need to execute simple a2ensite command for your newly configured site.
sudo a2ensite site1.com.conf |
And yes you have enabled this site in your configuration, you are one command away to make your site1.com live, just restart your apache and done.
sudo service apache2 restart |
Once the command is executed successfully, your site site1.com can be accessed from web directly and you can see web pages/apps stores in /var/www/html/sites/site1.com/ directory
What’s next?
If you face any duduk kasus in saving or execution of apache, check everything once again, for any typo or similar stuff.
Also do not forget to check apache error log if any, and if you are not able to restart apache.
You might wants to know how Expert secure themselves in an amazing infographic post followed by sharing your website/web application from your localhost to anywhere on internet to show someone your work without deploying it on server.
If you find it useful, please share it to your peers on social media and follow @inteligentcomp on twitter/facebook for more updates.
0 Response to "How To Setup Virtual Web Hosting And Host Multiple Sites On One Server ? [ In Two Minute ]"
Post a Comment