As useful as Apache is out of the box, some functionality you'll likely require are not built in. Apache uses modules to extend its feature set. Examples of this may include installing the php5
module to enable your site to use PHP, or perhaps the Python module if you develop in that language. Once a module is installed and activated, the features of that module will then become available to you.
The implementation of Apache between CentOS and Debian is different, and the ways in which modules are added between them is also different. In fact, Debian even includes its very own command for enabling and disabling modules, which is completely exclusive to Debian systems. These commands are a2enmod
and a2dismod
.
To work through the typical process of enabling a module in Debian, we can enable the PHP module on our server. I'll also detail this process in CentOS, but as I mentioned, this process is completely different between the two.
First, locate a package that contains the module you want. If you don't know the exact name of the package to install, you can print a list of available Apache modules to your terminal with the following command:
aptitude search libapache2-mod
By default, aptitude
is not installed on most Debian systems. If the previous command results in a command not found error
, you'll just need to install the aptitude
package via apt-get install
. The output may be too long depending on the size of your terminal window, so you may want to pipe the output into less
:
aptitude search libapache2-mod |less
The following screenshot shows the search results of aptitude on a Debian system searching for libapache2-mod
:
By searching that way, you can press Enter
or the up and down arrow keys to scroll through the output, and then press Q when you're finished. By perusing the output, you'll see that the PHP package is named libapache2-mod-php5
. So, let's install it with the following command:
# apt-get install libapache2-mod-php5
Once the package is installed, check the output. It's very possible that Debian already installed the module for you, the logic being that if you specifically ask for a package to be installed, you'll probably want to have it usable right away. If you see output similar to the following, then the PHP module in this example is already installed:
apache2_invoke: Enable module php5
You can verify this by attempting to enable it anyway, by executing a2enmod php5
in the shell. If it's enabled, you'll see output similar to the following:
Module php5 already enabled
In essence, the a2enmod
and a2dismod
commands work pretty much the same. As you can probably gather, one enables modules and the other disables them. In order to use an Apache module, it must be enabled. However, if you no longer need a module you can disable it (or better yet, remove it). Going over all the modules and the features they provide is outside the scope of this book. But in practice, you'll only enable modules that are required by your site, which differs from environment to environment. Before we move on to the same procedure when performed on CentOS systems, I'll leave you with this. To see a list of all modules that are installed on a Debian system, issue the following command:
# apache2ctl -M
Now, let's move on to CentOS. Most modules can be listed similar to how we did before in the Debian section, by using the package manager to list available module packages. In the CentOS, we can do so via the following command:
yum search mod_
Unfortunately, the PHP module isn't listed in this output. This is because we enable PHP in CentOS by simply installing the php
package. This is where things start to get confusing; quite a few CentOS Apache module packages have a naming convention beginning with mod_
, but not all of them do. A bit of research is sometimes necessary when determining which packages need to be installed to grant the system access to a module. If there are any other modules you may need for a site you're developing, such as mod_ldap
for LDAP authentication, feel free to install those as well.
Unlike Debian, the yum
package manager should have already enabled the modules you installed for you. Now that we've installed PHP in our CentOS system, we should have PHP available to us once we restart the httpd
daemon. To verify this, we should be able to create an info.php
file and store it in /var/www/html/info.php
. The contents of the file are as follows:
<?php phpinfo(); ?>
If you navigate to the URL http://<your_server_IP>/info.php
, you should see a page containing information regarding your server's PHP implementation.
Although it's perfectly fine to use an info.php
file in order to test PHP, do not leave it on the server—it is a security risk. You don't want to make it too easy for attackers to determine specific information regarding what your server is running. This procedure is merely to test that PHP is running properly.
Now that we've gone through installing Apache modules, it should be easy for you to customize your web server as you need in order to support any websites or applications you plan to run.