Installing LAMP on Ubuntu 21.04 / 20.04
What is LAMP?
In this tutorial, you will learn how to install the LAMP stack, which comprises Linux, Apache, MySQL, and PHP, on Ubuntu 21.04 and 20.04, facilitating the development of high-performance web applications within this open-source software stack.
Updating Package Repository
To update the available packages, use the following command
sudo apt-get update -y
Installing Apache
To install Apache, use the following command.
sudo apt install apache2 -y
To verify if Apache is running, you can use the following command.
sudo systemctl status apache2
The output, if Apache is running, might look something like this.
apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2022-04-11 14:36:01 CEST; 20h ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 12175 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 12179 (apache2)
Tasks: 8 (limit: 2229)
Memory: 11.7M
CGroup: /system.slice/apache2.service
ââ12179 /usr/sbin/apache2 -k start
ââ12181 /usr/sbin/apache2 -k start
ââ12182 /usr/sbin/apache2 -k start
ââ12183 /usr/sbin/apache2 -k start
ââ12184 /usr/sbin/apache2 -k start
ââ12185 /usr/sbin/apache2 -k start
ââ12552 /usr/sbin/apache2 -k start
ââ13118 /usr/sbin/apache2 -k start
Apr 11 14:36:01 testing systemd[1]: Starting The Apache HTTP Server...
Apr 11 14:36:01 testing systemd[1]: Started The Apache HTTP Server.
If Apache is operational, you should be able to access the server through your web browser. Navigate to http://YOUR-IP, and you should see the default Apache page displayed.
Installing MariaDB
Install MariaDB by using this command.
sudo apt install mariadb-server mariadb-client -y
Verify if MariaDB is running by using the following command.
sudo systemctl status maridb.service
The output should look something like this.
mariadb.service - MariaDB 10.5.13 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2022-04-13 10:21:42 CEST; 42s ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Process: 28206 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
Process: 28207 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 28209 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ] && systemc>
Process: 28271 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 28273 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
Main PID: 28256 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 15 (limit: 2229)
Memory: 58.6M
CGroup: /system.slice/mariadb.service
ââ28256 /usr/sbin/mariadbd
Apr 13 10:21:41 testing mariadbd[28256]: 2022-04-13 10:21:41 0 [Note] InnoDB: Buffer pool(s) load completed at 220413 10:21:41
Apr 13 10:21:42 testing mariadbd[28256]: 2022-04-13 10:21:41 0 [Note] Reading of all Master_info entries succeeded
Apr 13 10:21:42 testing mariadbd[28256]: 2022-04-13 10:21:41 0 [Note] Added new Master_info '' to hash table
Apr 13 10:21:42 testing mariadbd[28256]: 2022-04-13 10:21:41 0 [Note] /usr/sbin/mariadbd: ready for connections.
Apr 13 10:21:42 testing mariadbd[28256]: Version: '10.5.13-MariaDB-0ubuntu0.21.04.1' socket: '/run/mysqld/mysqld.sock' port: 3306 Ubuntu 21.04
Apr 13 10:21:42 testing systemd[1]: Started MariaDB 10.5.13 database server.
Configuring MySQL
For a new MySQL installation, it’s advisable to execute the security script that accompanies it. This script will prompt you with several security-related questions. Respond to them according to your preferences. Run the script using the following command:
mysql_secure_installation
Installing PHP
Install PHP by using the following command.
sudo apt install php -y
Installing PHP Modules
To inspect available modules, you can use the following command:
apt-cache search php
Once you’ve identified the modules you wish to install, proceed with the installation using the following command.
sudo apt install php-<modulename> -y
For example:
sudo apt install php-cli -y
Summary
I’m glad you found the tutorial helpful! If you have any further questions or if there’s anything else you’d like assistance with, feel free to ask.
If you have any questions, please don’t hesitate to reach out to us through our community forum. We’re here to help!
