×
Community Blog How to Install LAMP ( Linux, Apache, MySQL and PHP ) Stack on Ubuntu 20.04 LTS

How to Install LAMP ( Linux, Apache, MySQL and PHP ) Stack on Ubuntu 20.04 LTS

In this guide, we'll install LAMP Stack on Ubuntu 20.04 with an Alibaba Cloud Elastic Compute Service (ECS) instance.

By Arman Ali

There are the two most popular stacks available in the current market "LAMP Stack" and "LEMP Stack".

Both stacks have contained a group of open-source software like - Linux, MySQL, PHP.

In this tutorial, we are going to install LAMP Stack on Ubuntu 20.04.

Prerequisites

To complete this guide, You will need to have an Ubuntu 20.04 installed on VPS or Cloud Instance. We will be using an Alibaba Cloud Elastic Compute Service (ECS) instance for our guide.

Step 1 - Install Apache Web Server

Apache web server is one the most famous web server in the market. it captured approx 33.5% of the websites on the internet. Apache is being developed and maintained by the Apache Foundation.

In order to install Apache on your Ubuntu 20.04 First -

Login to your server via SSH terminal.

    ssh username@you-IP-address

Update the Ubuntu's package manager

    sudo apt-get update 

Now, Use this command to install Apache.

    sudo apt install apache2 

Press Y for yes and press Enter.

We now have successfully installed apache on our server.

You can confirm this by visiting your IP to see the holding page Apache.

    http://your-IP-address 

apache

Step 2 - Install & Secure MySQL

Now we need to install MySQL on our instance. MySQL is a widely popular database management system.

In order to install MySQL, we need to run this command

    sudo apt install mysql-server 

Press Y for yes and then press Enter.

It is time to secure our MySQL server. Use this command to secure the MySQL server.

    sudo mysql_secure_installation 

It will ask for VALIDATE PASSWORD PLUGIN

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

If you are planning to install WordPress on this LAMP Stack. Leave this thing otherwise it will conflict later with some plugins in WordPress.

Press Enter to No.

Now, this will ask to set a new root password for MySQL. You should enter a very secure password. confirm your password again and press Enter.

Now, this will ask you to remove anonymous users from MySQL.
Type Y and press Enter.

Now, this will ask you to Disallow root login remotely?

Press Y and Enter

Now, this will ask you to Remove test database and access to it?

Press Y and Enter

Finally, this will ask you to Reload privilege tables now?

Press Y and Enter

You have successfully secured your MySQL server.

Step 3 - Install PHP & It's Extensions

PHP will help our server to display dynamic content to end-users. you can install PHP by using this command.

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

Press Y and Enter

This will install PHP and some default PHP extension on your server if you want to use some specific PHP extensions you can install that particular extension by using this php-extentsionname
For example, we want to install a PHP-mbstring extension We have to run this command

    sudo apt install php-mbstring

Press Y and Enter

All Done!

Restart the Apache web server to load PHP by using this command.

    sudo systemctl restart apache2

To test whether PHP is working on your server or not we can create an info.php file in the root directory of your web server with a PHP info script.

    sudo nano /var/www/html/info.php

This will open a nano text editor in your terminal

Now Paste this script

<?php
phpinfo();

Now press CTRL+X, Y, and Enter to save this file.

Now you can visit your IP Address with info.php to see your info file like this.

http://your-IP-adress/info.php

You should get a detailed PHP info page as shown below.

phpinfo

Congratulations! We have successfully installed LAMP Stack on Ubuntu 20,04 LTS.

Conclusion

Now your LAMP stack is now ready on Ubuntu 20.04 you can now start budding/deploying your dynamic or static site on this LAMP stack.

If you have any questions feel free to ask in the comment section. we will surely reply to them.

0 1 0
Share on

Arman Ali

3 posts | 1 followers

You may also like

Comments

Arman Ali

3 posts | 1 followers

Related Products