Skip to main content

Installing phpMyAdmin in userspace

Installing phpMyAdmin in user space will come with severals benefits, including:

  • Allows for custom URLs.
  • Let's Encrypt SSL certificates
  • .htaccess Files for Basic Auth enablement and/or ip access restrictions

phpMyAdmin Installation

Download the latest version of phpMyAdmin from phpmyadmin.net/downloads and extract it to a folder of your choice:

Please adapt the version mentioned in the following example to the newest version available.

$ export VERSION=5.2.0
$ mkdir -p ~/phpmyadmin
$ cd ~/phpmyadmin
$ curl -O https://files.phpmyadmin.net/phpMyAdmin/$VERSION/phpMyAdmin-$VERSION-all-languages.tar.gz # download
$ tar -zxf phpMyAdmin-$VERSION-all-languages.tar.gz # extract

Create a symbolic link so that in the future you can easily update the phpMyAdmin installation without adjusting the webserver configuration:

$ ln -vsf phpMyAdmin-$VERSION-all-languages current

Create the virtual host

Using our tool nine-manage-vhosts, you can create a virtual host for phpMyAdmin. We reference the formerly created symbolic link:

$ sudo nine-manage-vhosts virtual-host create <YOUR.PHPMYADMIN-URL.HERE> --webroot=/home/www-data/phpmyadmin/current

Additional details about nine-manage-vhosts can be found in its own support articel.

Create a SSL certificate

We recommend to secure the web accesses to phpMyAdmin installations using a SSL certificate. On our "Managed Server" products you can use nine-manage-vhosts to use our Let's Encrypt integration. For details about the setup and usage of Let's Encrypt, check the corresponding support article.

If you would like to use your own, or a purchased SSL certificate for the site, please contact us for purchase and/or installation at Support.

Optional Access Restriction

Using a ".htaccess" file, the access to the newly created phpMyAdmin instance can be restricted.

Restrict by IP

To restrict access by static IP addresses, create ~/phpmyadmin/current/.htaccess:

Require ip 122.122.122.122
Require ip 123.123.123.123

Restrict with Basic Auth

To restrict access with basic auth, first create a user like so:

$ htpasswd -c ~/phpmyadmin/.htpasswd USERNAME

And then create ~/phpmyadmin/current/.htaccess:

AuthType Basic
AuthName "Restricted Content"
AuthUserFile /home/www-data/phpmyadmin/.htpasswd
Require valid-user

Configure phpMyAdmin

We recommend using a basic default configuration. To create it automatically, run the following command:

cat << EOF > ~/phpmyadmin/current/config.inc.php
<?php
\$cfg['blowfish_secret'] = '$(pwgen -1 -r "'" --symbols --secure 32 1)';

\$i=0;
\$i++;
\$cfg['Servers'][\$i]['auth_type'] = 'cookie';
EOF

The configuration file can be created either manually or via the built in setup URL (/setup).

Confirm setup

You may now access the login page at the base URL: https://YOUR.PHPMYADMIN-URL.HERE

From there you may login with any database user you have previously created using nine-manage-databases.

Keeping phpMyAdmin up to date

phpMyAdmin is periodically updated with new features, bug fixes, and security fixes.

In order to update your installation

  1. Download the new version according to the steps phpMyAdmin Installation and extract it beside your existing installation.

  2. Copy the configuration file you created or generated above to the new installation:

    $ cd ~/phpmyadmin
    $ cp current/config.inc.php phpMyAdmin-$VERSION-all-languages/
  3. Update the existing symbolic link to point to the new installation:

    $ cd ~/phpmyadmin
    $ ln -svf phpMyAdmin-$VERSION-all-languages current

Using this method, the webserver configuration can remain unchanged, and the new installations may be used immediately via the same URL. You should see the new version information on the phpMyAdmin dashboard after logging in.