Tech Corner

HOW TO INSTALL APACHE IN UBUNTU

21 Feb, 2022
image

Apache is open-source cross-platform web server software, released under the terms of Apache License 2.0. Apache is developed and maintained by an open community of developers under the auspices of the Apache Software Foundation. In this article, we will guide how to install Apache server in Ubuntu?

How to install Apache in Ubuntu?

1.) you need to install latest version of meta-package apache2.0 by running the below command.

sudo apt update
						sudo apt install apache2

Once you run these command al required package will be installed and you can check it by typing your server IP. If you will able to see the below screen on your server, it means new package were installed correctly.

\

Create a website…

Apache comes with its default site, you can edit the site contents from /var/www/HTML or you can directly edit the Apache host file which is located at /etc/apache2/sites-enabled/000-default.conf.You are able to modify apache to handle incoming requests and rub multiple websites on the same server. Let’s create a new site in Apache.

How to create a new website?

We strongly recommended that to leave the default Apache site that’s pointing to www.yourdomain.com and create a new virtual host(subsite) E.x.: klc.klcweb.com

1.) create a new folder for a new site inside var > www by running the below command. I am mentioning KLCWEB as a folder name you can give any name of the site folder. It will work

sudo mkdir /var/www/klcweb/

2.) Now, you need to create html file for testing purpose inside var > www > klcweb by using this command.

cd /var/www/klcweb/
						nano index.html

3.) You can create your own testing HTML code or you can simply copy and paste the below code.

<html>
						<head>
						  <title> Apache working </title>
						</head>
						<body>
						  <p> Hello, this is a first HMTL page to check how Apache works on Ubuntu server? </p>
						</body>
						</html>

4.) Now, we need to create virtual host configuration file to run test.klcweb.com

How to create a virtual host configuration file?

First, go to the virtual host file by following the below command.

cd /etc/apache2/sites-available/

However, Apache comes with the default site so we need to go with klc.cnf file by using this command.

sudo cp 000-default.conf klc.conf

Once you arrived at virtual host configuration file, you need to edit this file.

sudo nano klc.conf

If Apache facing error you can reach at using serveradmin’s email address “Serveradmin [email protected]

Now, Default root directly is must be to point site files are hosted on this server.

DocumentRoot /var/www/klcweb/

The default file did not come with the server name so you will have to set and find it by using the command.

ServerName klc.klcweb.com

It will help you to run the right website you have created for a testing purpose instead of running the Apache default site.

Last and final step is activate virtual host

How to activate virtual host?

After installing Apache and configure it, you have to active virtual hosting by running the below command.

sudo a2ensite klc.conf

After running this command, you might able to see the below output result.

Enabling site klc.
						To activate the new configuration, you need to run:
						  service apache2 reload
						root@ubuntu-server:/etc/apache2/sites-available#

In output screen, you can see server asks to restart the apache by hitting the displayed command.

service apache2 reload

After restating the server, browse the website in a browser.