Web & data

How to build your own LAMP web server on Ubuntu, Debian, Fedora and RHEL

Install a LAMP stack step by step: update the packages, then set up Apache, MariaDB or MySQL and PHP on Ubuntu, Debian, Fedora and RHEL.

· 2 min read · level: beginner

LAMP refers to a set of free software programs used to build web site servers. The original acronym refers to the following software:

  • "Linux", the operating system ( GNU/Linux )
  • "Apache", the web server
  • "MySQL or MariaDB", the database server
  • Originally, "PHP", "Perl" or "Python", the scripting languages.

To install the various components you will need a working Linux distribution with Internet access.

1. Updating the package list

Before installing new software, it is advisable to refresh your package list to make sure that you have access to the latest versions. This reduces the time needed to update after installation, and it also helps to avoid zero-day exploits against outdated software.

Update on Ubuntu/Debian

sudo apt update

Update on Fedora/CentOS/Red Hat Enterprise Linux

sudo yum update

2. Installing Apache

Apache HTTP Server is a web server application that delivers content such as HTML pages, multimedia and CSS style sheets over the Internet. It is arguably the most popular web server software available on the World Wide Web

The apt install and yum install commands perform the installation according to the distribution on which you run them. The package name may also vary between apache2 and httpd depending on your distribution.

Installation on Ubuntu/Debian

sudo apt install apache2
sudo systemctl start apache2

Installation on Fedora/CentOS/Red Hat Enterprise Linux

sudo yum install httpd
sudo systemctl start httpd

Checking the service status on Ubuntu/Debian

sudo systemctl status httpd

Checking the service status on Fedora/CentOS/Red Hat Enterprise Linux

sudo systemctl status apach2

The status must be marked active for the service to be running.


3. Installing MariaDB or MYSQL

MySQL is a database management system. A database is a structured set of data; it can be as simple as a shopping list, a photo gallery, or a place to store large amounts of information from a company network.

It is recommended not to use MariaDB and MYSQL at the same time on a server, so take care to check whether an installation has not already been carried out on your system.

Installation on Ubuntu/Debian

sudo apt install mariadb-server

Installation on Fedora/CentOS/Red Hat Enterprise Linux

sudo yum install mariadb-server

4. Installing PHP

PHP is the component used to display dynamic content. It can run scripts, connect to your SQL databases in order to obtain information and pass the processed content to your web server to display it.

Installation on Ubuntu/Debian

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

Installation on Fedora/CentOS/Red Hat Enterprise Linux

sudo yum install php libapache2-mod-php php-mysql