Install phpMyAdmin With Nginx on Ubuntu

Recipe # | | Comments

First of all be sure that Nginx is up and running without any problems.

Solution

1
2
sudo apt-get update
sudo apt-get install phpmyadmin

During the installation you will see a window asking for a web server to automatically configure. Since Nginx is not in the list just hit TAB to bypass this prompt.

The next prompt will ask if you would like dbconfig-common to configure a database for phpmyadmin to use. Select “Yes” to continue.

Enter the database administrative password that you configured during the MySQL installation to allow these changes.

The installation will now complete.

Now, we have to create a symbolic link to the phpmyadmin files inside the /var/www folder. If www is not there create it first

1
2
3
4
5
6
cd /var
mkdir www 
cd www
ln -s /usr/share/phpmyadmin phpmyadmin
cd phpmyadmin
chown -R our_login_name:www-data *

Then go to /etc/nginx/site

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
server {
  listen   80; ## listen for ipv4; this line is default and implied
  server_name www.mysite.com;

    root /var/www/;

    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }

  #========================================
  location /phpmyadmin {
    root /var/www;
    index index.php index.html index.htm;
    location ~ ^/phpmyadmin/(.+\.php)$ {
      try_files $uri =404;
      root /var/www;
      fastcgi_pass unix:/var/run/php5-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;

      #port_in_redirect off; 
      #proxy_set_header X-Real-IP $remote_addr; 
      #proxy_set_header X-Forwarded-For $remote_addr; 
      #proxy_set_header Host $host; 
      #proxy_pass http://127.0.0.1:8090;
    }

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

  location /phpMyAdmin {
    rewrite ^/* /phpmyadmin last;
  }
  #========================================
  ...
}

Go now to www.mysite.com/phpmyadmin and use the mysql name and password to login

References

[1]