Apache is the most preferred and popular open source web server. Most of the websites run with Apache platform. You can configure Apache in almost all the Linux variants including Ubuntu, RHEL, and Fedora. The configuration of Apache is not too much difficult. In this tutorial, we are going to explain how to configure Apache in Ubuntu Linux. We are using the latest version of Ubuntu that is Ubuntu 17.04. However, the same steps can also be used to configure Apache in earlier versions of Ubuntu such Ubuntu 14.04 and Ubuntu 16.04. For other Linux variants, you may need to adjust some of the steps mentioned in this tutorial but the basic concept would remain same for all the Linux variants.
- Configure DNS in Ubuntu 17.04
- Configuring LAMP in AWS Cloud using Ubuntu
- Configure Samba in Ubuntu Linux
In order to configure Apache in Ubuntu 17.04, you need to perform the following tasks:
- Updating packages and upgrading system
- Installing Apache packages
- Configuring Apache Web server
- Testing Apache configuration
1. Updating Ubuntu Linux Packages
It is always the best practice to keep your system updated. In Ubuntu Linux, you can use the following command to update the packages and upgrade the entire system.
sudo apt update -y sudo apt dist-upgrade -y
2.Installing Apache in Ubuntu Linux
Once the system packages are upgraded, install the Apache package using the following command.
sudo apt install apache2 -y
3.Configuring Apache in Ubuntu Linux
In order to configure Apache in Linux, you need to set the configuration options in the apache configuration file (/etc/apache/apache2.conf). In this file, there are various options that you can set as per the requirements. For this demonstration, let’s change the web server name from default to www.myserver.com. For this, add the following line in the Global Configuration section.
sudo vi /etc/apache/apache2.conf ServerName www.myserver.com
3.1.Testing Apache Config File Syntax
Sometimes, you may modify something unexpected unintentionally in this file. So, it is always recommended to check the syntax of configuration file before to proceed. To test the apache config file syntax, use the apachectl command. The output should be Syntax OK as shown in the following figure.
3.2.Enabling and Starting Apache Service
Once you are done with your desired modification, restart and enable the Apache service using the following commands:
sudo systemctl restart apache2 sudo systemctl enable apache2 sudo systemctl status apache2
We assume that you have already set the hosts configuration file. So you can access your web server with hostname along with IP address. If not, you need to add the following line in the /etc/hosts file.
Note: For the production network, you may need to register the DNS name of your web server. Alternatively, you can also configure your own DNS server in Ubuntu.
Now, verify that your server is reachable using hostname as shown in the following figure.
4.Testing Apache Server Configuration
Now you have set all the apache configuration as per your requirement. Open the browser and test that your Apache server is working fine as shown in the following figure.
That’s all you need to configure Apache in Ubuntu Linux. We would like to hear you if you have any further query or suggestions. In this tutorial, we have explained how to configure Apache Web Server in Ubuntu Linux.
However, here anyone can access your web server without restriction because we have not implemented any kind of web security. In some scenarios, you may need to set the user-based authentication to access Apache web server. This can be done by setting up the Password Authentication with Apache. Read out the below article to set the password authentication for your Apache web server.