Table of contents
The LAMP stack is a well-known and widely used web-development stack whose primary goal is to help you to build an open source web hosting environment. This stack consists of the following components: Linux (base operating system), Apache (web server), MySQL (relational database) and PHP (multi-platform scripting language). And here’s where LAMP comes from. You may have heard about some well-known projects which are heavily relying on this stack: Facebook, Wikipedia, Tumblr, and WordPress. In this article we’ll show you how you can install it on Ubuntu server.
You must have root privileges or have an ability to use sudo to install required packages to your system.
Installation process is easy and straightforward.
Before installing a new package, you need to update your packages list:
sudo apt update
Now, let’s install Apache web-server:
sudo apt install -y apache2
Make sure that Apache server is up and running:
sudo systemctl status apache2
Now, check that you can open your server’s default web page:
The default Apache web page would appear on the screen:
Your web-server configuration files are stored at
Default web page and other website content should be stored at
It is not required, but if you’d like to change this webpage right now, use
nano editor to make any changes:
sudo nano /var/www/html/index.html
To save a file, press “CTRL+X”, Y, and “Enter”.
Update your system packages before installing the MySQL:
sudo apt update
Now, the installation command:
sudo apt install -y mysql-server
Check that the MySQL service is up and running:
sudo service mysql status
MySQL initial configuration
At this stage we need to configure MySQL default security settings:
During this setup you’ll be asked about:
- Password complexity validation settings
- Password for the root user
- Deletion of anonymous user
- Preventing remote connection to DB using root account
- Removing test database
To make your MySQL database as secure as possible, you definitely need to consider answer Y to all those questions.
As soon as you complete all steps to protect your MySQL, you’ll see a message “All done”.
Let’s check if we can connect to the database.
Testing MySQL connection
You can start MySQL client and connect to the database using the following command:
Type “exit” to exit the MySQL client (or press Ctrl+D).
The PHP is the last component of the LAMP stack installation.
As usual, update the software packages list first:
sudo apt update
Now, you need to install two additional packages:
php– scripting language interpreter
libapache2-mod-php– PHP module for Apache web-server
php-mysql– MySQL client for PHP
Use the following command:
sudo apt install -y php libapache2-mod-php php-mysql
Now, all packages have been successfully installed.
Now, use the following command to check the version of PHP interpreter:
Now, let’s verify the integration of PHP with the Apache web-server.
Create a file named
sudo nano /var/www/html/test.php
Put the following boilerplate test PHP function:
<?php phpinfo(); ?>
To Save the file, press “CTRL+X”, Y and hit “Enter”.
Check the PHP integration with Apache web-server by accessing the following URL:
It’s important to delete
test.php once you’ve ensured that PHP is working, because it contains sensitive server information.
Execute the following command in your terminal:
sudo rm /var/www/html/test.php
Free SSL certificate installation (Let’s Encrypt)
As a small bonus, let’s install a free Let’s Encrypt SSL certificate to your web-server.
First you need to install Certbot (a script, which will renew your SSL certificate automatically).
Update the Ubuntu packages list:
sudo apt-get update
Now, you can install Certbot:
sudo apt-get install -y certbot python3-certbot-apache
Make required changes in your DNS control panel to set up a DNS name for your server.
Now, use the following command to create an SSL certificate:
sudo certbot --apache --redirect -d demo.hands-on.cloud -m firstname.lastname@example.org --agree-tos
demo.hands-on.cloud with your own server DNS name.
Now, you can check that your Apache web-server has a valid free SSL certificate.
Configure automatic SSL certificate renewal
Let’s Encrypt certificates are valid for 90 days.
The Certbot updates the systemd timers and crontab to automatically renew your certificate.
Check that the systemd timer is active.
sudo systemctl list-timers | grep 'certbot\|ACTIVATES'
Now, let’s check that the crontab entry is in place.
sudo ls -l /etc/cron.d/certbot
Finally, let’s verify that the renewal process works without issues:
sudo certbot renew --dry-run
Now you’re ready to deploy your PHP application.
WordPress, right? 😉
In this article we’ve installed the LAMP stack including Apache2 web server, MySQL database and PHP 7.4.3 in Ubuntu Linux. In addition to that we’ve configured a free SSL certificate and prepared your server for hosting your PHP applications.
We hope that this article was useful. If so, please, help us to spread it to the world!