Jesin's Blog

Welcome to the Portal of Technology

  • Facebook
  • GitHub
  • RSS
  • Twitter
  • Home
  • Categories
    • Domains
    • Linux
    • Networking
    • PHP
    • Virtualization
    • Web Design
    • Web Servers
    • Windows
  • WordPress Plugins
    • Custom Error Pages
    • HTTP Digest Authentication
    • Mailgun Email Validator
  • Toolbox
    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool
  • About Me
  • Contact Me
  • Sitemap
Home ›
Linux ›
How to install PHPMyAdmin on an Nginx Web Server

How to install PHPMyAdmin on an Nginx Web Server

July 16, 2015 Linux, Web Servers Jesin A 6 Comments

nginx phpmyadmin thumbnail

This article will show you how to install the latest version of PHPMyAdmin on Nginx. We will be obtaining the latest stable version of PHPMyAdmin from the GitHub repository and periodically pull updates for it via Git.

Create a directory for PHPMyAdmin and change its ownership to the www-data user.

mkdir /usr/share/phpmyadmin
chown www-data:www-data /usr/share/phpmyadmin

Clone the “STABLE” branch of the PHPMyAdmin GitHub repository into this directory.

cd /usr/share/phpmyadmin
sudo -u www-data -H git clone --depth=1 --branch=STABLE https://github.com/phpmyadmin/phpmyadmin.git .

Do not miss the dot at the end of the Git command.

Edit the desired virtual host file and add the following to it:

location /phpmyadmin {
        alias /usr/share/phpmyadmin;
}

location ~ ^/phpmyadmin(.+\.php)$ {
        alias /usr/share/phpmyadmin;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin$1;
        include fastcgi_params;
}

location ~ ^/phpmyadmin/(.*\.(eot|otf|woff|ttf|css|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|xls|tar|bmp))$ {
        alias /usr/share/phpmyadmin/$1;
        expires 30d;
        log_not_found off;
        access_log off;
}

Make sure these blocks are placed above the other location blocks.

Create a database and grant the necessary privileges to utilize the extra features of PHPMyAdmin like bookmarking and history.

mysql -u root -p
CREATE DATABASE phpmyadmin;
GRANT USAGE ON mysql.* TO 'pmauser'@'localhost' IDENTIFIED BY 'pmapass';
GRANT SELECT (
    Host, User, Select_priv, Insert_priv, Update_priv, Delete_priv,
    Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv,
    File_priv, Grant_priv, References_priv, Index_priv, Alter_priv,
    Show_db_priv, Super_priv, Create_tmp_table_priv, Lock_tables_priv,
    Execute_priv, Repl_slave_priv, Repl_client_priv
    ) ON mysql.user TO 'pmauser'@'localhost';
GRANT SELECT ON mysql.db TO 'pmauser'@'localhost';
GRANT SELECT ON mysql.host TO 'pmauser'@'localhost';
GRANT SELECT (Host, Db, User, Table_name, Table_priv, Column_priv)
    ON mysql.tables_priv TO 'pmauser'@'localhost';
GRANT SELECT, INSERT, UPDATE, DELETE ON phpmyadmin.* TO 'pmauser'@'localhost';

Create a config.inc.php file for PHPMyAdmin:

nano /usr/share/phpmyadmin/config.inc.php

Place the following code:

<?php
$i = 0;

$i++;
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['connect_type'] = 'socket';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = '';
$cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['controluser'] = 'pmauser';
$cfg['Servers'][$i]['controlpass'] = 'pmapass';
$cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
$cfg['Servers'][$i]['relation'] = 'pma__relation';
$cfg['Servers'][$i]['table_info'] = 'pma__table_info';
$cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
$cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
$cfg['Servers'][$i]['column_info'] = 'pma__column_info';
$cfg['Servers'][$i]['history'] = 'pma__history';
$cfg['Servers'][$i]['recent'] = 'pma__recent';
$cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
$cfg['Servers'][$i]['users'] = 'pma__users';
$cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
$cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
$cfg['Servers'][$i]['tracking'] = 'pma__tracking';
$cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
$cfg['Servers'][$i]['designer_coords'] = 'pma__designer_coords';
$cfg['Servers'][$i]['favorite'] = 'pma__favorite';
$cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
$cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';

$cfg['DefaultLang'] = 'en';
$cfg['ServerDefault'] = 1;
$cfg['blowfish_secret'] = 'random-secret';
$cfg['ForceSSL'] = false;
?>

Set ForceSSL to true if you have an SSL certificate installed.

Obtain a randomly generated blowfish secret from this website and add it to the blowfish_secret line.

Do an Nginx configuration test and reload if successful:

sudo service nginx configtest
sudo service nginx reload

Access PHPMyAdmin from the web browser:

http://example.com/phpmyadmin

Configure Cron to periodically check for updates and pull them from GitHub. Edit the cron file of the www-data user.

crontab -u www-data -e

Add the following line:

@daily    cd /usr/share/phpmyadmin/ && git pull -q origin STABLE

That’s it, we have installed the latest version of PHPMyAdmin on Nginx and also configured it to

Related posts:

Default ThumbnailInstalling phpMyAdmin behind Varnish php category thumbnailCreating a PHP MySQL Login Page Script modsecurity serverpilotHow to setup mod_security with ServerPilot php category thumbnailHow to reset the Joomla Administrator password connect php with mysql thumbnailConnect PHP with MySQL

Tags: nginx, phpmyadmin

Comments

  1. Andrey says

    August 8, 2016 at 7:33 pm

    ln -s /usr/share/phpmyadmin /usr/share/nginx/html

    Reply
  2. daksh says

    September 1, 2016 at 2:32 pm

    get 403 error

    Reply
    • kafka says

      October 15, 2020 at 1:01 am

      it work
      add “index index.php;”

      location /phpmyadmin {
      alias /usr/share/phpmyadmin;
      index index.php;
      }

      location ~ ^/phpmyadmin(.+\.php)$ {
      alias /usr/share/phpmyadmin;
      index index.php;
      fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin$1;
      include fastcgi_params;
      }

      Reply
      • kafka says

        October 15, 2020 at 1:02 am

        location ~ ^/phpmyadmin/(.*\.(eot|otf|woff|ttf|css|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|xls|tar|bmp))$ {
        alias /usr/share/phpmyadmin/$1;
        index index.php;
        expires 30d;
        log_not_found off;
        access_log off;
        }

        Reply
  3. Paul P says

    May 31, 2019 at 8:52 pm

    I installed this on my Raspberry but get a ‘502 Bad Gateway’ message

    Reply
  4. basteyy says

    November 10, 2023 at 11:19 pm

    First of all: Thanks for the tutorial.

    2023 you will run into a timeout, when you try to download via

    “`bash
    sudo -u www-data -H git clone –depth=1 –branch=STABLE git://github.com/phpmyadmin/phpmyadmin.git .
    “`
    You should use `https://github.com/phpmyadmin/phpmyadmin.git`.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Get a wealth of information delivered to your inbox. Subscribe and never miss a single article.

  • Tutorials and howtos
  • Code, scripts and commands
  • Online Tools

* No spam, unsubscribe anytime

Hire Me

  • SSL installation and hardening (A+ on Qualys SSL test)
  • Apache & Nginx configuration
  • Email deliverability improvement (10/10 on Mail Tester & MailGenius)
  • WordPress customization, optimization and migration
  • and much more…

    Tools

    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool

    Nav

    • Home
    • About Me
    • Contact Me
    • Privacy Policy
    • Sitemap
    Vultr SSD VPS

    Creative Commons License
    Jesin's Blog by Jesin A is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
    Based on a work at websistent.com.