Category: Ubuntu

Added: 26th of June 2022

Viewed: 288 times

Install Apache2 on Ubuntu and Ubuntu based distributions in 2022

This is a basic guide to installing Apache2 on Ubuntu and Ubuntu based distributions

Install Apache2 by entering the following command

sudo apt-get install apache2


Once installed enter localhost or 127.0.0.1 in the address of your web browser. You will now see the Apache holding page.



Create a new folder in the /var/www/ directory named mysite
sudo mkdir /var/www/mysite


Create an index.html file in the mysite folder
sudo touch /var/www/mysite/index.html


Next we need to open the index.html file in nano and add some basic html code.
sudo nano /var/www/mysite/index.html


Copy and paste the code below
<!DOCTYPE html>
<html>
<body>
<h1>Apache 2 successfully installed</h1>
<p>Welcome to mysite</p>
</body>
</html> 




To save the index.html file in nano, do the following
Press CTRL +O to write to file, press enter to confirm
Press CTRL +X to exit nano


Next we need to take ownership of the folder and files in the mysite folder.
If you run the ls -l command you will see that root has ownership of the folder and file
ls -l /var/www/mysite

drwxr-xr-x 2 root root 4096 Jun 25 14:03 mysite


Enter the following command to change ownership to your username. Replace username with your real username
sudo chown -R username:username /var/www/mysite/


Run the ls -l command again
ls -l /var/www/mysite

drwxr-xr-x 2 username username 4096 Jun 25 14:03 mysite


Next change the permissions of the folder and file to enable read, write
sudo chmod -R 755 /var/www/mysite/


So that apache2 points to your new mysite folder, we need to copy the 000-default.conf file

The main 000-default.conf file is located in the following directory /etc/apache2/sites-available/ so cd to that directory using the command below
cd /etc/apache2/sites-available/


Copy the 000-default.conf file using the cp command and create a new .conf file named mysite.conf
sudo cp 000-default.conf mysite.conf


Open and edit the mysite.conf file using nano
sudo nano mysite.conf


Locate the line
DocumentRoot /var/www/html
Change this to
DocumentRoot /var/www/mysite




To save the configuration file in nano, do the following
Press CTRL +O to write to file, press enter to confirm
Press CTRL +X to exit nano


Next we need to enable the mysite.conf file

We first need to disable the 000-default.conf using the ad2dissite command
sudo a2dissite 000-default.conf


Then we need to enable the mysite.conf file using the a2ensite command
sudo a2ensite mysite.conf


Next we need to restart apache2 using the following command
sudo systemctl reload apache2


Enter localhost or 127.0.0.1 in the address of your webrowser. You will now see your Apache holding page.

Other Tips & Tutorials

Ubuntu

Install Apache2 on Ubuntu and Ubuntu based distributions in 2022

Posted: 26th of June 2022

Views: 288

Ubuntu

How do I upgrade a single package in Ubuntu and Ubuntu based distributions

Posted: 12th of September 2021

Views: 1078

Ubuntu

Create a multiboot USB for your .iso images, using Ventoy on Linux

Posted: 25th of August 2021

Views: 1294

Ubuntu

How to find out what date you installed Linux on your machine

Posted: 13th of April 2021

Views: 1298

Ubuntu

Install bashtop in Ubuntu and Ubuntu based distributions. Monitor your cpu, memory, disks, network and other processes

Posted: 21st of February 2021

Views: 1356

Ubuntu

Ubuntu 20.10 Groovy Gorilla installation error, installer crashed

Posted: 3rd of February 2021

Views: 1918

Ubuntu

Find out what version of Ubuntu you are running, using the terminal

Posted: 29th of January 2021

Views: 1236

Ubuntu

Install Redshift to automatically adjust the colour of your screen depending on time of day on Ubuntu and Ubuntu based distributions

Posted: 26th of November 2020

Views: 2072

Ubuntu

PulseAudio, Pavucontrol not saving settings after reboot on Ubuntu and Ubuntu based distributions

Posted: 11th of November 2020

Views: 6224

Ubuntu

No sound after installation of Ubuntu or Ubuntu based distribution, install pavucontrol

Posted: 9th of November 2020

Views: 1373