fbpx

How to Install LAMP Stack on Ubuntu 20.04 LTS

· >
how-to-install-lamp-stack-ubuntu

In this post we are going to learn how to install LAMP stack on Ubuntu 20.04 LTS. LAMP stands for (Linux, Apache, MySQL/MariaDB, PHP).

  • Linux which is Operating System
  • Apache which is Web Server
  • MySQL/MariaDB which is Database
  • PHP is scripting language to serve dynamic content

All of these are open source and free to use. Each piece of the stack is mandatory for creating fully functional dynamic website.

Pre-requisites

  • Ubuntu Server running Focal Fossa 20.04 LTS
  • SSH Access with Root Privileges

Step 1 – Update Packages

First of all, Login with your Ubuntu Server & escalate the privileges to root. Before installation of LAMP stack, update your repository & software packages by running below commands on your ubuntu 20.04 LTS.

#apt update && apt upgrade -y

Step 2 – LAMP Stack Install Apache

Now that your repository & software packages are upgraded, now install apache by entering below commands in your ubuntu server terminal.

#apt install apache2 -y

“-y” switch allows to accept all permissions required by installer. Now that apache2 has been installed, next enable and start the service by running below commands in your terminal if not already

#systemctl enable apache2
#systemctl start apache2

Apache2 service should be active & enabled, like so.

apache2-status-using-systemctl

Step 3 – Update Firewall Rules

UFW is the defualt ubuntu firewall, we need to enable Apache2 access through firewall. Here is our turtoial on UFW Firewall to learn more about it.

We shall enable Apache Full profile to allow port 80 & 443 on our server.

root@lamp-stack:~# ufw allow “apache full”
Rules updated
Rules updated (v6)

Check firewall rule with “ufw app list” to check list of allowed apps.

ufw-app-list

Now if you visit your server IP Address, Apache2 Ubuntu Default Pag should appear.

Step 4 – LAMP Stack MySQL Installation

To install MySQL, type following command in your terminal.

#apt install mysql-server -y

Now check mysql service status, it should be enabled & Active. If it is not Active & enabled, copy below commands & paste in your terminal.

#sudo systemctl start mysql
#sudo systemctl enable mysql
mysql-status-systemctl

Step 5 – MySQL Secure Installation

Next to secure the MySQL installation, execute the following command in your terminal & Answer as follows:

#mysql_secure_installation
mysql-secure-installation

Step 6 – LAMP Stack PHP Installation

Next, to install PHP execute below command in your terminal. Currently PHP 7.4 is the latest release, it will automatically fetch it.

#sudo apt install php libapache2-mod-php php-mysql php-cli php7.4-fpm -y

Once it is installed, verify the PHP version as follows.

php-version-check

PHP-FPM is not enabled by default for Apache2 also to configure apache2 with PHP-FPM we need to execute below commands.

#a2enmod proxy_fcgi setenvif
#a2enconf php7.4-fpm

To activate the new configuration, we need to reload apache2.

#systemctl reload apache2
php7.4-service-status-check
PHP7.4-FPM Service is Active & Enabled

Step 7 – Test PHP Integration with Apache2

To test that php is serving contect via apache2 server, for this pupose we shall create php script in web root directory (/var/www/html/info.php) by entering “vim /var/www/html/info.php” in our terminal and pasting below code & save the file

<?php phpinfo (); ?>

Now if you visit your server IP address/info.php, you will get below screen. which shows that PHP has been installed properly along with apache2 web server.

php7.4-info-php-test-page

In this post, we followed these step by step guide to install LAMP stack on ubuntu 20.04 LTS. If you are interested in setting up LEMP stack on ubuntu, visit our post Learn to Install LEMP stack on Ubuntu here on techacad.net.

That’s all for now, i hope this is been informative for you and i would like to thank you for viewing.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments