Linux Linux help


Apache Server

1. How to install Apache Server?

In Linux Mint you can install Apache HTTP (Web Server) in two ways:

a) Administration, Software Manager. Type in 'apache' in the search box and select Apache2 (Apache http server) from the list.

b) From the command line, enter the following commands.

$ sudo apt-get update

$ sudo apt-get install apache2

It will install the following components: apache2-doc, apache2-bin, apache2-data, apache2-utils, libapr1, libarprutil1, libaprutil1-dbd-sqlite3, libaprutil1-ldap.
The main tool to control apache server is apachectl (apache control).

2. How do I install additional libraries and utilities?

Apache will work by default with plain HTML web pages but if you need scripting with PHP, Python or Perl etc then you need to install additional tools and libraries.

a) PHP support.

To install php for apache, run apt-get install php. This will also install apache along with these components: libapache2-mod-php7.4 and php7.4. The module will allow
php scripts to run within a apache website.

To enable PHP, you need to enable the php7 module and load the module in the main apache configuation and restart apache service:
$ sudo a2enmod php7
$ sudo vi /etc/apache2/httpd.conf

Uncomment the follow line:
#LoadModule php7_module /usr/lib/mods-available/
Save the file
$ sudo apachectl reload

b) Python support.

To install python3, run apt-get install python3. This will install the following components: python3-minimal, python3.8, libpython3-stdlib, python3-doc, python3-tk, python3-venv,

To install python packages you will need the Pip, a python package manager which allows to install packages by name. Run apt-get install python3-pip.

To enable Python for Apache, you need to disable multireading processes and five permission to run scripts:
$ sudo a2dismod mpm_event
$ sudo a2enmod mpm_prefork cgi

c) Perl support.

Apache also supports Perl. To install perl, run apt-get install perl. Then you need to enable the CGID module for it to work with Apache:

$ sudo a2enmod cgid
$ sudo apachectl reload

Create a test file in /usr/lib/cgi-bin called test:

print "Content-Type: text/html\n\n";
print ("<h1>Perl is working!</h1>");

and enable execution bit with chmod 755 /usr/lib/cgi-bin/ and you can test it by browsing to http://ip-address/cgi-bin/

3. How do I configure a web site in Apache?

To configure a website you need to create a configuration file, also known as a vhost (virtual host) file with special directives for the website, usually located in /etc/apache2/sites-available folder.
For example, the following configuration defines site to use HTTP (Port 80), web location is located in /var/www/test (default is /var/www/html),
Enable executable CGI, set the startup file as index.for the test site, enable handler for cgi scripts and python scripts (end with .py) and set document root
for /var/www/test.


<VirtualHost *:80>

<Directory /var/www/test>

Options +ExecCGI


AddHandler cgi-script .py

DocumentRoot /var/www/test


Once a configuration is created and save, you can enable the vhost by creating a link to the configuration file in sites-available to the sites-enabled folder:

$ sudo ln -s /etc/apache2/sites-available/001-mywebsite-vhost.conf /etc/apache2/sites-enabled/001-mywebsite-vhost.conf

$ sudo apachectl configtest # Test to see configuration is valid, use -t as instead of configtest.

$ sudo apachectl graceful # Reload apache without affecting existing sessions.

Now test the site by loading a web browser and enter http://localhost, http://ip-address or http://website-address (if configured in DNS or /etc/hosts).