How To Install And Configure Apache Web Server In Ubuntu 20.04

How to Install And Configure Apache web Server in Ubuntu 20.04

In this tutorial, we learn About How to Install And Configure apache in Ubuntu 20.04 and other Ubuntu Version. Apache HTTP is an open-source(which means it can be used and modified freely.) web server that’s available for Linux and other Linux distributions, it is free of charge it is so powerful and flexible is that its design allows extensions through modules. Apache comes with many modules by default and automatically.

Update system repositories:

Update the system repository before installing Apache packages. Because due to system updates, sometimes occurred dependencies package issues and confidant we are working with the latest packages

root@simitech:~# apt-get update && upgrade -y

Install Apache2 package In Ubuntu 20.04

Enter the below command to Install Apache2 package with the help of apt command.

root@simitech:~# apt install apache2 -y

Install  Apache2 package on Ubuntu20.04

When the installation is completed, check the Apache version number by entering the following command.

root@simitech:~# apache2 -version

Apache Configuration File:

simi@simtech:$ vim /etc/mods-enabled/dir.conf

Apache2 Configuration File on Ubuntu20.04

Open Apache2 configuration File:

this is the main Apache configuration file, Changes here affect all the websites hosted on this machine. open the Apache configuration file and go to near line number 70 and Change your server name According to your server name.

Open  Apache2 main configuration File in Ubuntu 20

save and exit from Apache configuration file and start services

Check Apache Configuration Syntax:

To check Apache’s configuration file, by executing the below command, it can be found that there is an error in the configuration file.

check Apache's configuration file syntax

/var/log/apache/ : Store All Apache related Error logs (error and access logs).

Start Apache2 Service

start and check Apache HTTP Services to check service status Execute below command.

start and check Apache HTTP Services

Verify That The Apache Service Is Running:

Verify That The Apache2 Service Is Running in Ubuntu 20.04

Allow Apache on UFW And Verify Its Status:

If firewall service is running in your system, Configure the default UFW firewall to allow traffic on port 80.

root@simitech:~# ufw allow ‘apache’

UFW firewall to allow traffic on port 80 in Ubuntu 20.04

Apache2 ubuntu Defaults page:

To check whether the Apache server is working properly OR not. Open the web browser and type the Apache server hostname or IP address in the Address bar.

Apache2 ubuntu Defaults page

Configure Virtual Hosting In Apache

/etc/apache2/sites-available: storage Apache Virtual host configuration file. The configuration file of all virtual hosts that will be created is stored here

Configure Virtual Hosting In Apache2 on Ubuntu20

a2ensite: a2ensite is a script that enable specified site under /etc/apache2 /site-available. creating a symlink from /etc/apache2/sites-enable to /etc/apche/sites-available

a2ensite is a script that enable specified site

first Create a directory virtual.host in Apache Document root location /var/www/ Create index.html file in the virtual host directory That you access from the web browser

root@simitech:~# mkdir /var/www/virtual.host

Create index.html file for apache virtual host test page

Let us now create an index.html file that we can access later from Browser

now create an index.html file in Ubuntu 20.04 Document Root Location

Start Apache services to update configuration

root@simitech:~# systemctl restart apache2.service

To check whether the virtual hosting is working properly OR not. Open the web browser and type www.simi.host.

Check virtual hosting test page on Ubuntu20.04

Uninstall Apache2 from ubuntu system:

If Apache service is running in your system, then first stop the service of Apache, then you can remove the Apache package from your system.

root@simitech:~# systemctl stop apache

Uninstall Apache2 from ubuntu system:

OR

root@simitech:~# sudo apt-get purge apache2*

Install Apache PHP on Ubuntu 20.04

Configure Apache2 to use PHP Scripts. First, install PHP related packages in your System

root@simitech:~#apt install php php-cgi libapache2-mod-php php-common php-pear php-mbstring

Install Apache PHP on Ubuntu 20.04
Install Apache PHP  Modules on Ubuntu 20.04

open the php.ini file, go to near line number 962, uncomment date. timezone and edit Asia/Kolkata. follow the below screen.

simi@simitech:~# vim /etc/php/7.4/apache2/php.ini

date.timezone = Asia/Kolkata”

go to apache Document root location /var/www/html/ and Create file name phpinfo.php Open the file and write ‘<?php phpinfo();‘ in it and save exit from file.

Create file name phpinfo.php Open

Restart Apache services to update the configuration.

root@simitech:~# systemctl restart apache2

To check whether the file is in working, open the browser from any system (the computer must be connected to the Apache server) Type the http://System-IP_Address/phpinfo.php OR http://hostName/phpinfo.php as given below. to the check the IP of the system execute the below command

simi@simitech:~#ip addr show

Check PHP Modules from Web Browser in Ubuntu20.04

Conclusion

Tutorials ubuntu install and configure Apache Web Server In Ubuntu 20.04 Step By steps hope that now you are comfortable with windows 10 installation If your problem is still not solved share your Problem via comments.

Related Posts