In this section, we will see how to install and configure an Apache web server on an Ubuntu system:
- As Apache is available in Ubuntu's default software repositories, we can install it easily by using the apt installer. To install Apache and all its required dependencies, we run the following command:
- During the installation process, Apache registers itself with Ubuntu's default firewall, UFW. This provides profiles that can be used to enable or disable access to Apache through the firewall. To list the profiles, type the following command:
We can see three profiles are available for Apache. Apache refers to port 80 only, and Apache Full refers to both port 80 and 443, whereas Apache Secure refers to only port 443.
- As SSL is not configured, we will allow traffic on port 80 only for now. To do this, we run the following command:
- Now, we can verify that access has been granted for HTTP traffic by checking the status of UFW, as shown here:
- When the installation for Apache completes, Ubuntu automatically starts it. This can be confirmed by running the following command:
- Once Apache is up and running, we can enable additional modules to get extended features.
- To check the list of additional modules, see the /etc/apache2/mods-available directory.
- Suppose we want to install the MySQL Authentication module; this can be done by running the following command:
apt-get install libapache2-mod-auth-mysql
- Once installed, the module can be enabled by using the following command:
a2enmod auth_mysql
- Next, we need to restart Apache to make the changes effective:
systemctl restart apache2.service
- If we wish to encrypt the traffic sent and received by the Apache server, we can use the mod_ssl module. As this module is available in the apache2-common package, we can directly enable it by using the following command:
a2enmod ssl
- Once the SSL module has been enabled, manual configuration is needed to make SSL function properly. We have already discussed this in previous chapters.