• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install Apache, MySQL, PHP (LAMP) on Ubuntu 20.04

Written by Admin, Updated On May 6, 2020
apache, lamp, mysql, php, ubuntu
How to Install Apache, MySQL, PHP (LAMP) on Ubuntu 20.04

A LAMP stack is short form of Linux, Apache, MySQL and PHP. Here, L means Linux operating system, A for Apache web server, M is for MySQL database, P for PHP programming language. In this guide, we’ll install Apache 2.4, MySQL 8.0 and PHP 7.4 (LAMP) on Ubuntu 20.04 LTS (Focal Fossa) system.

Prerequisites#

You must have root user or user with sudo privileges.

Upgrade current packages to latest version.

sudo apt update
sudo apt upgrade

Step 1 – Installing Apache#

Installing Apache is a pretty straightforward process. We will install Apache from default Ubuntu repositories using apt package manager. On Debian based distributions, the Apache package and the service is called apache2.

sudo apt install apache2

Step 2 — Installing MySQL#

MySQL is a popular database management system used within PHP environments. The default Ubuntu repositories includes MySQL server 8.0. Use the following command to install it.

sudo apt install mysql-server

Once the installation is finished, it’s recommended that you run a security script that comes pre-installed with MySQL. This script will remove some insecure default settings and lock down access to your database system. Run the below command:

sudo mysql_secure_installation

You will be prompt for few questions as given below, select the appropriate options:

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

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? 

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

Step 3 – Installing PHP#

At this point, you have installed Apache and MySQL. Now we need PHP to process code to display dynamic content to user. PHP 7.4 packages are available under the default repositories on Ubuntu 20.04 LTS. To install PHP on your system, update apt index and then install it on your system. It also required to install libapache2-mod-php to enable Apache to handle PHP files.

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

Step 4 – Adjusting the Firewall#

After Apache installation make sure that your firewall allows HTTP and HTTPS traffic. You can get list of ufw profile list by typing :

sudo ufw app list
Available applications:
   Apache
   Apache Full
   Apache Secure
   OpenSSH

Allow incoming HTTP and HTTPS traffic for this profile:

sudo ufw allow in "Apache Full"

Step 5 – Manage Services#

Now we completed LAMP installation steps. We will see some basic management commands.

To stop Apache and MySQL service you can run :

sudo systemctl stop apache2
sudo systemctl stop mysql

You can again start service by type :

sudo systemctl start apache2
sudo systemctl start mysql

To do Restart (stop and start) the Apache service:

sudo systemctl restart apache2
sudo systemctl restart mysql

Step 6 – Test Setup#

After completing all steps, Create a new file named info.php inside your custom web root folder:

nano /var/www/html/info.php

Add the following text into it:

<?php
phpinfo();

Save and close the file.

Now, open your web browser and access your server’s domain name or IP address followed by the script name info.php. You will see a page like below:

ubuntu-20-04-phpinfo

That’s it. You successfully install LAMP stack (Apache, MySQL, PHP) on your Ubuntu 20.04 LTS server.

Feel free to comment below, if you have any question or feedback.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install Node.js on Ubuntu 20.04 LTS
Next Article   How to Install LEMP Stack on Ubuntu 20.04

Related Posts

  • How to Install and Use PHP Composer on Ubuntu 22.04

    How to Install Composer on Ubuntu 22.04

    January 31, 2023
  • How to Install Nginx on Ubuntu 22.04

    How to Install Nginx on Ubuntu 22.04

    January 28, 2023
  • How to Install Puppet Agent on Ubuntu 22.04

    How to Install Puppet Agent on Ubuntu 22.04

    January 22, 2023

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install SSH Keys on Ubuntu 22.04
    How to Set up SSH Keys on Ubuntu 22.04 January 7, 2023
  • How to Install Mongodb on Debian 11
    How to Install MongoDB on Debian 11 Linux January 11, 2023
  • How to Install Puppet Agent on Ubuntu 22.04
    How to Install Puppet Agent on Ubuntu 22.04 January 22, 2023
  • How to Install Jenkins on Debian 11
    How to Install Jenkins on Debian 11 January 5, 2023
  • How to Change-Hostname Ubuntu 22.04
    How to Change Hostname on Ubuntu 22.04 January 19, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook