In this tutorial, we are going to see how to Install, Manage and Configure Apache on Debian10
Apache is also known as the Apache HTTP server. It is an open-source, cross-platform web server software that is free of cost. Apache mainly runs on Linux distributions, but it also ran on OpenVMS, NetWare, and other Operating systems, including ports to mainframes.
The current versions of Apache also run on Microsoft Windows and a wide variety of Unix-like systems. Apache powers around 46% of the world-wide websites. The use of Apache HTTP web server makes it easy for the website developers to server their website contents over the Internet. Apache delivers all the files requested by a user when they hit the domain name in a web browser’s address bar.
Prerequisites
Make sure that you have SSH user with sudo privileges.
Update the apt package using the $ sudo apt update
command before the installation.
Install Apache HTTP Server on Debian 10
To install the Apache HTTP server, run the following process.
Log in to the Debian 10 server as a sudo user via SSH.
Run the following command to install Apache 2 on Debian 10.
$ sudo apt install apache2
Manage Apache Service
To manage Apache 2 service, you can use the systemctl command from the command-line.
Run the following command after the Apache installation to check the status of the Apache service.
$ sudo systemctl status apache2.service
To start, enable, stop, and restart Apache 2 service, run the following commands, respectively.
$ sudo systemctl start apache2.service $ sudo systemctl enable apache2.service $ sudo systemctl stop apache2.service $ sudo systemctl restart apache2.service
Test Apache Installation
To check the installed version details, run the following command.
$ sudo apache2 -v
This above command should get an output similar to the one shown below.
$ sudo apache2 -v Server version: Apache/2.4.41 (Debian) Server built: 2019-12-14T19:53:42
Now, you can access the Apache HTTP server by using your domain name or IP address. When you hit the domain name or your server’s IP address from a web browser, it should open a default Apache page on the browser. If this page is displayed in the browser when we hit the below URL, then Apache 2 is installed successfully on your Debian server.
http://<domain_name> or http://<Server_IP_address>
Configure Firewall Settings
First, we need to allow specific web ports on your system and then allow Apache on your UFW firewall. To configure Apache on your server, follow the below steps.
First, list all the UFW application profiles by running the following command.
$ sudo ufw app list
Next, we need to allow Apache on UFW by running the following command.
$ sudo ufw allow ‘Apache’
After allowing Apache, run the following command to check the status of UFW.
$ sudo ufw status
Create Virtual Hosts
Now let’s configure Apache. To create the first Virtual host on port 80 of your Apache server, follow the below steps.
Create a sample index file in the /var/www/<domain_name> directory.
$ sudo mkdir -p /var/www/<domain_name> $ sudo echo “hello <domain_name>” > /var/www/<domain_name>/index.html
For example, if your domain is test123.com, then run the following command.
$ sudo mkdir -p /var/www/test123.com $ sudo echo “hello test123.com” > /var/www/test123.com/index.html
Now, create the virtual host configuration file.
$ sudo vim /etc/apache2/sites-available/<domain_name>.conf
For example, If the domain is test123.com, then run the following command.
$ sudo vim /etc/apache2/ sites-available/test123.com.conf
Add the following content in the above-created configuration file. Replace test123.com with on your server domain name.
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot /var/www/test123.com ServerName test123.com ServerAlias www.test123.com <Directory /var/www/test123.com> #Allowoverride all ###Uncomment if required </Directory> ErrorLog ${APACHE_LOG_DIR}/test123.com_error.log CustomLog ${APACHE_LOG_DIR}/test123.com_access.log combined </VirtualHost>
Save and close the configuration file.
Enable virtual host by running the following command.
$ sudo a2ensite <domain_name>
For example,
$ sudo a2ensite test123.com
Then, reload the Apache server by running the following command.
$ sudo systemctl reload apache2.service
Configure SSL Virtual Host
If you don’t want to configure SSL on your server, then you can skip this step. But we recommend configuring SSL because security is always the first concert of a website. By default, Apache listens to HTTPS ports 443, and the Apache SSL module is disabled. Make sure that other services are not using the same HTTPS port and then run the following command to enable the Apache SSL module.
$ sudo a2enmod ssl
Next, create an SSL Virtual host file by running the following command.
$ sudo vim /etc/apache2/sites-available/<domain_name>_ssl.conf
For example,
$ sudo vim /etc/apache2/sites-available/test123.com_ssl.conf
Then, add the following content into the above-created file. In the following contents, replace test123.com with your domain name.
<VirtualHost *:443> ServerAdmin [email protected] DocumentRoot /var/www/test123.com ServerName test123.com ServerAlias www.test123.com <Directory /var/www/test123.com> #Allowoverride all ###Uncomment if required </Directory> SSLEngine on SSLCertificateFile /etc/pki/tls/certs/test123.com.crt SSLCertificateKeyFile /etc/pki/tls/certs/test123.com.key ErrorLog ${APACHE_LOG_DIR}/test123.com_ssl-error.log CustomLog ${APACHE_LOG_DIR}/test123.com_ssl-access.log combined </VirtualHost>
The following three terms used in the above file are to configure the SSL virtual host.
- SSLEngine – Set this value as “on” to enable SSL.
- SSLCertificateFile – In this term, set the SSL certificate path.
- SSLCertificateKeyFile – In this term, mention the private key files used to generate an SSL certificate.
Now, save and close the above file after that enable the SSL virtual host by using the following command.
$ sudo a2ensite <domain_name>_ssl
For example,
$ sudo a2ensite test123.com_ssl
To reflect all the changes made, reload the Apache 2 server by using the following command.
$ sudo systemctl reload apache2.service
So this is how you Install, Manage and Configure Apache on Debian10.
Please comment below for any questions or queries. If you are an InterServer customer, please reach out to our support team for further help.