Install and enable Apache modules on debian / ubuntu
Install and enable Apache modules
In order for Apache to handle different situation or certain settings the user requires, certain modules are required to be installed and enabled. Usually Apache comes with most of the modules you require to work with installed, however there are certain cases where you need these modules to install first in order to be used. In such cases you would need to first install and enable Apache modules on your system in order to use them. In this article I’m going to show you how you can easily install and enable Apache modules step by step, the manual compile option would be interesting so do read below.
Install and enable Apache modules on Debian / Ubuntu
Debian and Ubuntu are kind enough to provide us with the default modules we need directly in their repository, however there are certain cases when you need to install the modules manually. We’ll get to that part a bit later.
To install the apache modules on Debian or Ubuntu directly from repository, you need to use the below commands:
1 |
apt-get install libapache2-mod-php5 |
you will see an output similar to bellow:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
The following NEW packages will be installed: libapache2-mod-php5 0 upgraded, 1 newly installed, 0 to remove and 8 not upgraded. Need to get 3,136 kB of archives. After this operation, 8,718 kB of additional disk space will be used. Get:1 http://ro.archive.ubuntu.com/ubuntu/ precise-updates/main libapache2-mod-php5 amd64 5.3.10-1ubuntu3.8 [3,136 kB] Fetched 3,136 kB in 1s (2,932 kB/s) Selecting previously unselected package libapache2-mod-php5. (Reading database ... 787966 files and directories currently installed.) Unpacking libapache2-mod-php5 (from .../libapache2-mod-php5_5.3.10-1ubuntu3.8_amd64.deb) ... Setting up libapache2-mod-php5 (5.3.10-1ubuntu3.8) ... Creating config file /etc/php5/apache2/php.ini with new version * Restarting web server apache2 |
After apache has been restarted, you will be able to start using that module.
Enable or disable apache module
In case you want to disable or enable a module you can run the bellow command:
- Enable apache module
1 2 3 |
~# a2enmod php5 To activate the new configuration, you need to run: service apache2 restart |
- Disable apache module
1 2 3 |
~# a2dismod php5 To activate the new configuration, you need to run: service apache2 restart |
The process is easy, you just call the enable or disable command along with the apache module and finally restart your web server and you are done. Of course you need to be root to be able to execute the commands, you can use sudo in case you are not root.
Compiling Apache module
This process is a bit different and depends on each case or specific apache module. If you need a specific module to be compiled, please comment below and I’ll try to help out. For now, I’ll go with one specific module that exists in debian repository, but we will install it and enable it manually just to see how this process goes.
So for instance, we have the below commands to download and compile the RPAF module for reverse proxy:
1 2 3 4 5 6 7 8 9 10 11 |
# Install required package for compiling apt-get install apache2-dev # Download the rpaf module source file cd /usr/local/src/ wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz tar -xvf mod_rpaf-0.6.tar.gz cd mod_rpaf-0.6 # Compile the module apxs2 -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c |
As you can see below, we are using apxs2 to compile the apache module.
Next we need to create a configuration file for this module and enable the module and setup some basic settings. So create the file
/etc/apache2/conf.d/rpaf.conf
Then edit this file and add the following settings:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
LoadModule rpaf_module /usr/lib/apache2/modules/mod_rpaf-2.0.so RPAFenable On # Enable reverse proxy add forward RPAFproxy_ips 127.0.0.1 10.0.0.1 # which ips are forwarding requests to us RPAFsethostname On # let rpaf update vhost settings # allows to have the same hostnames as in the "real" # configuration for the forwarding Apache RPAFheader X-Forwarded-For # Allows you to change which header mod_rpaf looks # for when trying to find the ip the that is forwarding # our requests RPAFheader Incap-Client-IP # Add other http headers to read the correct IP address, # eg. Incapsula CDN http header |
The very first line is important, that will enable the module and we can use then the next settings. Most of the other modules have similar compiling methods, however there are cases where different requirements are needed. Most of the time these are specified in the module README file, so please do read that!
Of course you can create this configuration directly in the /etc/apache2/mods-available/ folder and use a2enmod command to enable the module, but since its a manual compile, I try to keep them separated.
That would be all for now, see you again in our next tutorial.