Install and Configure phpMyAdmin on Ubuntu 22.04: Free Web App

Posted on

Install and Configure phpMyAdmin on Ubuntu 22.04: Free Web App

Install and Configure phpMyAdmin on Ubuntu 22.04: Free Web App

This tutorial aims to guide you through the process of Install and Configure phpMyAdmin on Ubuntu 22.04. phpMyAdmin is a widely used, free and open-source web application written in PHP. It provides a graphical user interface (GUI) for managing MySQL and MariaDB databases. Millions of users worldwide rely on it for its convenience and comprehensive features, making database administration tasks significantly easier.

With phpMyAdmin, you can do such things as:

  • Create, alter, drop, and browse databases, tables, fields, and indexes.
  • Execute SQL statements, including batch processing.
  • Manage users, permissions, and privileges.
  • Import data from CSV and SQL files.
  • Export data to various formats such as CSV, SQL, XML, PDF, and more.
  • Administer multiple servers.

Before diving into the installation process, let’s ensure we have the necessary prerequisites in place.

1. Requirements for phpMyAdmin Setup

To successfully Install and Configure phpMyAdmin on Ubuntu 22.04, you’ll need the following:

  1. Ubuntu 22.04 Server: A running instance of Ubuntu 22.04 server.
  2. LAMP Stack: A fully functional LAMP (Linux, Apache, MySQL/MariaDB, PHP) stack. This means you should have Apache web server, MySQL or MariaDB database server, and PHP installed and running.
  3. Root or Sudo Privileges: Access to an account with root or sudo privileges to execute administrative commands.
  4. Internet Connection: A stable internet connection to download necessary packages.

Once you have these requirements satisfied, you can proceed with the installation and configuration of phpMyAdmin.

2. Create MySQL User for phpMyAdmin

For security reasons, it’s best practice to create a dedicated MySQL user for phpMyAdmin. This user will be used to access and manage your databases through the phpMyAdmin interface.

Log in to your MariaDB shell with the command below:

sudo mysql -u root -p

From there, use the command below to create a user, here we named it ‘newuser’:

CREATE USER '**newuser**'@'localhost' IDENTIFIED BY '**password**';

Grant all the privileges to it:

GRANT ALL PRIVILEGES ON *.* TO '**newuser**'@'localhost';

Flush the privileges and exit:

FLUSH PRIVILEGES;
Exit;

Replace **newuser** with your desired username and **password** with a strong, secure password.

3. Install phpMyAdmin on Ubuntu 22.04

In this section, we’ll install phpMyAdmin by downloading the zip file from the phpMyadmin Downloads page. Visit the page, check for the latest version, and copy the link address of the all languages zip file.

First, use the wget command to download the phpMyAdmin on Ubuntu 22.04:

sudo wget https://files.phpmyadmin.net/phpMyAdmin/5.2.1/phpMyAdmin-5.2.1-all-languages.zip

Next, you can extract your downloaded file with the command below:

sudo unzip phpMyAdmin-*-all-languages.zip

Here you need to move your extracted files to the /usr/share/phpmyadmin directory:

sudo mv phpMyAdmin-*-all-languages /usr/share/phpmyadmin

Switch the phpMyAdmin directory on Ubuntu 22.04 with the following command:

cd /usr/share/phpmyadmin

The sample configuration file for phpMyAdmin already exists in the directory. You just need to rename it with the following command:

sudo mv config.sample.inc.php config.inc.php

Also, you need to generate a secret string for the next steps. To do this, run the following command:

openssl rand -base64 32

In your output, you will see something similar to this:

**Output**
fdA3eu1hn2er64R4Q8laHXwi5DkqJAzZEOTwwyb0zYU=

4. Configure phpMyAdmin on Ubuntu 22.04

Now, you need to make some configuration changes to the file that you have renamed before.

Open the file with your favorite text editor, here we use vi editor:

sudo vi config.inc.php

At the file, find the line below and enter the secret string that you have generated before in it:

$cfg['blowfish_secret'] = '<mark>yourgeneratedstring</mark>';

Next, find the ‘Directories for saving/loading files from server’ section and add the following line under this section:

$cfg['TempDir'] = '/tmp';

When you are done, save and close the file.

This temp directory that you have defined in the phpMyAdmin configuration file on Ubuntu 22.04, is used to store the cache files.

Now use the following command to create it:

sudo mkdir /usr/share/phpmyadmin/tmp

Then, set the ownership and correct permissions with the commands below:

sudo chown -R www-data:www-data /usr/share/phpmyadmin
sudo chmod 777 /usr/share/phpmyadmin/tmp

Create Apache configuration file for phpMyAdmin

Here you need to create an Apache configuration file for the phpMyAdmin files on Ubuntu 22.04.

Create and open the file with your favorite text editor, here we use vi:

sudo vi /etc/apache2/conf-available/phpmyadmin.conf

Add the following contents to the file:

Alias /phpmyadmin /usr/share/phpmyadmin

<Directory /usr/share/phpmyadmin/>
  AddDefaultCharset UTF-8
  <IfModule mod_authz_core.c>
    # Apache 2.4
    <RequireAny>
      Require all granted
    </RequireAny>
  </IfModule>
</Directory>

<Directory /usr/share/phpmyadmin/setup/>
  <IfModule mod_authz_core.c>
    # Apache 2.4
    <RequireAny>
      Require all granted
    </RequireAny>
  </IfModule>
</Directory>

When you are done, save and close the file.

Restart Apache to apply the changes:

sudo a2enconf phpmyadmin
sudo systemctl restart apache2

5. Access phpMyAdmin Login Page

Now that you’ve completed the installation and configuration, you can access the phpMyAdmin web interface by typing your server’s IP address in your web browser followed by /phpmyadmin:

http://<mark>your-server-ip-address</mark>/phpmyadmin

You will see the phpMyAdmin login screen. Enter your MariaDB user and password that you have created before and press the Login button to see your phpMyAdmin dashboard.

phpMyAdmin Login screen
phpMyAdmin Login screen
phpMyAdmin Dashboard
phpMyAdmin Dashboard

That’s it, you are done. Enjoy using your phpMyAdmin.

Conclusion

At this point, you have learned to Install and Configure phpMyAdmin on Ubuntu 22.04. phpMyAdmin is a free tool written in PHP that helps you handle the administration of MySQL over the Web.

Hope you enjoy it. You may also like these articles:

How To Install aaPanel on Ubuntu 22.04

Install and Use Yarn on Debian 11

MariaDB installation on Ubuntu 20.04

How to change SSH port in Linux Ubuntu?

How do I stress test CPU and RAM in Ubuntu?

phpMyAdmin Setup Ubuntu 20.04

Installing Nodejs Ubuntu 20.04

Alternative Solutions for Managing MySQL/MariaDB Databases on Ubuntu 22.04

While phpMyAdmin is a popular choice, several alternative methods exist for managing MySQL/MariaDB databases on Ubuntu 22.04. Here are two alternative approaches:

1. Using MySQL Shell

MySQL Shell is an advanced client and code editor for MySQL. It supports JavaScript, Python, and SQL scripting languages and offers features such as:

  • Interactive SQL execution: Execute SQL queries and view results directly in the shell.
  • Scripting capabilities: Write scripts in JavaScript or Python to automate database tasks.
  • Data import and export: Import data from various formats and export data to JSON, CSV, and other formats.
  • Admin API: Manage MySQL Server instances through an administrative API.

Installation:

sudo apt update
sudo apt install mysql-shell

Connecting to the database:

mysqlsh -u root -p

Example Usage (JavaScript):

// Connect to the database
var session = mysql.getSession({
  host: 'localhost',
  port: 3306,
  user: 'newuser',
  password: 'password'
});

// Execute a SQL query
var result = session.sql("SHOW DATABASES").execute();

// Print the result
print(result);

Explanation:

This method offers more flexibility and control compared to phpMyAdmin. It’s particularly useful for developers and administrators who prefer a command-line interface and scripting capabilities. The ability to use JavaScript and Python allows for creating complex automation scripts for database management tasks. It is a powerful alternative to Install and Configure phpMyAdmin on Ubuntu 22.04.

2. Using Dbeaver

Dbeaver is a free, open-source, and universal database tool. It supports a wide range of databases, including MySQL, MariaDB, PostgreSQL, Oracle, and more. Dbeaver provides a rich set of features, including:

  • Data browsing and editing: Browse and edit data in a tabular format.
  • SQL editor: Write and execute SQL queries with syntax highlighting and auto-completion.
  • ER diagrams: Visualize database schemas using entity-relationship diagrams.
  • Data import and export: Import and export data from various formats.

Installation (using Snap):

sudo snap install dbeaver-community

Installation (using apt – requires adding a repository):

wget -O - https://dbeaver.io/debs/dbeaver.key | sudo apt-key add -
echo "deb https://dbeaver.io/debs/dbeaver-ce stable main" | sudo tee /etc/apt/sources.list.d/dbeaver.list
sudo apt update
sudo apt install dbeaver-ce

Connecting to the database:

  1. Launch Dbeaver.
  2. Click on "New Database Connection".
  3. Select "MySQL" or "MariaDB".
  4. Enter the connection details (host, port, username, password).
  5. Click "Test Connection" to verify the connection.
  6. Click "Finish" to save the connection.

Explanation:

Dbeaver offers a desktop-based GUI with a more modern and feature-rich interface compared to phpMyAdmin. Its support for multiple database types makes it a versatile tool for developers and database administrators who work with different database systems. Choosing Dbeaver avoids the need to Install and Configure phpMyAdmin on Ubuntu 22.04.

These alternative solutions offer different approaches to managing your MySQL/MariaDB databases on Ubuntu 22.04. Choose the method that best suits your needs and preferences. These suggestions hope to assist you in choosing the right database management tool for you.

Leave a Reply

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