In this article, we will guide you on how to install phpMyadmin with Nginx on Ubuntu 22.04 or 20.04, allowing you to securely and easily manage your databases.
How to install phpMyadmin with Nginx on Ubuntu 22.04 and 20.04 LTS
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 have the ability to directly execute any SQL statement.
Step 1. Prerequisites for Installing phpMyAdmin with Nginx
Before beginning the installation of phpMyadmin on Ubuntu 22.04 or 20.04, make sure that you have already installed PHP, MYSQL, and NGINX.
Once you have installed Nginx, PHP, and MYSQL, you may also need to disable Apache2 by running the following command in the terminal:
sudo systemctl disable apache2
Step 2. Install & Secure phpMyAdmin for Nginx
Install phpMyAdminon Ubuntu 20.04
It is very easy to install phpMyadmin with Nginx on Ubuntu 20.04, because it already comes with the phpMyadmin package, you just need to run the following command to install:
sudo apt install phpmyadmin -y
In this step, since we are using phpMyadmin with Nginx, we will not select apache2 or lighttpd. Simply press TAB, select OK, and then press enter.
Enter and confirm the password when prompted.
During the install phpMyadmin with Nginx on Ubuntu 22.04 or 20.04, if you wish to make changes to the configuration, you can do so using the following command:
sudo dpkg-reconfigure phpmyadmin
Install phpMyAdminon Ubuntu 22.04
Unlike the installation process for Ubuntu 20.04, this guide will demonstrate how to install phpMyAdmin on the latest version of Ubuntu 22.04 or Debian Linux. To begin, run the following command to download the phpMyAdmin source code:
Multiple language version:
DATA="$(wget https://www.phpmyadmin.net/home_page/version.txt -q -O-)" URL="$(echo $DATA | awk '{print $3}')" VERSION="$(echo $DATA | cut -d ' ' -f 1)" wget https://files.phpmyadmin.net/phpMyAdmin/${VERSION}/phpMyAdmin-${VERSION}-all-languages.tar.gz
English version (Only):
DATA="$(wget https://www.phpmyadmin.net/home_page/version.txt -q -O-)" URL="$(echo $DATA | awk '{print $3}')" VERSION="$(echo $DATA | cut -d ' ' -f 1)" wget https://files.phpmyadmin.net/phpMyAdmin/${VERSION}/phpMyAdmin-${VERSION}-english.tar.gz
Note: If the command gives a 404 error, you can go to phpmyadmin.net to download the file and then extract it.
You can alternatively download the file from the official website at phpmyadmin.net and extract it. If you prefer to use the English version, you can replace the end line with the following command.
wget https://files.phpmyadmin.net/phpMyAdmin/${VERSION}/phpMyAdmin-${VERSION}-english.tar.gz
Step 3. Securely Set Up phpMyAdmin on Linux / Ubuntu
After the file has been downloaded, extract it and copy or move the files to the “/usr/share/” directory to start install phpMyadmin with Nginx on Ubuntu 22.04 or 20.04. To do this, run each of the following commands in the terminal.
tar xvf phpMyAdmin-${VERSION}-all-languages.tar.gz sudo mv phpMyAdmin-*/ /usr/share/phpmyadmin sudo mkdir -p /usr/share/phpmyadmin/tmp
Note: If you download the English version, the command will be as follows:
tar xvf phpMyAdmin-${VERSION}-english.tar.gz sudo mv phpMyAdmin-${VERSION}-english /usr/share/phpmyadmin sudo mkdir -p /usr/share/phpmyadmin/tmp
As you can see from the command above, after ItsmeIT moved the source code to the /usr/share/ directory, I ran the command to create the tmp directory. By default, when installing phpMyAdmin, the tmp directory is not automatically created. Therefore, you need to create this directory manually.
PhpMyAdmin uses Blowfish to encrypt user passwords when logging into the system. When users log in, the password is encrypted using Blowfish and compared to the previously encrypted password in the database. Using Blowfish helps ensure that passwords are secure and unreadable even when attacked by hackers. In the next step of the process of installing phpMyAdmin on Ubuntu or Linux, to use the Blowfish encryption method, you need to provide a value for it.
Continuing with the install phpMyadmin with Nginx on Ubuntu 22.04, 20.04 or Linux, you need to copy the config.sample.inc.php
file and rename it to config.inc.php
, and then open the config.inc.php file and set the Blowfish value.
sudo cp /usr/share/phpmyadmin/config.sample.inc.php /usr/share/phpmyadmin/config.inc.php sudo nano /usr/share/phpmyadmin/config.inc.php
Scroll down to the line starting with $cfg['blowfish_secret']
, and give it any value. You can generate a random value here: tools/blowfish-salt.
And add the configuration for the temp (tmp) directory at the end.
After you have entered the correct values as instructed by ItsmeIT, press Ctrl + X, select Y to save the file. Finally, you need to set permissions for the directories and files so that phpmyadmin can operate properly.
sudo chown -R www-data:www-data /usr/share/phpmyadmin/ sudo find /usr/share/phpmyadmin/ -type d -exec chmod 755 {} \; sudo find /usr/share/phpmyadmin/ -type f -exec chmod 644 {} \;
Step 4. Config phpMyadmin with Nginx
In order to configure phpMyAdmin to work with Nginx on a Linux system such as Debian or Ubuntu, you’ll need to create a configuration file for it. Use the following command to add and save the configuration for phpMyAdmin:
sudo nano /etc/nginx/conf.d/phpmyadmin.conf
server { listen 80; listen [::]:80; server_name 127.0.0.1; root /usr/share/nginx/html/; index index.php index.html index.htm index.nginx-debian.html; location / { try_files $uri $uri/ =404; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { fastcgi_pass unix:/run/php/php8.1-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; include snippets/fastcgi-php.conf; } location ~ /\.ht { deny all; } location /phpmyadmin { root /usr/share/; index index.php; try_files $uri $uri/ =404; location ~ ^/phpmyadmin/(doc|sql|setup)/ { deny all; } location ~ /phpmyadmin/(.+\.php)$ { fastcgi_pass unix:/run/php/php8.1-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; include snippets/fastcgi-php.conf; } } }
Note:
- I’m using php8.1, so my fastcgi_pass config is /run/php/php8.1-fpm.sock. Therefore, please replace the php version you want to use accordingly.
- This guide is for installation on localhost, so we’ll be using listen 80 for regular HTTP. If you’re installing on a server, you can use SSL with listen 443 and add your own SSL configuration file.
After finishing the installation of phpMyadmin with Nginx on Ubuntu and adding the configuration of the file phpmyadmin.conf, save the file and restart nginx to apply the changes.
sudo service nginx restart
You’re done! Now, open your web browser and enter the address 127.0.0.1/phpmyadmin
or localhost/phpmyadmin
to access phpMyAdmin.
Step 5. Use the phpMyadmin on Linux Ubuntu
After completing the installation steps for phpMyAdmin on Ubuntu 22.04, 20.04 or Linux, to use the phpMyAdmin interface, you need to create a MySQL account and assign it allocated privileges instead of using the root account as on XAMPP on Windows.
The root account in MySQL is the account with the highest permissions, allowing access and performing all functions on the database system. However, for security reasons, using the root account to access the database is not recommended.
Instead, you should create a new account and give it the necessary permissions to access and manage your database through phpMyAdmin. To create a user for MYSQL you can find instructions here.
How to remove phpMyadmin on Ubuntu 20.04, 22.04 OR Debian
— Remove phpMyadmin on Ubuntu 20.04 LTS
The following command will remove phpMyadmin from your system
sudo apt remove phpmyadmin sudo apt autoremove sudo rm -rf /etc/nginx/conf.d/phpmyadmin.conf sudo service nginx restart
— Remove phpMyadmin on Ubuntu 22.04 LTS
sudo rm -rf /usr/share/phpmyadmin/ sudo rm -rf /etc/nginx/conf.d/phpmyadmin.conf sudo service nginx restart
The above is a guide on how to install phpMyadmin with Nginx on Ubuntu 22.04 or 20.04. It involves adding a few simple configurations in Nginx to integrate it with phpMyadmin and Mysql for a more convenient use. I hope it helps you!
– Advertising –
1 vote cho bài viết này!