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 free and open-source web application that provides a user-friendly graphical interface (GUI) for managing MySQL and MariaDB databases. It’s the most widely used MySQL administration tool globally, favored by millions for its ease of use and comprehensive features.
With phpMyAdmin, you can do such things as:
- Create, modify, and delete databases.
- Create, modify, and delete tables.
- Execute SQL queries.
- Import and export data.
- Manage users and permissions.
- Perform database maintenance tasks.
Before we dive into the installation process, let’s ensure you 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:
- An Ubuntu 22.04 Server: A fresh installation of Ubuntu 22.04 is recommended.
- A Web Server: Apache is commonly used, but Nginx will also work.
- PHP: PHP and necessary extensions (e.g.,
php-mysql
,php-mbstring
,php-zip
,php-gd
,php-xml
,php-curl
) are essential for phpMyAdmin to function. - MySQL or MariaDB: A running instance of either MySQL or MariaDB database server.
- Root or Sudo Privileges: You’ll need administrative rights to install software and configure the system.
Once you have satisfied these requirements, you are ready to Install and Configure phpMyAdmin on Ubuntu 22.04.
2. Create MySQL User for phpMyAdmin
First, you need to 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;
3. Install phpMyAdmin on Ubuntu 22.04
Here we will 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
At this point, 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
At this point, you can access the phpMyAdmin web interface by typing your server’s IP address in your web browser followed by /phpmyadmin
:
http://your-server-ip-address/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.
[Insert phpMyAdmin Login screen image here]
[Insert phpMyAdmin Dashboard image here]
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. With these steps, you should have a fully functional phpMyAdmin installation on your Ubuntu 22.04 server.
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 Installing phpMyAdmin on Ubuntu 22.04
While the method described above works, here are two alternative approaches to achieve the same goal of installing and configuring phpMyAdmin.
1. Using apt
Package Manager
The simplest and most recommended way to Install and Configure phpMyAdmin on Ubuntu 22.04 is using the apt
package manager. This method handles dependencies automatically and keeps your installation up-to-date with security patches.
Steps:
-
Update Package Index:
sudo apt update
-
Install phpMyAdmin:
sudo apt install phpmyadmin php-mbstring php-zip php-gd php-xml php-curl
During the installation, you will be prompted to configure phpMyAdmin. Choose
apache2
as the web server. -
Enable
mbstring
Extension:sudo phpenmod enable mbstring
-
Restart Apache:
sudo systemctl restart apache2
-
Create a symbolic link (if prompted): Sometimes, the installer doesn’t automatically create the necessary symbolic link to make phpMyAdmin accessible. If you encounter a "Not Found" error when accessing
/phpmyadmin
, create the symbolic link manually:sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
Or
sudo ln -s /usr/share/phpmyadmin /etc/apache2/sites-available/phpmyadmin.conf sudo a2enconf phpmyadmin sudo systemctl restart apache2
This links the phpMyAdmin installation directory to your web server’s document root or configurations directory.
Advantages:
- Easy and Fast: The
apt
package manager streamlines the installation process. - Automatic Dependency Resolution: Handles all necessary PHP extensions.
- Automatic Updates: Keeps phpMyAdmin updated with security patches and bug fixes.
Disadvantages:
- May not always be the latest version: The version available in the Ubuntu repositories might not be the absolute newest release.
2. Using Docker
Docker provides a containerized environment, making it easy to deploy phpMyAdmin in isolation without affecting the host system.
Prerequisites:
- Docker installed on your Ubuntu 22.04 server.
Steps:
-
Pull the phpMyAdmin Docker Image:
docker pull phpmyadmin/phpmyadmin
-
Run the phpMyAdmin Container:
docker run --name myphpadmin -d -e PMA_HOST=your_mysql_host -e PMA_PORT=3306 -p 8080:80 phpmyadmin/phpmyadmin
--name myphpadmin
: Assigns a name to the container.-d
: Runs the container in detached mode (background).-e PMA_HOST=your_mysql_host
: Sets the MySQL host (e.g.,localhost
if MySQL is on the same machine, or the IP address of the MySQL server).-e PMA_PORT=3306
: Sets the MySQL port (default is 3306).-p 8080:80
: Maps port 8080 on the host to port 80 inside the container (where phpMyAdmin runs).phpmyadmin/phpmyadmin
: Specifies the Docker image to use.
-
Access phpMyAdmin:
Open your web browser and navigate to
http://your-server-ip-address:8080
.
Advantages:
- Isolation: phpMyAdmin runs in a container, isolated from the host system.
- Consistency: Ensures consistent behavior across different environments.
- Easy Deployment: Simplifies deployment and management.
Disadvantages:
- Requires Docker Knowledge: Familiarity with Docker is necessary.
- Resource Overhead: Containerization adds a slight overhead in terms of resource usage.
By understanding these alternative methods, you can choose the approach that best suits your needs and technical expertise to Install and Configure phpMyAdmin on Ubuntu 22.04.