How to Host a Website in Apache Web Server Ubuntu

 How to Host a Website in Apache Web Server Ubuntu

In this tutorial you are going to learn How to host a website in Apache Web Server Ubuntu.

How to install Apache Web Server in Ububtu

1. Create a folder for the website that you want to host in var/www/html

You can run the following command to go to html folder in ubuntu

cd var/www/html

2. Create site directory in html folder
for example i created a directory in html folder. To create a directory in html directory run the following command

sudo mkdir


step 1

Now create a sample page in var/www/html/ run the following command

sudo nano index.html

Copy and Pase the following code in index.html and press CTRL + X and then type Y and press Enter to save the file

        <title>Example Site</title>
        <h1>Congratulations, site successfully created</h1>

3. Host a website in apache

To host a website navigate to apache installation directory. The default installation directory is etc/apache2. Run the following command to go in the apache directory

cd etc/apache2

now navigate to the sites-avalable directory which is located in etc/apache2. Run the following command

//Run this command to go in the sites-available directory and press enter
cd sites-available
//Run this command it will list all the sites available in apache server
//Now copy default site, in my case i want to host domain
sudo cp 000-default.conf


step 2 1

4. Edit and make changes as mention below

To edit the site run the following command

sudo nano

Now replace the content of with following code

<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.
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/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
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

5. Now enable the site in apache server
To enable the site in apache run the following command

sudo a2ensite

6. Restart apache server
Run the following command to restart the apache server

sudo service apache2 restart

Add your server ip address in your domain and wait for few minutes then enter domain name in your browser



Related post

Leave a Reply

Your email address will not be published. Required fields are marked *