Apache Server Basic Configuration

Please find below a guide to configure Apache server on Ubuntu.

You can access the main Apache page at https://httpd.apache.org/ for further information and support.
To begin, add the Apache repository by running the following command:
sudo add-apt-repository ppa:ondrej/apache2

Next, install Apache using the following command:
sudo apt install apache2

Once installation is complete, check the version using the following command:
apache2 -v

Default Site

Please note the following information regarding the default site directory and available files:
The directory containing files with information on available sites is located at
/etc/apache2/sites-available/.
By default, this directory only includes two files, namely 000-default.conf and default-ssl.conf.

On the other hand, the directory that contains files for enabled sites is located at
/etc/apache2/sites-enabled.
By default, this directory only includes a single file, 000-default.conf.
This is considered the main site and operates on port 80 by default.

Configure Self Sign SSL on Apache.

Please follow the steps below:
Run the following command to generate a private key and a certificate signing request:

sudo openssl req -nodes -newkey rsa:2048 -keyout /etc/ssl/private/private.key -out /etc/ssl/private/request.csr -subj “/C=CA/ST=ON/L=Ottawa/O=2tech/OU=IT/CN=2tech-Monitoring”

Use the certificate signing request to generate a self-signed SSL certificate:
sudo openssl x509 -in /etc/ssl/private/request.csr -out /etc/ssl/private/certificate.crt -req -signkey /etc/ssl/private/private.key -days 1825

Open the default-ssl.conf file:
sudo nano /etc/apache2/sites-available/default-ssl.conf

Change the SSLCertificateFile and SSLCertificateKeyFile paths to point to the files created in the previous steps:

<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin admin@example.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/private/certificate.crt
SSLCertificateKeyFile /etc/ssl/private/private.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
</IfModule>

Enable and configure the SSL site by running the following commands:
sudo a2ensite default-ssl.conf # Enable SSL Site
sudo a2enmod SSL # Enable SSL mode on apache
sudo a2enmod headers # Enable Headers mode
sudo systemctl reload apache2 # Reload Apache configuration

After completing these steps, self-signed SSL will be enabled for all sites on Apache.

Enable additional listening ports

Follow these steps to configure the default server to listen on ports 1433 and 1521.
Firstly, create the following configuration files:
sudo nano /etc/apache2/sites-available/1433.conf

<VirtualHost *:1433>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
</VirtualHost>

sudo nano /etc/apache2/sites-available/1521.conf
<VirtualHost *:1521>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
</VirtualHost>

Now, enable the new configuration files using the following commands:

sudo a2ensite 1433
sudo a2ensite 1521
sudo systemctl reload apache2

Finally, you can access your website using the following URL formats:

http://IP:80
http://IP:1433
http://IP:1521

Note that “IP” should be replaced with your server’s IP address. With these steps, your website is now accessible on three different ports.