How to Install LAMP Stack with PhpMyAdmin in Ubuntu 20.04

LAMP stack is the combination of the most frequently used software packages to build dynamic websites. LAMP is an abbreviation that uses the first letter of each of the packages included in it: Linux, Apache, MariaDB, and PHP.

You can use LAMP to build awesome websites with platforms such as WordPress or Joomla for example.

Additionally, by default, MySQL/MariaDB databases are managed from the command-line interface, via the MySQL shell. If you prefer to manage your databases and perform other useful database server operations from a graphical interface, you need to install PhpMyAdmin, a popular PHP-based web application.

If you looking for a LAMP setup for your Ubuntu 20.04, then you should read our LEMP setup guide on Ubuntu 20.04.

In this article, you will learn how to install and configure LAMP with PhpMyAdmin in Ubuntu 20.04 server. The guide assumes that you have already installed Ubuntu 20.04. If you have not installed already, you can refer to our guides here:

Prerequisites:

  1. Ubuntu 20.04 Server Installation Guide

Step 1: Installing Apache on Ubuntu 20.04

1. Apache2 is an open-source popular, powerful, reliable, and high extensible web/HTTP server software used by numerous websites on the internet.

To install the Apache2 package, use the default package manager as follows:

$ sudo apt install apache2
Install Apache on Ubuntu 20.04
Install Apache on Ubuntu 20.04

The configuration files for Apache2 are located in /etc/apache2 directory and the main configuration file is /etc//etc/apache2/apache2.conf. And the default document root for storing your web files is /var/www/html/.

2. On Ubuntu unlike on other major Linux distributions, systemd services are automatically started and enabled to start at system boot, when a package (intended to run as a service) installation is complete.

You can confirm that the Apache2 service is up and enabled on boot using the following systemctl commands.

$ sudo systemctl status apache2
$ sudo systemctl is-enabled apache2
Check Apache Service
Check Apache Service

4. Next, you need to test the correct operation of the Apache2 server installation. Open a web browser and use the following address to navigate.

http://YOUR_SERVER_IP

You should see the Apache Ubuntu default page shown in the screenshot.

Check Apache Default Page
Check Apache Default Page

Step 2: Installing MariaDB Database on Ubuntu 20.04

5. MariaDB is a fork of the popular MySQL database. It is now popular too and is the default in most Linux distributions including Ubuntu and is also part of most cloud offerings.

To install the MariaDB database server and client, run the following command.

$ sudo apt install mariadb-server mariadb-client
Install MariaDB on Ubuntu 20.04
Install MariaDB on Ubuntu 20.04

The MariaDB configuration files are stored under the /etc/mysql/ directory. There are so many configuration files in there, you can read the MariaDB documentation for more information.

6. Next, confirm that the MariaDB database service is running and is enabled to automatically start when your system is restarted.

$ sudo systemctl status mariadb
$ sudo systemctl is-enabled mariadb
Check MariaDB Service
Check MariaDB Service

7. On production servers, you need to enable some basic security measures for the MariaDB database installation, by running the mysql_secure_installation script which ships with the MariaDB package.

$ sudo mysql_secure_installation

After running the script, it will take you through a series of questions where you can answer yes(y) or no(n) to enable some security options. Because the database system has just been installed, there is no database root (or administrator) user password.

So you need to create one as shown in the following screenshot.

  • Enter current password for root (enter for none): Enter
  • Set a root password? [Y/n] y
  • Remove anonymous users? [Y/n] y
  • Disallow root login remotely? [Y/n] y
  • Remove test database and access to it? [Y/n] y
  • Reload privilege tables now? [Y/n] y
Secure MariaDB Server
Secure MariaDB Server

8. To access the MariaDB shell, run the mysql command with the -u option with sudo. If you do not use the sudo command, you are bound to encounter the error indicated in the following screenshot.

$ mysql -u root -p
$ sudo mysql -u root
Access MariaDB Shell
Access MariaDB Shell

Step 3: Installing PHP in Ubuntu 20.04

9. A general-purpose open-source scripting language, PHP is one of the most popular programming languages for web development. It powers some of the most popular websites and web applications in the world.

To install PHP, run the following command.

$ sudo apt install php libapache2-mod-php php-mysql
Install PHP in Ubuntu 20.04
Install PHP in Ubuntu 20.04

The PHP configuration file will be located in /etc/php/7.2/.

Also, depending on your project, you may want to install some PHP extensions required by your application. You can search a PHP extension as shown.

$ sudo apt-cache search php | grep php-		#show all php packages

10. After finding the extension, you can install it. For example, I am installing PHP modules for Redis in-memory cache and Zip compression tool.

$ sudo apt install php-redis php-zip

11. After installing PHP extension, you need to restart apache to apply recent changes.

$ sudo systemctl restart apache2

12. Next, test if Apache is working in conjunction with PHP. Create an info.php page under the web document root /var/www/html/ directory as shown.

$ sudo vi /var/www/html/info.php

Copy and paste the following code in the file, then save the file and exit it.

<?php
        phpinfo();
?>

13. Next, open a web browser and navigate using the following address.

http://YOUR_SERVER_IP/info.php

If Apache and PHP are working well together, you should see the PHP information (configuration settings and available predefined variables, installed modules, and more on your system) shown in the following screenshot.

Verify PHP Information
Verify PHP Information

Step 4: Installing PhpMyAdmin in Ubuntu 20.04

14. Intended to handle the administration of MySQL/MariaDB databases, PhpMyAdmin is a free widely-used web-based graphical tool with an intuitive web interface, that supports a wide range of operations on MySQL and MariaDB.

To install PhpMyAdmin, run the following command.

$ sudo apt install phpmyadmin
Install PhpMyAdmin in Ubuntu 20.04
Install PhpMyAdmin in Ubuntu 20.04

15. During the package installation, you will be prompted to choose the web server that should be automatically configured to run PhpMyAdmin. Click enter to use Apache, the default option.

Configure Apache to Use PhpMyAdmin
Configure Apache to Use PhpMyAdmin

16. Also, PhpMyAdmin must have a database installed and configured before you can start using it. To configure a database for PhpMyAdmin with the dbconfig-common package, select yes in the next prompt.

Configure Database for PhpMyAdmin
Configure Database for PhpMyAdmin

17. Next, create a password for PhpMyAdmin to register with the MariaDB database server.

Create a Password for PhpMyAdmin
Create a Password for PhpMyAdmin

Once the installation process is complete, the configuration files for phpMyAdmin are located in /etc/phpmyadmin and its main configuration file is /etc/phpmyadmin/config.inc.php. Another important configuration file is /etc/phpmyadmin/apache.conf, used to configure Apache2 to work with PhpMyAdmin.

18. Next, you need to configure Apache2 to serve the phpMyAdmin site. Run the following command to symlink the file /etc/phpmyadmin/apache.conf to /etc/apache2/conf-available/phpmyadmin.conf. Then enable the phpmyadmin.conf configuration files for Apache2 and restart the Apache2 service to apply the recent changes.

$ sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
$ sudo a2enconf phpmyadmin.conf
$ sudo systemctl reload apache2.service
Enable PhpMyAdmin for Apache2
Enable PhpMyAdmin for Apache2

19. In a browser go to http://SERVER_IP/phpmyadmin, replacing SERVER_IP with the server’s actual IP address.

http://SERVER_IP/phpmyadmin

Once the PhpMyAdmin login page loads, enter root for the username and its password, or another MariaDB user, if you have any setup, and enter the user’s password. If you disabled remote root user login, you can use the phpmyadmin user and password to log in.

PhpMyAdmin Login
PhpMyAdmin Login

20. After login, you will see the PhpMyAdmin dashboard. Use it for managing databases, tables, columns, relations, indexes, users, permissions, etc.

PhpMyAdmin Dashboard
PhpMyAdmin Dashboard

This brings us to the end of this guide. Use the feedback form to ask any questions about this guide or any other LAMP stack related issues concerning Ubuntu 20.04.

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

17 thoughts on “How to Install LAMP Stack with PhpMyAdmin in Ubuntu 20.04”

  1. Hi Aaron,

    Installation went well. However, in phpmyadmin there is a warning “NO RIGHTS”.

    Creating a database is impossible. Where could I have gone wrong?

    Thank you in advance,
    Gerard

    Reply
  2. Hi! Thanks for the best guide about LAMP stack Installing. But could you please help me to solve some issues? For example, I go to the /var/www/ and I can not create there any new folder or file, no I can, but only using sudo mkdir test_project and password request after.

    This way is really not convenient for me. The same with the file for example I created the file (sudo touch index.php) Then I open the new file using Visual Code, made some changes and try to save, and again face the notification: “failed to save insufficient permissions” of cour I can save it as Sudo but it’s really not convenient, maybe for the test but not for the real project work.

    Reply
    • To solve that you can do create a group let’s say “developers” and assign the users “www-data” and your user id then via terminal go to /var and change group to “developers” with 775 access. This way all users in group Developers will have write access to www folder, below is a more detailed process:

      1. create group “developers”
      2. Assign the users to ne group : user 1 = “your_user_id” / user 2 = “www-data”
      3. Go to /Var and change group for www folder to developers
      4. Change permissions for group to 7 for www folder
      5. logout and login back again and that should be all
      Reply
  3. This line provides me this error :

    $ sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
    
    ln: failed to create symbolic link '/etc/apache2/conf-available/phpmyadmin.conf': File exists
    

    Any suggestions?

    Reply
      • I got the same notice. Then I added the next line:

        $ sudo a2enconf phpmyadmin.conf. 
        

        It showed me ‘ERROR: Conf PHPMyAdmin does not exist!’

        Any advice? Many thanks for your help!

        Reply
  4. Hi,

    Thank you for the detailed documentation of LAMP and Phpmyadmin. I could successfully install all.

    I could not see the full database list in the PHPMyAdmin database option. What must be the reason?

    Please clarify.
    Thanks

    Reply
    • @nagaraju

      Are you logged in as a user who has the privileges to access all databases on the system? Try to verify this. Also ensure that there are actually many databases on your system, cross-check via the command-line client.

      Reply

Leave a Reply to Gerard Cancel reply

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.