How to use SSH tunnel to access phpMyAdmin

| By Manoj Thakur

Server Side:

  1. ssh to your remote machine
  2. Block direct access to your PHPMyAdmin and allow it for localhost only.
    If you have a standalone PHPMyAdmin then go to the apache configuration file and add the following lines.
    #Restricted the Access to phpMyAdmin
    <Directory /var/www/html/project/path-to/phpMyAdmin>
    Order Deny,Allow
    Deny from all
    Allow from localhost

    If you have installed the PHPMyAdmin then add lines I mentioned below in “PHPMyAdmin.conf” file, I mentioned the absolute path below.
    #Restricted Access to phpMyAdmin
    Order Allow,Deny
    Allow from localhost
    Path: /etc/apache2/conf-available/phpmyadmin.conf

  3. However, we can still connect to our database via the SSH tunnel approach, as I have mentioned in the steps below in the section.

Client Side:

  1. The user would create an SSH session for a specific server. For instance, if my server’s host IP is, I’ll do the following course of action.
    • ssh -L 8900:localhost:80 user@, run this command on the client side(Local system)
    • login with your SSH password
    • Once logged in, you can access phpMyAdmin locally via … http://localhost:8900/phpmyadmin

Leave a Reply

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