Home » DevOps » Install phpMyAdmin with Nginx on Ubuntu 22.04

The free and open-source online application phpMyAdmin was created in PHP to manage MySQL database management. It offers a graphical user interface for managing databases, enabling users to carry out many database activities via a web browser, including creating tables, adding data, performing SQL queries, and managing users and permissions. This geeky article will show you how to install phpMyAdmin with Nginx on Ubuntu 22.04.

Installing phpMyAdmin on Ubuntu 

The procedure to install phpMyAdmin on Ubuntu Server is pretty simple, and we’ll get started by first upgrading the package list.

# sudo apt-get update

All the packages specified in Ubuntu Server will be checked and updated by the preceding command. We will install phpMyAdmin using the command below after upgrading all of the packages.

# sudo apt-get install phpmyadmin

Ensure that nginx and php-fpm are operational on the Ubuntu server before installing phpmyadmin.

Running the aforementioned command will prompt the installer to select an Apache2 or Lighttpd web server for the automated default server setup. Keep keeping mind that Nginx is not included in the list. To set up nginx manually, just enter without selecting any web servers from the list after pressing TAB to pick OK.

The installer will next ask you if you want to use the dbconfig-common tool to construct the database. After selecting Yes, hit Enter.

Enter a password, hit Enter, and then hit OK for phpMyAdmin to connect to the database.

Enter the same password when prompted, choose OK, and press Enter.

Your Ubuntu server has now been configured to use phpMyAdmin.

Create an Administrative MySQL User

Use the root user to access the MySQL shell.

# sudo mysql -u root -p

Create a new user with administrative privileges

mysql> CREATE USER 'admin'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql> exit;

To change the username and password in the example above, simply swap out “admin” and “password.” The user can only access the database from the same computer that the MySQL server is operating on because it was built using the hostname “localhost.”

Configuring Nginx and phpMyAdmin

Let’s configure Nginx for recently installed MySQL.

Here we will use our custom Nginx Configuration file which we are going to create inside /etc/nginx/conf.d/ with the name of phpMyAdmin.conf.

# sudo touch /etc/nginx/conf.d/phpMyAdmin.conf

Use the command above to create a custom configuration file, then copy and paste the following settings into phpMyAdmin.conf.

# Nginx server configuration for phpMyAdmin

server {
    listen 80 default_server;
	listen [::]:80 default_server;
    server_name example.com;

    root /var/www/html/;
    index index.php index.html index.htm index.nginx-debian.html;

    location /phpmyadmin {
        root /usr/share/;
        index index.php index.html index.htm;
        location ~ ^/phpmyadmin/(.+\.php)$ {
            try_files $uri =404;
            root /usr/share/;
            fastcgi_pass unix:/run/php/php8.1-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include /etc/nginx/fastcgi_params;
        }

        location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
            root /usr/share/;
        }
    }


    location ~ /\.ht {
        deny all;
    }

}

How Nginx will recognize our custom configuration file is the next question. We need to change the default nginx.conf file because it won’t happen automatically.

# sudo nano /etc/nginx/nginx.conf

find for below line and comment it out so that it will not create any conflicts in configuration.
#include /etc/nginx/sites-enabled/*;

If you want to create multiple configuration files, then go to /etc/nginx/conf.d and create n number of config files based on your requirements.

The syntax and configuration are written in the phpMyAdmin.conf file must be verified to be correct after performing all of the aforementioned modifications.

# sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

If you are getting the aforementioned result, your configuration file is completely fine. Otherwise, verify the syntax and configuration once more.

# sudo nginx -s reload

Run the last command only after testing your Nginx configuration to avoid having your website go down.

Voila!!! All of the installations have been completed.

You may now access phpMyAdmin at domain.com/phpmyadmin by opening your server URL or domain.

http(s)://your_domain_or_ip_address/phpmyadmin

Click Go after entering the login information for the administrator user. You will get the below screen by opening above URL.

phpMyAdmin

Conclusion

Congratulations! Your Ubuntu22.04 server now has phpMyAdmin installed. The creation of MySQL databases, users, and tables, as well as a variety of MySQL functions, is now possible. We hope that you found a way how to install phpMyAdmin with Nginx on Ubuntu 22.04.

Pin It on Pinterest

Share This