LAMP server stack

Icons von Linux, Apache, MySQL und PHP

The abbreviation LAMP stands for Linux, the web server Apache, the database MySQL (or MariaDB) and the scripting language PHP (or Python, Perl).

In contrast to Debian, Ubuntu continues to rely on Oracle’s open source edition of the MySQL server instead of using the MariaDB fork. Debian, on the other hand, installs MariaDB even if the admin types apt install mysql-server into the console.

Thanks to the magic of the Debian/Ubuntu package manager Apt, a short command line is enough to quickly set up a complete web server stack with PHP as Apache module and an extension for the database server. Apt will automatically install all additionally required packages (including the base package php-common and some common extensions) and ask for a root password for MySQL. A local web server can then be accessed via a web browser at http://localhost.

However, in production one might prefer to install PHP-FPM instead of the PHP module, which performs better by reducing the load on the web server. In this case, a one-line command is not quite enough; the proxy module and the configuration file for PHP-FPM must also be provided to complete the installation.

Installation

Here is how to install the LAMP stack with PHP as Apache module:

sudo apt install php-mysql libapache2-mod-php mysql-server

The more performant variante with PHP-FPM:

sudo apt install php-fpm php-mysql apache2 mysql-server
sudo a2enmod proxy_fcgi
sudo a2enconf php-fpm
systemctl reload apache2

In Ubuntu, if you want to do without MySQL in favor of MariaDB, install the package mariadb-server instead of mysql-server.

If you want to install a PHP version other than the one provided by the distribution maintainers, you can rely on the repositories of developer Ondrej Sury. For Ubuntu, Sury provides a PPA, which can be integrated as follows:

sudo add-apt-repository ppa:ondrej/php
sudo apt update

After successful installation of the PPA, you can install other PHP versions by adding the version number to the package names. In the following example, the FPM version of PHP 8.2 is to replace the PHP version installed by default:

sudo apt install php8.2-fpm php8.2-mysql
sudo a2disconf php-fpm
sudo a2enconf php8.2-fpm
systemctl reload apache2
systemctl stop php-fpm

First, PHP 8.2 with FPM and the MySQL extension for the new PHP version are installed; next, the Apache configuration for the default install of PHP FPM is removed and then the new configuration for PHP 8.2 is activated. Old PHP-FPM processes are stopped and the new PHP-FPM service is started. Finally, Apache is reloaded to make the new configuration effective.