Create apache Virtual Hosts In Ubuntu
Create apache Virtual Hosts In Ubuntu
DATE POSTED: 06/03/2019
In this post we will explain how to create the virtual hosts in ubuntu.
What is: Apache?
Apache is the most important used web server software in the world because it is an open source software. This web server developed and maintained by Apache Software Foundation.
1) Install the apache web server on your ubuntu server
$ sudo apt-get install apache2
2) Make the new directory for the new domain.
sudo mkdir -p /var/www/html/example.com
3) You can use the code for your new domain.
vi /var/www/html/example.com/index.html <html> <head> <title>example.com</title> </head> <body> <h1>Hello, This is a test page for example.com website</h1> </body> </html>
3) New configuration file for example.com domain.
sudo vi /etc/apache2/sites-available/example.com.conf <VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.example.com ServerAdmin webmaster@example.com ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/html/example.com/public_html # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost>
4) Enable virtual host configuration files.
a2ensite example.com.conf
5) Run this command and check the apache files is syntax is correct or not.
apachectl configtest
6) If made any change in the apache related configuration you need to restart apache web server to take a look upon the changes.
systemctl restart apache2
Congratulations! You have completed the virtual host setup and now be able to access your websites.
Thanks for using pheonix solutions.
You find this tutorial helpful? Share with your friends to keep it alive.