How to install MySQL-server and PhpMyAdmin in Ubuntu 22.04

Introduction:
In this article, we will be covering how to install php myadmin on Ubuntu 22.0.

MySQL:
MySQL is an open-source relational database management system (RDBMS) that is widely used for managing and organizing data. Developed by Oracle Corporation, MySQL is known for its reliability, performance, and ease of use. It uses a client-server architecture and SQL (Structured Query Language) to interact with databases. MySQL is commonly used in web applications to store and retrieve data efficiently. It supports various storage engines, and transactions, and has a strong community and extensive documentation.

PhpMyAdmin
PhpMyAdmin
is a free software tool written in PHP, intended to handle the administration of MySQL over the Web. PhpMyAdmin supports a wide range of operations on MySQL and MariaDB. Frequently used operations (managing databases, tables, columns, relations, indexes, users, permissions, etc) can be performed via the user interface, while you still can directly execute any SQL statement.

Prerequisites:

You must have a Ubuntu 22 server with root access.

Step 1: Update the packages
Step 2: Install MySQL-Server from the apt repository.

Log in to MySQL using the command MySQL and then run the query to set the password for the root user.

After this exit from MySQL and try to log in again with the command mysql -u root -p and the password you have provided.

mysql_secure_installation is a script that assists in securing a newly installed MySQL server by applying recommended security configurations.

Step 3: Run the secure installation script

This will take you to a series of prompts as shown below you can answer them according to your use case and complete all the configurations.

Step 4: Create a new database and a user in MySQL

Login into MySQL using the root password and run this query.

Run this query to create a new user named John in MySQL with the password.

Next, Run this command to create a database my_db

Next need to grant privilege for this user for this database for that you need to run the script.

This will give access to all tables of the database to the user if you want to give access to a particular table you can modify the script accordingly like below.

Try logging into MySQL using the new username.

Step 5: Install PHP and Required Extensions:

This will install Apache and the necessary packages for PhpMyAdmin.

After the installation, you can check the status of apache2 using the command

Step 6: Install PhpMyAdmin

Only need to run this command to install PhpMyAdmin and follow the installation wizard.

Chose apache2 webserver to configure automatically

Then you can either manually create the dbconfig-common or else click yes and enter the root password of your MySQL server to configure automatically.

After the process completes the PhpMyAdmin creates a configuration directory in /etc/phpmyadmin.
You can see an apache.conf as well as config-db.php file.
The apache.conf holds the configuration file for Apache and config-db.php contains the connection details of mysql-server.

Lastly, you need to include this PhpMyAdmin apache configuration file in the apache.conf.

For that open vi /etc/apache/apache2.conf.

Append this line to the conf file and check the syntax using the command apachectl -t.
And restart the Apache service.

Test the working open up your browser and type http://<your_server_public_ip>/phpmyadmin

You will get the default PhpMyAdmin login page as shown below.

Try to log in using the MySQL details you can either log in via the root user or by the non-root user.
After successful login, you will get a similar console as shown below.

You can also use the same setup to install local host php my admin

Step 7: Remove PhpMyAdmin

In order to remove PhpMyAdmin you need to run the below commands

Summary:
In this article, you have learned how to install and configure MySQL and PhpMyAdmin in Ubuntu 22.0

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *