In this tutorial, we learn About how to install apache in ubuntu 20.4 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
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
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.
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.
/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.
Verify That The Apache Service Is Running:
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’
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.
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
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
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
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.
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
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
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.
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
Tutorials Ubuntu install and configure how to install apache in ubuntu 20.4 Step By steps hop that now you are comfortable with apache web server installation and configuration If you have any doubt related this article you can comment in the comment box , i will try to solve your problem .