Installing Apache Web Server on Ubuntu is straightforward and simple to follow for anyone who is interested to make localhost on the system for development work. But before going to in details, I would like to focus on some important and basic information about Apache. This software is one of the popular web server software in the tech world. It is a free, open-source and cross-platform web server which is developed as well as maintained by Apache Software Foundation. Most Apache servers run on Linux though latest versions are compatible to run on Windows and OS/2 also. It is an overwhelmingly popular web server software. For its fastness, reliability, and security, it became so dominant in this field, and it is used on 67% of all web servers.
Using extensions and modules, Apache can be heavily customized to meet the needs of different situations. This popular web server offers powerful features and dynamic modules. Besides these, it provides robust media support and integration with other software. Now, here I am going to show you how to install Apache web server on Ubuntu Linux.
Before going to install the Apache web server, you need to have an updated Ubuntu server and a secure shell (SSH) access to the server. The user needs to log-in as a non-root user to initiate the process. The user needs to have “sudo” facilities. It is required to activate a basic firewall for blocking not essential ports.
Resources: How to Install MySQL on Ubuntu Linux
So let us start with the installation process of setting up an Apache web server in Ubuntu Linux:
In Ubuntu’s default software system Apache is available. It is possible to install it easily by using the traditional package management tools. You can update the local package and install the apache2 package by running the following.
sudo apt update sudo apt install apache2
The next process is adjusting the firewall. Firstly, check for “ufw application profiles” with the following command:
sudo ufw app list
Now it’s time to enable ufw firewall in your system and need to open the port of 80 and 443 which helps to pass the client-side request through Apache web server using both HTTP and HTTPS. Run the following command:
sudo ufw allow 80/tcp sudo ufw allow 443/tcp sudo ufw reload
Now, verify the change.
sudo ufw status
Checking the Web Server
Using the following command, it is possible to ensure that the service is running.
sudo systemctl status apache2
After that, check whether the software runs through your IP address by accessing the default Apache landing page.
https://domain_name/ OR https://SERVER_IP/
Apache Process Management
After running the web server let’s go to the management of some basic commands. For stopping your web server use the following command:
sudo systemctl stop apache2
To resume the web server from the stopped condition, type:
sudo systemctl start apache2
If you want to stop and then start the again, then type the below command.
sudo systemctl restart apache2
For simple configuration changes, without dropping connections, Apache can reload. Use the following command to execute this.
sudo systemctl reload apache2
Apache is configured by default to start automatically if the server boots. You may disable this behavior with the following command if you do not want this.
sudo systemctl disable apache2
To re-enable the service and start up at boot, use the following.
sudo systemctl enable apache2
Now, Apache should start automatically after the rebooting of the server.
Important Apache Files and Directories
After learning the management of Apache service itself, this is the time to get familiar with some important files and directories.
- /var/www/html: This directory contains the actual web content consisting of the default Apache page seen earlier. It can be changed by changing files of Apache configuration.
Server Configuration Files and Directories
- /etc/apache2: This refers to the configuration directory of Apache. It contains all Apache configuration files. It is accountable for loading other files in a place named configuration directory.
- /etc/apache2/apache2.conf: This is the main file for configuring Apache.
- /etc/apache2/ports.conf: Apache will listen on the ports, specified by this file. Apache listens on port 80 and 443 (additionally) by default when SSL capability providing module is active.
- /etc/apache2/sites-available/: It is the storing place of virtual hosts per-site. Unless the configuration files are linked to the sites-enabled directory, Apache will not use them. Usually, maximum server block configuration is performed in this directory, and with the command a2ensite, it is enabled by linking to the other directory.
- /etc/apache2/sites-enabled/: Here, enabled per-site virtual hosts are stored. Commonly, these are made by linking to available configuration files in the sites-available directory using the a2ensite. Apache analyzes the configuration files as well as available links in this directory. Then, configuration compiling starts by Apache.
- /etc/apache2/conf-available/, /etc/apache2/conf-enabled/: They are of similar relation as the sites-available and sites-enabled directories. But they are used for the configuration of fragments which are not originated in a virtual host. With the a2enconf command, files in the conf-available directory can be enabled. It can also be disabled with the a2disconf command.
- /etc/apache2/mods-available/, /etc/apache2/mods-enabled/: Available and enabled modules are kept by these directories, respectively.
- /var/log/apache2/access.log: In this log file, every request to your web server is recorded by default, unless Apache is asked to do otherwise.
- /var/log/apache2/error.log: All errors are stored here, by default. The LogLeveldirective specifies the capacity of error logs.
So, the Apache web server on Ubuntu is now installed. For more knowledge on this topic, you may do some extra research on how to install Apache web server Linux or how to install Apache web server Ubuntu. You have now experienced on different types of commands and directories used in an Apache web server to maximize web environment.