Apache HTTP — The HTTP Server | Installation and Configuration on Debian and Ubuntu Server

Muhammad Abdul Royyaq
3 min readAug 21, 2022

--

The World Wide Web Server — The article you are reading right now is the World Wide Web or commonly known as the Web.
The web allows hypermedia and other web resources to be accessed over the Internet. Web uses Hypertext Transfer Protocol or commonly called HTTP. HTTP is the data communication basis for the World Wide Web. So what is Apache HTTP?, Apache HTTP is one of the software that can provide the web with the HTTP protocol.

Installation

Before installation, make sure the system is updated and has user privileges.

Installing Apache

apt install apache2

Configuration

The configuration file is in the /etc/apache2/ directory, and the main configuration file is /etc/apache2/apache2.conf

Before reaching the configuration file, please note that Apache HTTP has configuration templates, stored in /etc/apache2/mods-available and /etc/apache2/sites-available, mods-available is the template for modules and sites-available is the sites configuration template.

By default web services run on http but not on https; for example, we will run a web service on http and https.

In configuring we won’t touch the main configuration, we will tweak the configuration file in the /etc/apache2/sites-enabled/ directory.

Copying https site template

cp /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-enabled/

Enabling the SSL module

a2enmod ssl

Default snakeoil certificate. Also, you can change using generated self-signed SSL certificate or valid signed SSL certificate.

apt install openssl ssl-cert

Generate self-signed SSL certificate, for example, we will generate self-signed SSL certificate will valid in 365 days with 4096-bit RSA key and will stored with self-signed name.

openssl req -x509 -nodes -days 365 -newkey rsa:4096 -keyout /etc/ssl/private/self-signed.key -out /etc/ssl/certs/self-signed.crt

Configure to use self-signed SSL certificate

nano /etc/apache2/sites-enabled/default-ssl.conf

Example

  SSLCertificateFile /etc/ssl/certs/self-signed.crt
SSLCertificateKeyFile /etc/ssl/private/self-signed.key

Running on specific multiple hostname and port, for example, we will run http in custom hostname and port 8080; also you can do it with https.

Configuring VirtualHost

nano /etc/apache2/sites-enabled/000-default.conf

For example, we use sxs3c.org as hostname and change the server root directory to /var/www/sxs3c.org/

<VirtualHost *:8080>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName sxs3c.org
ServerAdmin webmaster@sxs3c.org
DocumentRoot /var/www/sxs3c.org
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

Web Programming Application

For example, we will install a PHP module.

Installing PHP and modules

apt install php libapache2-mod-php

Enable PHP module

a2enmod php

Restart Apache service

service apache2 restart

Testing

Test the result, for example, we will test the PHP modules.

To test the PHP module create this file in server directory, for example in /var/www/sxs3c.org/ directory.

echo "<?php
phpinfo();
?>" > /var/www/sxs3c.org/info.php

Access web server in browser with server IP address or hostname /info.php.

--

--