Apache Web Server is one of the more dominant web servers on the net. Most of those installations are running some form of PHP applications, whether Laravel, WordPress, or some other custom application.
Apache was originally used as a static web server, hosting HTML files, for example, directly the client. However, due to its support for modules the web servers capabilities have grown to run as an application server as well.
Out of the box, a default Apache2 web server installation on Ubuntu 18.04, 18.10, 19.04, and 19.10 will not run a PHP application. The PHP module is not included.
This tutorial will show you how to configure an Apache web server for running PHP applications.
To install Apache on your Ubuntu server, run the following command.
sudo apt install apache2
Install PHP is simply enough. It can Ben installed using the Apt package manager from Ubuntu’s repositories.
PHP can also be installed from source, if you require a more recent version. That task, unfortunately, is outside of the scope of this tutorial.
To install PHP, run the following command:
sudo apt install php
Additional PHP modules can be installed with the language itself.
Install Apache PHP Module
The PHP module for Apache is not bundled with Apache. As such, it must be installed in addition to the Apache package.
sudo apt install libapache2-mod-php
Once installed the module will have to be enabled. We accomplish this using the a2enmod command.
sudo a2enmod php
Lastly, the Apache web service requires a reboot before the enabled mod will be loaded.
sudo systemctl restart apache2