How to Install phpMyAdmin on Ubuntu 22.04 | Step-by-Step

July 5th, 2023
How to Install phpMyAdmin on Ubuntu 22.04 | Step-by-Step

PHPMyAdmin is an excellent choice for managing MySQL databases on Ubuntu 22.04. It is a popular tool with a simple, effective, and user-friendly web-based interface which lets you administer MySQL databases effortlessly. Therefore, many developers, database administrators, and website owners trust PHPMyAdmin for their database needs.

This comprehensive guide will explain how to install PHPMyAdmin on Ubuntu 22.04 operating system. By following it, you will know how to run your own PHPMyAdmin to manage your databases effectively.

Prerequisites

To follow along with this phpMyAdmin installation guide, you will need the following:

What is PHPMyAdmin?

PHPMyAdmin is a web-based tool designed to interact with MySQL databases and is based on the PHP web programming language. It allows you to perform various operations like creating tables, executing update and delete commands, as well as data insertion, update, and data import and export.

Moreover, you can manage users accessing the database and run different queries for various business needs. PHPMyAdmin is popular among technical users such as database administrators and web developers as it greatly simplifies database management.

Some of the major benefits of PHPMyAdmin are:

  • Provides the necessary tools to manage the MySQL server;
  • Administrators can manage and control user accounts and access;
  • Privileged users can import and export data to and from various file formats;
  • Capabilities to manipulate data using insert, update, and delete commands;
  • A visual query builder to construct MySQL queries;
  • Database management capabilities such as creating, deleting, and modifying tables, columns, and relationships among tables.

How to install phpMyAdmin on Ubuntu: step-by-step

If you are a beginner unfamiliar with the LAMP stack, continue with the step 1 section of this article. However, if you have already installed it, you can skip this section and jump directly into step 2 of the installation process.

Step 1: Install the LAMP stack

The LAMP stack is a popular open-source software bundle among developers. LAMP stands for Linux, Apache, MySQL, and PHP Python Perl. Most of these technologies are used in web development. This stack is named LAMP, as it is used with Linux operating systems. Ubuntu, Debian, CentOS, and many other Linux operating systems are highly compatible with the LAMP stack.

This section will first describe the essential steps to installing the LAMP stack on Ubuntu. If you have already installed LAMP on your machine, you can skip this part and go straight to installing PHPMyAdmin (step 2).

1. Update system packages

It is important to update your system packages before installing an application on a Linux machine. When you update your system, you are providing it with the latest dependency requirements.

You can update your system using the following command.

1.sudo apt update - This command retrieves information about available updates from repositories and updates all the package lists.

update system example

2. Install Apache web server

The second thing we need to do is install the Apache web server. You can use the sudo apt install apache2 command on your terminal.

install apache web server example

3. Enable Apache

Next, you should instruct the Ubuntu firewall to allow Apache to communicate through it. By now, you should have also enabled Apache services. For that, you may use the sudo ufw allow Apache command first and then the sudo systemctl enable apache2 command.

allow apache example

enable apache example

4. Install MySQL Server

Now it is time to install the MySQL server on your Ubuntu computer. You can do it with the command sudo apt install mysql-server.

install mysql server example

5. MySQL Security

In the next step, you should use the below command to configure MySQL security.

sudo mysql_secure_installation.

Error!

Once you execute the sudo mysql_secure_installation command, you will be prompted to choose the password strength parameters. You can specify 0 for low, 1 for medium, and 2 for strong. Then you will be asked to enter a password and re-enter it for confirmation. There, you may encounter the following error:

“... Failed! Error: SET PASSWORD has no significance for user 'root'@'localhost' as the authentication method doesn't store authentication data in the MySQL server. Please consider using ALTER USER instead if you want to change authentication parameters.”

In that case, you can terminate the current terminal and enter the command sudo mysql in a new terminal.

access mysql terminal example

Then, you can use the following command inside the MySQL terminal.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'your_new_password';.

assign a new password to root user example

After that, your password will be set correctly for the root user of the MySQL server. You can successfully complete the security setup by entering the command sudo mysql_secure_installation.

In that process, you will be asked to:

  • Change the password for root;
  • To remove anonymous users;
  • To disallow remote login as root;
  • To remove the test database and access to it;
  • To reload privileges tables etc.

secure mysql server example

other mysql securing steps example

Furthermore, it is important to note that running the command sudo mysql from now on will result in an error. The reason is that now you have a password for the root user. So, you need to enter the mysql -u root -p command and provide the new password you set earlier to gain access to the MySQL console.

6. Install PHP

Now we can install PHP and the necessary modules using the command sudo apt install php libapache2-mod-php php-mysql.

install php example

7. Configure Apache for PHP

Now it’s time to configure the Apache server to use PHP. For that, we should find the dir.conf file and edit it by moving the “index.php” phrase to the front of the line named “DirectoryIndex”.

First, we can use the command, sudo nano /etc/apache2/mods-enabled/dir.conf to open the file on the nano text editor.

open dir.conf file example

Then we can edit the file as DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm.

edit the conf file example

You can save the file by pressing ctrl+x and then pressing y to say ‘yes’ to save changes. Finally, press the enter/return key to exit the editor.

8. Restart Apache

You should restart the Apache server so that it will update itself and the changes will take effect. You can use the command, sudo systemctl restart apache2 to restart the Apache service.

restart apache example

9. Check if PHP is working

Now it’s time to check if PHP is processed by the Apache server. It can be done by creating a PHP file and trying to access it through our local server(Apache).

First, we will create a file called abc.php. You can use any name ending with the .php: extension for the file. The command, sudo nano /var/www/html/abc.php will do it while opening the file in the nano editor.

create and open a php script file example

Then we can write very simple PHP code and save the file. For example, we will print a message as an output using the following code.

< ?php
echo "Hello to LAMP STACK! From Ubuntu 22.04";
?>

writing php code example

After saving the file, you can open a web browser and type http://your_server_ip/abc.php in the URL bar. In our case, it is “http://localhost/abc.php”.

php output example

Now, you will see the output as in the above screenshot. That means you wrote your first PHP code on your Ubuntu computer.

Great! Now you have successfully set up the LAMP stack on your Ubuntu computer. Now it is time to install phpMyAdmin.

Step 2: Install PHPMyAdmin

Now that we have installed the LAMP stack and set everything up let's begin with the PHPMyAdmin installation.

First, we have to use the command sudo apt install phpmyadmin.

install phpmyadmin example

Then you will be asked to choose the web server to run PHPMyAdmin on. We will choose Apache2 and press ok.

select web server example

The next prompt will ask you to configure a database for phpMyAdmin. Since we have already installed the MySQL server, we can press No and go ahead.

sey 'no' to database configuration example

However, if you choose yes in the above prompt, you will be asked to provide a password for your new database. Additionally, you will be asked to verify the password. If your password does not match the security requirements (ex: the password is not strong enough), you will be asked to retry or ignore the steps. You may select retry and provide a stronger password. After that, the installation will be completed.

provide password example

Next, we should restart the Apache server using the command, sudo systemctl restart apache2.

Now all you need to do is visit the URL http://localhost/phpmyadmin. You will see the PHPMyAdmin login interface, as shown in the following image.

login interface for phpmyadmin example

There, you can provide the Username as root and the Password you set earlier for the MySQL server and press the Go button.

phpmyadmin interface example

Then, you will see your phpMyAdmin interface, as shown in the above image. Now you can easily manage your MySQL/MariaDB databases using PHPMyAdmin.

Conclusion

You have now successfully installed phpMyAdmin on your Ubuntu 22.04 and can start managing and administrating your databases effectively. With its user-friendly, simple interface, and wide range of functionalities, phpMyAdmin is a powerful tool to help you develop your web applications smoothly and perform SQL queries efficiently.

Shanika is a technical consultant and writer with over eight years of experience as a software engineer in the IT sector. Her professional journey started as a software engineer with WSO2. At the same time, she started working as a freelancer on Upwork. She has collaborated with numerous companies throughout her freelance career, including Digication, Splunk, BMC.com, Filestack, APILayer, Flosum, Blazemeter, Sencha, and over twenty others. Having opportunities to work with various companies in different roles has allowed her to amass a wealth of experience. Shanika is an expert in web development, programming, Java, Python, React, Cypress, CI/CD, Docker, and Kubernetes,m. She has significantly contributed to developing products such as IAM solutions, APIs, OCR technologies, test management systems, and front-end frameworks throughout her career. She has also produced blog articles, tutorials, user guides, product documentation, and many other documents, as well as consulting companies to enhance their productivity. Overall, Shanika brings together the experience of a web developer, automation engineer, DevOps developer, software consultant, and technical writer, which is the main reason behind her success as a freelancer. Shanika received her B.Sc. (Hons) in Computer Science from University of Moratuwa, Sri Lanka and resides in Colombo, Sri Lanka.

Cloud VPS - Cheaper Each Month

Start with $9.99 and pay $0.5 less until your price reaches $6 / month.

We use cookies to ensure seamless user experience for our website. Required cookies - technical, functional and analytical - are set automatically. Please accept the use of targeted cookies to ensure the best marketing experience for your user journey. You may revoke your consent at any time through our Cookie Policy.
build: 89586843.644