Ubuntu has a PHPMyAdmin included in their repository and you can install it directly from the console command. But the problem is it only comes with packages for Lighttpd or Apache, it does not support Nginx. The best alternative solution is to install it from the original itself at phpmyadmin.net which also has the latest built version. As of writing, the latest version is PHPMyAdmin 5.0.4.
Table of Contents
In this guide, we will show you how to download it from the official source and how to add access to it for the web.
Downloading PHPMyAdmin Source
To install PHPMyAdmin to your NGINX, open up the SSH console command and connect it to your server.
First, we need to create a folder for our PHPMyAdmin.
mkdir /var/phpmyadmin
Assign www-data as the owner of the directory.
sudo chown -R www-data:www-data /var/phpmyadmin
Let’s go to the folder that we just created.
cd /var/phpmyadmin
Then let’s download the latest PHPMyAdmin files. You can find the latest zip at https://phpmyadmin.net.
wget https://files.phpmyadmin.net/phpMyAdmin/5.0.4/phpMyAdmin-5.0.4-all-languages.zip
Let’s unzip the file. If you haven’t installed unzip yet, just install it sudo apt-get install unzip
.
unzip *.zip
Let’s move all of the files in the parent directory.
cd phpMyAdmin-5.0.4-all-languages
mv * ../
Then let’s edit the config.sample.inc.php, make sure to edit the $cfg['blowfish_secret']
with your own value. Then fill up the $cfg['Servers'][$i]['host']
with the host connection, if your MySQL is installed in the server, just use localhost.
Lastly, create a MySQL user to access the PHPMyAdmin. Unfortunately, root access is not allowed here. You need to create one in mysql -u root -p
.
grant all privileges on *.* to 'your_name'@'localhost' identified by "Your_Password";
If you got an error saying “ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘identified by XXXXXXXX at line 1”.
You can use this code instead.
CREATE USER 'your_name'@'localhost' IDENTIFIED BY 'Your_Password';
GRANT ALL PRIVILEGES ON *.* TO 'your_name'@'localhost' WITH GRANT OPTION;
That’s it for setting up the basics of PHPMyAdmin. Let’s proceed with accessing it on the web.
Adding HTTP Access to a Sub-Domain
We don’t recommend accessing your PHPMyAdmin with a plain IP Address, we have a bad experience on Google Chrome that will mark your IP Address as unsafe and dangerous when using PHPMyAdmin. To avoid this, use a subdomain to access it.
To add access to PHPMyAdmin using a Subdomain in your Nginx config. You need to set the following in your Domain DNS records.
Type: A
Host: yoursubdomain
Points to: YOUR_IP_ADDRESS
TTL: 1 Hour
Once done, you can create the NGINX configuration file for it.
vim /etc/nginx/sites-available/yoursubdomain.yourdomain.com
Then add these server directives. The .php directives are quite long – to make it as plug-and-play when you paste this configuration in your server, feel free to use your existing .php directives. If you use that part, make sure to change the fastcgi_pass directory with the path of your php-fpm.
server{
listen 80;
root /var/phpmyadmin;
index index.php index.html index.html index.nginx-debian.html;
server_name yoursubdomain.yourdomain.com
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
try_files $fastcgi_script_name =404;
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_read_timeout 300;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
}
}
Once done, refresh your Nginx server.
sudo service nginx restart
Check your PHPMyAdmin in action at http://yoursubdomain.yourdomain.com and login the MySQL account that we just created earlier.
By now, you can now access the PHPMyAdmin and enjoy the GUI version of MySQL. If you find this post helpful, please leave a comment down below.