Difference between revisions of "PhpMyAdmin"

From ArchWiki
Jump to: navigation, search
(update installation, some rephrasing, remove out of date information)
m (Fix typo: lenght -> length)
 
(54 intermediate revisions by 26 users not shown)
Line 1: Line 1:
[[Category:Web Server]]
 
 
{{lowercase title}}
 
{{lowercase title}}
 +
[[Category:Web server]]
 
[[cs:PhpMyAdmin]]
 
[[cs:PhpMyAdmin]]
 
[[es:PhpMyAdmin]]
 
[[es:PhpMyAdmin]]
 
[[fr:phpmyadmin]]
 
[[fr:phpmyadmin]]
 +
[[ja:PhpMyAdmin]]
 
[[ru:PhpMyAdmin]]
 
[[ru:PhpMyAdmin]]
 
[[tr:PhpMyAdmin]]
 
[[tr:PhpMyAdmin]]
 
[[zh-CN:PhpMyAdmin]]
 
[[zh-CN:PhpMyAdmin]]
 
 
[http://www.phpmyadmin.net/ phpMyAdmin] is a web-based tool to help manage MySQL databases using an Apache/PHP frontend. It requires a working [[LAMP]] setup.
 
[http://www.phpmyadmin.net/ phpMyAdmin] is a web-based tool to help manage MySQL databases using an Apache/PHP frontend. It requires a working [[LAMP]] setup.
  
Line 15: Line 15:
  
 
== Configuration ==
 
== Configuration ==
 +
 +
===PHP===
 +
You need to enable the {{ic|mysqli}} and {{ic|mcrypt}} (if you want phpMyAdmin internal authentication) extensions in PHP by editing {{ic|/etc/php/php.ini}} and uncommenting the following lines:
 +
extension=mysqli.so
 +
extension=mcrypt.so
 +
 +
Optionally you can enable {{ic|bz2.so}} and {{ic|zip.so}} for compression support.
 +
{{Accuracy|{{ic|open_basedir}} is no longer set by default, in fact it may cause a server error if set.}}
 +
You need to make sure that PHP can access {{ic|/etc/webapps}}. Add it to {{ic|open_basedir}} in {{ic|/etc/php/php.ini}} if necessary:
 +
open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/
  
 
===Apache===
 
===Apache===
Copy the example Apache configuration file to your Apache configuration directory:
+
{{Note|The following works (at least no obvious problems) with Apache 2.4 and php-apache/mod_mpm_prefork or php-fpm/mod_proxy_handler}}
# /etc/webapps/phpmyadmin/apache.example.conf /etc/httpd/conf/extra/httpd-phpmyadmin.conf
+
 
 +
Set up Apache to use php as outlined in the [[LAMP#PHP|LAMP]] article.
 +
 
 +
Create the Apache configuration file:
 +
{{hc|/etc/httpd/conf/extra/phpmyadmin.conf|<nowiki>
 +
Alias /phpmyadmin "/usr/share/webapps/phpMyAdmin"
 +
<Directory "/usr/share/webapps/phpMyAdmin">
 +
    DirectoryIndex index.php
 +
    AllowOverride All
 +
    Options FollowSymlinks
 +
    Require all granted
 +
</Directory>
 +
</nowiki>}}
  
 
And include it in {{ic|/etc/httpd/conf/httpd.conf}}:
 
And include it in {{ic|/etc/httpd/conf/httpd.conf}}:
 
  # phpMyAdmin configuration
 
  # phpMyAdmin configuration
  Include conf/extra/httpd-phpmyadmin.conf
+
  Include conf/extra/phpmyadmin.conf
  
By default, everyone can see the phpMyAdmin page, to change this, edit {{ic|/etc/httpd/conf/extra/httpd-phpmyadmin.conf}} to your liking. For example, if you only want to be able to access it from the same machine, replace {{ic|Allow from all}} by {{ic|Allow from localhost}}.
+
{{note|By default, everyone who can reach the Apache Web Server can see the phpMyAdmin login page under this URL. To change this, edit {{ic|/etc/httpd/conf/extra/phpmyadmin.conf}} to your liking. For example, if you only want to be able to access it from the same machine, replace {{ic|Require all granted}} by {{ic|Require local}}. Beware that this will disallow connecting to PhpMyAdmin on a remote server.}}
  
===PHP===
+
===Lighttpd===
You need to enable the {{ic|mysqli}} and {{ic|mcrypt}} (if you want phpMyAdmin internal authentication) extensions in PHP by editing {{ic|/etc/php/php.ini}} and uncommenting the following lines:
+
Configuring Lighttpd is similar to Apache. Make sure Lighttpd is setup to serve PHP files (see [[Lighttpd]]).
extension=mysqli.so
+
 
  extension=mcrypt.so
+
Make an alias for phpmyadmin in your Lighttpd config.
 +
  alias.url = ( "/phpmyadmin" => "/usr/share/webapps/phpMyAdmin/")
 +
Then enable mod_alias, mod_fastcgi and mod_cgi in your config ( server.modules section )
 +
 
 +
Restart Lighttpd and go to [http://localhost/phpmyadmin/].
 +
 
 +
===Nginx===
 +
 
 +
==== Option 1: subdomain ====
 +
 
 +
Using this method, you'll access PhpMyAdmin as {{ic|phpmyadmin.<domain>}}.
 +
 
 +
Configurating Nginx is similar to Apache (and Lighttpd, for that matter). Make sure Nginx is setup to serve PHP files (see [[Nginx]]).
 +
 
 +
You can setup a sub domain (or domain) with a server block like so (if using php-fpm):
 +
 
 +
  server {
 +
          server_name    phpmyadmin.<domain.tld>;
 +
 
 +
          root    /usr/share/webapps/phpMyAdmin;
 +
          index  index.php;
 +
 
 +
          location ~ \.php$ {
 +
                  try_files      $uri =404;
 +
                  fastcgi_pass  unix:/run/php-fpm/php-fpm.sock;
 +
                  fastcgi_index  index.php;
 +
                  include        fastcgi.conf;
 +
          }
 +
  }
 +
 
 +
To access this url on your localhost, you can simply add an entry in /etc/hosts:
 +
  127.0.0.1 phpmyadmin.<domain.tld>
 +
 
 +
You need to update PHP's open_basedir option to add the appropriate directories.
 +
Either in /etc/php/php.ini:
 +
  open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/
 +
 
 +
Or if running php-fpm with a separate entry for phpmyadmin, you can overwrite this value in your pool definition (in /etc/php/fpm.d/<pool file>):
 +
  php_admin_value[open_basedir] = /tmp/:/usr/share/webapps/:/etc/webapps/
 +
 
 +
If the above doesn't fix it try adding the following to your NGINX Configuration below the other fastcgi_param (I think its something to do with the Suhosin-Patch)
 +
  fastcgi_param  PHP_ADMIN_VALUE  open_basedir="/srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/";
 +
 
 +
While you can enter anything for the blowfish password, you may want to choose a randomly generated string of characters (most likely for security reasons). Here's a handy tool that will do that for you on the web[http://www.question-defense.com/tools/phpmyadmin-blowfish-secret-generator].
 +
 
 +
When using SSL, you might run into the problem that the links on the pages generated by phpMyAdmin incorrectly start with "http" instead of "https" which may cause errors. To fix this, you can add the following fcgi_param to your SSL-enabled server section (in addition to your usual fastcgi params):
 +
  fastcgi_param HTTPS on;
 +
 
 +
==== Option 2: subdirectory ====
 +
 
 +
Using this method, you'll access PhpMyAdmin as {{ic|localhost/phpmyadmin}}, similarly to Apache.
 +
 
 +
=== Symlink Method ===
 +
 
 +
To get PhpMyAdmin working with your [[nginx]] setup, first take note of the root of the server you want to use. Supposing it is {{ic|/srv/http}}, now create a symlink:
 +
 
 +
  # ln -s /usr/share/webapps/phpMyAdmin/ /srv/http/phpmyadmin
 +
 
 +
=== Alias Method ===
 +
 
 +
If for some reason you are unable to create a symlink in the root of the server or would just rather use an alias, you can use this example configuration.
 +
  location /phpmyadmin {
 +
          alias /usr/share/webapps/phpMyAdmin;
 +
          # Optionally set separate access and error logs for phpMyAdmin
 +
          access_log /var/log/nginx/phpmyadmin_access.log;
 +
          error_log /var/log/nginx/phpmyadmin_error.log;
 +
          index  index.php;  
 +
          try_files $uri $uri/=404;
 +
          # Deny some static files
 +
          location ~ ^/phpmyadmin/(README|LICENSE|ChangeLog|DCO)$ {
 +
                  deny all;
 +
          }
 +
          # Deny .md files
 +
          location ~ ^/phpmyadmin/(.+\.md)$ {
 +
                  deny all;
 +
          }
 +
          # Deny some directories
 +
          location ~ ^/phpmyadmin/(doc|sql|setup)/ {
 +
                  deny all;
 +
          }
 +
          #FastCGI config for PhpMyAdmin
 +
          location ~ /phpmyadmin/(.+\.php)$ {
 +
                  fastcgi_param  SCRIPT_FILENAME /usr/share/webapps/phpMyAdmin/$1;
 +
                  fastcgi_pass  unix:/run/php-fpm/php-fpm.sock;
 +
                  fastcgi_index  index.php;
 +
                  include        fastcgi.conf;
 +
          }
 +
  }
  
===phpMyAdmin configuration===
+
==phpMyAdmin configuration==
phpMyAdmin's configuration file is located at {{ic|/etc/webapps/phpmyadmin/config.php}}. If you have a local MySQL server, it should be usable without making any modifications.
+
phpMyAdmin's configuration file is located at {{ic|/etc/webapps/phpmyadmin/config.inc.php}}. If you have a local MySQL server, it should be usable without making any modifications.
  
 
If your MySQL server is not on the localhost, uncomment and edit the following line:
 
If your MySQL server is not on the localhost, uncomment and edit the following line:
 
  $cfg['Servers'][$i]['host'] = 'localhost';
 
  $cfg['Servers'][$i]['host'] = 'localhost';
  
If you would like to use phpMyAdmin setup script by calling http://localhost/phpmyadmin/setup you will need to create a config directory that's writeable by the ''httpd'' user in {{ic|/usr/share/webapps/phpmyadmin}} as follows:
+
If you would like to use phpMyAdmin setup script by calling http://localhost/phpmyadmin/setup you will need to create a config directory that's writeable by the ''httpd'' user in {{ic|/usr/share/webapps/phpMyAdmin}} as follows:
 
  # cd /usr/share/webapps/phpMyAdmin
 
  # cd /usr/share/webapps/phpMyAdmin
 
  # mkdir config
 
  # mkdir config
Line 48: Line 157:
 
  ERROR: The configuration file now needs a secret passphrase (blowfish_secret)
 
  ERROR: The configuration file now needs a secret passphrase (blowfish_secret)
  
You need to add a blowfish password to the phpMyAdmin's config file. Edit {{ic|/etc/webapps/phpmyadmin/config.inc.php}} and insert a random blowfish "password" in the line
+
You need to add a unique password for the blowfish algorithm (which is used by phpMyAdmin to secure the authentication procedure) between the following {{ic|<nowiki>''</nowiki>}}. You can use any password generator for that matter, a key length of 32 is recommended.
  
$cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
+
{{hc|1=/etc/webapps/phpmyadmin/config.inc.php|2=$cfg['blowfish_secret'] = <nowiki>''</nowiki>; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */}}
 
+
Go [http://www.question-defense.com/tools/phpmyadmin-blowfish-secret-generator here] to get a nicely generated blowfish_secret and paste it between the '' marks. It should now look something like this:
+
+
$cfg['blowfish_secret'] = 'qtdRoGmbc9{8IZr323xYcSN]0s)r$9b_JUnb{~Xz'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
+
  
 
The error should go away if you refresh the phpmyadmin page.
 
The error should go away if you refresh the phpmyadmin page.
Line 75: Line 180:
 
/* Storage database and tables */
 
/* Storage database and tables */
 
// $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
 
// $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
// $cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark';
+
// $cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
// $cfg['Servers'][$i]['relation'] = 'pma_relation';
+
// $cfg['Servers'][$i]['relation'] = 'pma__relation';
// $cfg['Servers'][$i]['table_info'] = 'pma_table_info';
+
// $cfg['Servers'][$i]['table_info'] = 'pma__table_info';
// $cfg['Servers'][$i]['table_coords'] = 'pma_table_coords';
+
// $cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
// $cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages';
+
// $cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
// $cfg['Servers'][$i]['column_info'] = 'pma_column_info';
+
// $cfg['Servers'][$i]['column_info'] = 'pma__column_info';
// $cfg['Servers'][$i]['history'] = 'pma_history';
+
// $cfg['Servers'][$i]['history'] = 'pma__history';
// $cfg['Servers'][$i]['tracking'] = 'pma_tracking';
+
// $cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
// $cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords';
+
// $cfg['Servers'][$i]['tracking'] = 'pma__tracking';
// $cfg['Servers'][$i]['userconfig'] = 'pma_userconfig';
+
// $cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
// $cfg['Servers'][$i]['recent'] = 'pma_recent';
+
// $cfg['Servers'][$i]['recent'] = 'pma__recent';
 +
// $cfg['Servers'][$i]['favorite'] = 'pma__favorite';
 +
// $cfg['Servers'][$i]['users'] = 'pma__users';
 +
// $cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
 +
// $cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
 +
// $cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
 +
// $cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';
 +
// $cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
 +
// $cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';
 
}}
 
}}
  
Line 93: Line 206:
 
===== creating phpMyAdmin database =====
 
===== creating phpMyAdmin database =====
 
Using the phpMyAdmin web interface:
 
Using the phpMyAdmin web interface:
Import {{ic|/usr/share/webapps/phpMyAdmin/examples/create_tables.sql}} from phpMyAdmin -> Import.
+
Import {{ic|/usr/share/webapps/phpMyAdmin/sql/create_tables.sql}} from phpMyAdmin -> Import.
 
'''or'''
 
'''or'''
Using command line: {{ic|mysql -u root -p < /usr/share/webapps/phpMyAdmin/examples/create_tables.sql}}.
+
Using command line: {{ic|mysql -u root -p < /usr/share/webapps/phpMyAdmin/sql/create_tables.sql}}.
  
 
===== creating phpMyAdmin database user =====
 
===== creating phpMyAdmin database user =====
Now to apply the permissions to your controluser, in the SQL tab, make sure to replace all instances of 'pma' and 'pmapass' to the values set in config.inc.php. If you are setting this up for a remote database, then you must also change 'localhost' to the proper host:
+
Now to apply the permissions to your controluser, in the [[MySQL|SQL tab]], make sure to replace all instances of 'pma' and 'pmapass' to the values set in config.inc.php. If you are setting this up for a remote database, then you must also change 'localhost' to the proper host:
 
{{bc|
 
{{bc|
 
GRANT USAGE ON mysql.* TO 'pma'@'localhost' IDENTIFIED BY 'pmapass';
 
GRANT USAGE ON mysql.* TO 'pma'@'localhost' IDENTIFIED BY 'pmapass';
Line 121: Line 234:
  
 
==Accessing your phpMyAdmin installation==
 
==Accessing your phpMyAdmin installation==
Your phpMyAdmin installation is now complete. Before you start using it you need to [[Daemons#Restarting|restart]] httpd (Apache)
+
Your phpMyAdmin installation is now complete. Before you start using it you need to restart Apache.
  
 
You can access your phpMyAdmin installation by going to http://localhost/phpmyadmin/
 
You can access your phpMyAdmin installation by going to http://localhost/phpmyadmin/
  
==Lighttpd Configuration==
+
== Troubleshooting ==
Configurating Lighttpd is similar to Apache. Make sure Lighttpd is setup to serve PHP files (see [[Lighttpd]]).
+
  
Make an alias for phpmyadmin in your Lighttpd config.
+
=== Fixing open_basedir warning ===
  alias.url = ( "/phpmyadmin" => "/usr/share/webapps/phpMyAdmin/")
+
Then enable mod_alias, mod_fastcgi and mod_cgi in your config ( server.modules section )
+
  
Update open_basedir in /etc/php/php.ini and add "/usr/share/webapps/".
+
If you see the following Warning when entering the homepage of PhpMyAdmin:
  open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/
+
  
Restart Lighttpd and go to [http://localhost/phpmyadmin/].
+
{{bc|
 +
Warning in ./libraries/Config.class.php#1147
 +
file_exists(): open_basedir restriction in effect. File(./config.inc.php) is not within the allowed path(s): (/srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/)
 +
}}
  
==Nginx Configuration==
+
It means that phpmyadmin was not able to find where the {{ic|config.inc.php}} file is located.
Configurating Nginx is similar to Apache (and Lighttpd, for that matter). Make sure Nginx is setup to serve PHP files (see [[Nginx]]).
+
  
You can setup a sub domain (or domain) with a server block like so (if using php-fpm):
+
In order to fix that, you need to indicate the path in {{ic|/etc/php/php.ini}} of the {{ic|phpmyadmin}} directory containing the file, which should be {{ic|/etc/webapps}}, putting it at the end of the paths separated with a {{ic|:}} in the {{ic|open_basedir}} variable:
  
  server {
+
{{hc|head=/etc/php/php.ini|
          server_name    phpmyadmin.<domain.tld>;
+
output=open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/''':/etc/webapps/'''
 
+
}}
          root    /usr/share/webapps/phpMyAdmin;
+
          index  index.php;
+
 
+
          location ~ \.php$ {
+
                  try_files      $uri =404;
+
                  fastcgi_pass  unix:/var/run/php-fpm/php-fpm.sock;
+
                  fastcgi_index  index.php;
+
                  include        fastcgi.conf;
+
          }
+
  }
+
  
To access this url on your localhost, you can simply add an entry in /etc/hosts:
+
Once you have done that, [[restart]] {{ic|httpd.service}}.
  127.0.0.1 phpmyadmin.<domain.tld>
+
  
You need to update PHP's open_basedir option to add the appropriate directories.
+
Now refresh the page, and you should no longer have the warning.
Either in /etc/php/php.ini:
+
  open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/
+
  
Or if running php-fpm with a separate entry for phpmyadmin, you can overwrite this value in your pool definition (in /etc/php/fpm.d/<pool file>):
+
=== #2006 - MySQL server has gone away ===
  php_admin_value[open_basedir] = /tmp/:/usr/share/webapps/:/etc/webapps/
+
  
If the above doesn't fix it try adding the following to your NGINX Configuration below the other fastcgi_param (I think its something to do with the Suhosin-Patch)
+
If, when trying to log into PhpMyAdmin, you encounter
  fastcgi_param  PHP_ADMIN_VALUE  open_basedir="/srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/";
+
#2006 - MySQL server has gone away
 +
 +
Connection for controluser as defined in your configuration failed.
 +
a fix seems to be to make sure you do not have SSL connection between PhpMyAdmin and MariaDB activated. Hence comment out or set to {{ic|false}} the following line:
 +
{{hc|1=/etc/webapps/phpmyadmin/config.inc.php|2=
 +
$cfg['Servers'][$i]['ssl'] = true;
 +
}}
  
While you can enter anything for the blowfish password, you may want to choose a randomly generated string of characters (most likely for security reasons). Here's a handy tool that will do that for you on the web[http://www.question-defense.com/tools/phpmyadmin-blowfish-secret-generator].
+
{{Note|1=There surely must be a better fix since 'ssl = true' worked before. Also do not disable SSL if your PhpMyAdmin install is somehow not on the same server as MySQL!}}
 
+
When using SSL, you might run into the problem that the links on the pages generated by phpMyAdmin incorrectly start with "http" instead of "https" which may cause errors. To fix this, you can add the following fcgi_param to your SSL-enabled server section (in addition to your usual fastcgi params):
+
  fastcgi_param HTTPS on;
+

Latest revision as of 06:08, 6 April 2016

phpMyAdmin is a web-based tool to help manage MySQL databases using an Apache/PHP frontend. It requires a working LAMP setup.

Installation

Install the phpmyadmin and php-mcrypt packages from the official repositories.

Configuration

PHP

You need to enable the mysqli and mcrypt (if you want phpMyAdmin internal authentication) extensions in PHP by editing /etc/php/php.ini and uncommenting the following lines:

extension=mysqli.so
extension=mcrypt.so

Optionally you can enable bz2.so and zip.so for compression support.

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: open_basedir is no longer set by default, in fact it may cause a server error if set. (Discuss in Talk:PhpMyAdmin#)

You need to make sure that PHP can access /etc/webapps. Add it to open_basedir in /etc/php/php.ini if necessary:

open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/

Apache

Note: The following works (at least no obvious problems) with Apache 2.4 and php-apache/mod_mpm_prefork or php-fpm/mod_proxy_handler

Set up Apache to use php as outlined in the LAMP article.

Create the Apache configuration file:

/etc/httpd/conf/extra/phpmyadmin.conf
Alias /phpmyadmin "/usr/share/webapps/phpMyAdmin"
<Directory "/usr/share/webapps/phpMyAdmin">
    DirectoryIndex index.php
    AllowOverride All
    Options FollowSymlinks
    Require all granted
</Directory>

And include it in /etc/httpd/conf/httpd.conf:

# phpMyAdmin configuration
Include conf/extra/phpmyadmin.conf
Note: By default, everyone who can reach the Apache Web Server can see the phpMyAdmin login page under this URL. To change this, edit /etc/httpd/conf/extra/phpmyadmin.conf to your liking. For example, if you only want to be able to access it from the same machine, replace Require all granted by Require local. Beware that this will disallow connecting to PhpMyAdmin on a remote server.

Lighttpd

Configuring Lighttpd is similar to Apache. Make sure Lighttpd is setup to serve PHP files (see Lighttpd).

Make an alias for phpmyadmin in your Lighttpd config.

 alias.url = ( "/phpmyadmin" => "/usr/share/webapps/phpMyAdmin/")

Then enable mod_alias, mod_fastcgi and mod_cgi in your config ( server.modules section )

Restart Lighttpd and go to [1].

Nginx

Option 1: subdomain

Using this method, you'll access PhpMyAdmin as phpmyadmin.<domain>.

Configurating Nginx is similar to Apache (and Lighttpd, for that matter). Make sure Nginx is setup to serve PHP files (see Nginx).

You can setup a sub domain (or domain) with a server block like so (if using php-fpm):

 server {
         server_name     phpmyadmin.<domain.tld>;
 
         root    /usr/share/webapps/phpMyAdmin;
         index   index.php;
 
         location ~ \.php$ {
                 try_files      $uri =404;
                 fastcgi_pass   unix:/run/php-fpm/php-fpm.sock;
                 fastcgi_index  index.php;
                 include        fastcgi.conf;
         }
 }

To access this url on your localhost, you can simply add an entry in /etc/hosts:

 127.0.0.1	phpmyadmin.<domain.tld>

You need to update PHP's open_basedir option to add the appropriate directories. Either in /etc/php/php.ini:

 open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/

Or if running php-fpm with a separate entry for phpmyadmin, you can overwrite this value in your pool definition (in /etc/php/fpm.d/<pool file>):

 php_admin_value[open_basedir] = /tmp/:/usr/share/webapps/:/etc/webapps/

If the above doesn't fix it try adding the following to your NGINX Configuration below the other fastcgi_param (I think its something to do with the Suhosin-Patch)

 fastcgi_param  PHP_ADMIN_VALUE  open_basedir="/srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/";

While you can enter anything for the blowfish password, you may want to choose a randomly generated string of characters (most likely for security reasons). Here's a handy tool that will do that for you on the web[2].

When using SSL, you might run into the problem that the links on the pages generated by phpMyAdmin incorrectly start with "http" instead of "https" which may cause errors. To fix this, you can add the following fcgi_param to your SSL-enabled server section (in addition to your usual fastcgi params):

 fastcgi_param HTTPS on;

Option 2: subdirectory

Using this method, you'll access PhpMyAdmin as localhost/phpmyadmin, similarly to Apache.

Symlink Method

To get PhpMyAdmin working with your nginx setup, first take note of the root of the server you want to use. Supposing it is /srv/http, now create a symlink:

 # ln -s /usr/share/webapps/phpMyAdmin/ /srv/http/phpmyadmin

Alias Method

If for some reason you are unable to create a symlink in the root of the server or would just rather use an alias, you can use this example configuration.

 location /phpmyadmin {
         alias /usr/share/webapps/phpMyAdmin;
         # Optionally set separate access and error logs for phpMyAdmin
         access_log /var/log/nginx/phpmyadmin_access.log;
         error_log /var/log/nginx/phpmyadmin_error.log;
         index   index.php;  
         try_files $uri $uri/=404;
         # Deny some static files
         location ~ ^/phpmyadmin/(README|LICENSE|ChangeLog|DCO)$ {
                 deny all;
         }
         # Deny .md files
         location ~ ^/phpmyadmin/(.+\.md)$ {
                 deny all;
         }
         # Deny some directories
         location ~ ^/phpmyadmin/(doc|sql|setup)/ {
                 deny all;
         }
         #FastCGI config for PhpMyAdmin
         location ~ /phpmyadmin/(.+\.php)$ {
                 fastcgi_param  SCRIPT_FILENAME /usr/share/webapps/phpMyAdmin/$1;
                 fastcgi_pass   unix:/run/php-fpm/php-fpm.sock;
                 fastcgi_index  index.php;
                 include        fastcgi.conf;
         }
 }

phpMyAdmin configuration

phpMyAdmin's configuration file is located at /etc/webapps/phpmyadmin/config.inc.php. If you have a local MySQL server, it should be usable without making any modifications.

If your MySQL server is not on the localhost, uncomment and edit the following line:

$cfg['Servers'][$i]['host'] = 'localhost';

If you would like to use phpMyAdmin setup script by calling http://localhost/phpmyadmin/setup you will need to create a config directory that's writeable by the httpd user in /usr/share/webapps/phpMyAdmin as follows:

# cd /usr/share/webapps/phpMyAdmin
# mkdir config
# chgrp http config
# chmod g+w config

Add blowfish_secret passphrase

If you see the following error message at the bottom of the page when you first log in to /phpmyadmin (using a previously setup MySQL username and password) :

ERROR: The configuration file now needs a secret passphrase (blowfish_secret)

You need to add a unique password for the blowfish algorithm (which is used by phpMyAdmin to secure the authentication procedure) between the following ''. You can use any password generator for that matter, a key length of 32 is recommended.

/etc/webapps/phpmyadmin/config.inc.php
$cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

The error should go away if you refresh the phpmyadmin page.

Enabling Configuration Storage (optional)

Now that the basic database server has been setup, it is functional, however by default, extra options such as table linking, change tracking, PDF creation, and bookmarking queries are disabled. You will see a message at the bottom of the main phpMyAdmin page, "The phpMyAdmin configuration storage is not completely configured, some extended features have been deactivated. To find out why...", This section addresses how to to enable these extra features.

Note: This example assumes you want to use the username pma as the controluser, and pmapass as the controlpass. These should be changed (the very least, you should change the password!) to something more secure.

In /etc/webapps/phpmyadmin/config.inc.php, uncomment (remove the leading "//"s on) these two lines, and change them to your desired credentials:

// $cfg['Servers'][$i]['controluser'] = 'pma';
// $cfg['Servers'][$i]['controlpass'] = 'pmapass';

You will need this information later, so keep it in mind.

Beneath the controluser setup section, uncomment these lines:

/* Storage database and tables */
// $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
// $cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
// $cfg['Servers'][$i]['relation'] = 'pma__relation';
// $cfg['Servers'][$i]['table_info'] = 'pma__table_info';
// $cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
// $cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
// $cfg['Servers'][$i]['column_info'] = 'pma__column_info';
// $cfg['Servers'][$i]['history'] = 'pma__history';
// $cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
// $cfg['Servers'][$i]['tracking'] = 'pma__tracking';
// $cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
// $cfg['Servers'][$i]['recent'] = 'pma__recent';
// $cfg['Servers'][$i]['favorite'] = 'pma__favorite';
// $cfg['Servers'][$i]['users'] = 'pma__users';
// $cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
// $cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
// $cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
// $cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';
// $cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
// $cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';

Next, create the user with the above details. Don't set any permissions for it just yet.

Note: If you can't login to phpmyadmin, make sure that your mysql server is started.
creating phpMyAdmin database

Using the phpMyAdmin web interface: Import /usr/share/webapps/phpMyAdmin/sql/create_tables.sql from phpMyAdmin -> Import. or Using command line: mysql -u root -p < /usr/share/webapps/phpMyAdmin/sql/create_tables.sql.

creating phpMyAdmin database user

Now to apply the permissions to your controluser, in the SQL tab, make sure to replace all instances of 'pma' and 'pmapass' to the values set in config.inc.php. If you are setting this up for a remote database, then you must also change 'localhost' to the proper host:

GRANT USAGE ON mysql.* TO 'pma'@'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 'pma'@'localhost';
GRANT SELECT ON mysql.db TO 'pma'@'localhost';
GRANT SELECT ON mysql.host TO 'pma'@'localhost';
GRANT SELECT (Host, Db, User, Table_name, Table_priv, Column_priv)
    ON mysql.tables_priv TO 'pma'@'localhost';

In order to take advantage of the bookmark and relation features, you will also need to give pma some additional permissions:

Note: as long as you did not change the value of $cfg['Servers'][$i]['pmadb'] in /etc/webapps/phpmyadmin/config.inc.php, then <pma_db> should be phpmyadmin
GRANT SELECT, INSERT, UPDATE, DELETE ON <pma_db>.* TO 'pma'@'localhost';

Log out, and back in to ensure the new features are activated. The message at the bottom of the main screen should now be gone.

Accessing your phpMyAdmin installation

Your phpMyAdmin installation is now complete. Before you start using it you need to restart Apache.

You can access your phpMyAdmin installation by going to http://localhost/phpmyadmin/

Troubleshooting

Fixing open_basedir warning

If you see the following Warning when entering the homepage of PhpMyAdmin:

Warning in ./libraries/Config.class.php#1147
file_exists(): open_basedir restriction in effect. File(./config.inc.php) is not within the allowed path(s): (/srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/)

It means that phpmyadmin was not able to find where the config.inc.php file is located.

In order to fix that, you need to indicate the path in /etc/php/php.ini of the phpmyadmin directory containing the file, which should be /etc/webapps, putting it at the end of the paths separated with a : in the open_basedir variable:

/etc/php/php.ini
open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/

Once you have done that, restart httpd.service.

Now refresh the page, and you should no longer have the warning.

#2006 - MySQL server has gone away

If, when trying to log into PhpMyAdmin, you encounter

#2006 - MySQL server has gone away

Connection for controluser as defined in your configuration failed.

a fix seems to be to make sure you do not have SSL connection between PhpMyAdmin and MariaDB activated. Hence comment out or set to false the following line:

/etc/webapps/phpmyadmin/config.inc.php
$cfg['Servers'][$i]['ssl'] = true;
Note: There surely must be a better fix since 'ssl = true' worked before. Also do not disable SSL if your PhpMyAdmin install is somehow not on the same server as MySQL!