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:


 apt install apache2

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

To restart Apache 2, run:


 sudo service apache2 restart

Enter fullscreen mode Exit fullscreen mode

To stop Apache 2, run:


 sudo service apache2 stop

Enter fullscreen mode Exit fullscreen mode

To gracefully reload Apache 2, run:


 sudo service apache2 reload

Enter fullscreen mode Exit fullscreen mode

After starting the Apache Web Server, you may go into any browser and type http://127.0.0.1/ 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.



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

1 directory, 2 files


Enter fullscreen mode Exit fullscreen mode

Inside index.html :



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


Enter fullscreen mode Exit fullscreen mode

And inside css/style.css:



body{
    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

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

And type http://127.0.0.1/darkweb/ 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 http://127.0.0.1/YOUR_PROJECT_NAME/.

After hosting on Apache, the website looks like:

result

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)