Ubuntu Server 18.04 – Installing additional Apache modules

Installing MySQL On CentOS 8

Apache features additional modules that can be installed that will extend its functionality. These modules can provide additional features such as adding support for things like Python or PHP. Ubuntu’s implementation of Apache includes two specific commands for enabling and disabling mods, a2enmod and a2dismod, respectively. Apache modules are generally installed via packages from Ubuntu’s repositories. To see a list of modules available for Apache, run the following command:

apt search libapache2-mod 

In the results, you’ll see various module packages available, such as libapache2-python (which adds Python support) and libapache2-mod-php7.2 (which adds PHP 7.2 support), among many others. Installing an Apache module is done the same way as any other package, with the apt install or aptitude commands. In the case of PHP support, we can install the required package with the following command:

sudo apt install libapache2-mod-php7.2 

Installing a module package alone is not enough for a module to be usable in Apache, though. Modules must be enabled in order for Apache to be able to utilize them. We can use the a2enmod and a2dismod commands for enabling or disabling a module. If you wish to simply view a list of modules that Apache has available, the following command examples will help.

You can view a list of modules that are built-in to Apache with the following command:

apache2 -l 

The modules shown in the output will be those that are built-in to Apache, so you won’t need to enable them. If the module your website requires is listed in the output, you’re all set.

To view a list of all modules that are installed and ready to be enabled, you can run the a2enmod command by itself with no options:

The a2enmod command showing a list of available Apache modules

The end of the output of the a2enmod command will ask you whether or not you’d like to enable any of the modules:

Which module(s) do you want to enable (wildcards ok)? 

If you wanted to, you could type the names of any additional modules you’d like to enable and then press Enter. Alternatively, you can press Enter without typing anything to simply return to the prompt.

If you give the a2enmod command a module name as an option, it will enable it for you. To enable PHP 7 (which we’ll need later), you can run the following command:

sudo a2enmod php7.2 

Chances are though, if you’ve installed a package for an additional module, it was most likely was enabled for you during installation. With Debian and Ubuntu, it’s very common for daemons and modules to be enabled as soon as their packages are installed, and Apache is no exception. In the case of the libapache2-mod-php7.2 package I used as an example, the module should’ve been enabled for you once the package was installed:

sudo a2enmod php7.2 
Module php7.2 already enabled 

If the module wasn’t already enabled, we would see the following output:

Enabling module php7.2. 
To activate the new configuration, you need to run: 
service apache2 restart 

As instructed, we’ll need to restart Apache in order for the enabling of a module to take effect. The same also holds true when we disable a module as well. Disabling modules works pretty much the same way, you’ll use the a2dismod command along with the name of the module you’d like to disable:

sudo a2dismod php7.2 
Module php7.2 disabled. 
To activate the new configuration, you need to run: 
service apache2 restart 

The modules you install and enable on your Apache server will depend on the needs of your website. For example, if you’re going to need support for Python, you’ll want to install the libapache2-mod-python package. If you’re installing a third-party package, such as WordPress or Drupal, you’ll want to refer to the documentation for those packages in order to obtain a list of which modules are required for the solution to install and run properly. Once you have such a list, you’ll know which packages you’ll need to install and which modules to enable.

Comments are closed.