How To Install phpmyadmin on an Nginx Server (in less than 5 minutes)

2 min read 7 hours ago
Published on Jan 21, 2025 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial will guide you through the process of installing phpMyAdmin on an Nginx server running Ubuntu. With just a few simple commands and minimal configuration, you will have phpMyAdmin set up in less than five minutes, allowing you to manage your MySQL databases easily.

Step 1: Update Your System

Before installing phpMyAdmin, ensure that your package lists are up to date.

  1. Open your terminal.
  2. Run the following command to update your package list:
    sudo apt update
    
  3. Optionally, upgrade your installed packages with:
    sudo apt upgrade
    

Step 2: Install phpMyAdmin

Now, install phpMyAdmin using the following commands.

  1. Install phpMyAdmin by running:
    sudo apt install phpmyadmin
    
  2. During the installation, you will be prompted to choose a web server. Select "nginx" (use the spacebar to select).
  3. When asked if you want to use dbconfig-common to set up the database, choose "Yes" and provide your MySQL credentials when prompted.

Step 3: Configure Nginx for phpMyAdmin

Next, you need to configure Nginx to serve phpMyAdmin.

  1. Create a new configuration file for phpMyAdmin using:
    sudo nano /etc/nginx/conf.d/phpmyadmin.conf
    
  2. Add the following configuration into the file:
    server {
        listen 80;
        server_name your_domain_or_IP;
    
        root /usr/share/phpmyadmin;
        index index.php index.html index.htm;
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
    
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php7.x-fpm.sock; # Make sure to replace 7.x with your PHP version
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    
        location ~ /\.ht {
            deny all;
        }
    }
    
  3. Save and exit the editor (press CTRL + X, then Y, and Enter).

Step 4: Test the Nginx Configuration

After editing the configuration file, check for syntax errors.

  1. Run the following command:
    sudo nginx -t
    
  2. If the test is successful, restart Nginx to apply the changes:
    sudo systemctl restart nginx
    

Step 5: Access phpMyAdmin

Now you can access phpMyAdmin through your web browser.

  1. Open your browser and navigate to:
    http://your_domain_or_IP/phpmyadmin
    
  2. Log in using your MySQL username and password.

Conclusion

You have successfully installed phpMyAdmin on your Nginx server in Ubuntu. This setup allows you to easily manage your MySQL databases through a web interface.

Next Steps

  • Consider securing your phpMyAdmin installation by implementing HTTPS.
  • Familiarize yourself with the features of phpMyAdmin to make the most of your database management tasks.