DEV Community

Arjun Adhikari
Arjun Adhikari

Posted on

Locally Host Website using Apache2 Ubuntu Server

Hello geeks, In this tutorial I'm guiding you how to host a simple website locally in Apache Web Server in Linux. So, let's get started.

Install Apache

First, let's install Apache from the apt repository in Linux. Enter the following command on your terminal to install the Apache web server:

sudo apt install apache2

After successful installation, here are some commands that may come handy while running Apache web server.

To start Apache 2, run:

$ sudo service apache2 start

To restart Apache 2, run:

$ sudo service apache2 restart

To stop Apache 2, run:

$ sudo service apache2 stop

To gracefully reload Apache 2, run:

$ sudo service apache2 reload

After starting the Apache Web Server, you may go into any browser and type on Address Bar.
The resulting web page looks like:

Apache2 Start

The web page rendered is the default web page provided by the Apache itself. Now, we'll learn to replace by our website.

Create Website

For maintaining the simplicity, I'm creating a simple web project darkweb with the following file structure.

├── css
│   └── style.css
└── index.html

1 directory, 2 files
Enter fullscreen mode Exit fullscreen mode

Inside index.html :

<!DOCTYPE  html>
<html  lang="en">
    <title>Website on Dark Web</title>
    <link  rel="stylesheet"  href="./css/style.css">
    <h1>This is my first web site on Dark Web.</h1>
Enter fullscreen mode Exit fullscreen mode

And inside css/style.css:

    margin: 0px;
    color: red;
    background-color: darkslateblue;
Enter fullscreen mode Exit fullscreen mode

which results to form a webpage like :

Sample Website

Host Website on Apache Web Server

Going through the default configuration provided by the Apache, we're going to add website we just created to the Apache web server.

Assuming our web project name is darkweb, let's move the project to /var/www/html.

$ sudo mv darkweb/ /var/www/html

Now, we've hosted our website on Apache Web Server. To access the website from the Apache, first start the Apache Web Server:

$ sudo service apache2 start

And type on address bar on your browser. Now, you should see the website we just created on the browser. Here, my project name was darkweb, but the generalized URL for accessing your project is

After hosting on Apache, the website looks like:


I hope that now you're able to host website on Apache web server.

In next tutorial of this series, I'll be guiding you through how to install SSL certificate on Apache2 Ubuntu Server.

Till then, keep coding :)

Top comments (0)