Skip to content

Instantly share code, notes, and snippets.

@dipanshuchaubey
Created February 3, 2020 16:34
Show Gist options
  • Save dipanshuchaubey/fb205618514f2efbcb3bd4d2c761dd31 to your computer and use it in GitHub Desktop.
Save dipanshuchaubey/fb205618514f2efbcb3bd4d2c761dd31 to your computer and use it in GitHub Desktop.
Run phpMyAdmin on a custom port

Run phpMyAdmin On Custom Port

1. Make a virtual host for phpmyadmin

In /etc/apache2/sites-available/ directory create a new file named phpmyadmin.conf

$ sudo nano phpmyadmin.conf

The content of the file should be:

Listen 2222

<VirtualHost *:2222>

        ServerName localhost

        <Directory /usr/share/phpmyadmin>
                AllowOverride None
                Require all granted
        </Directory>

        DocumentRoot /usr/share/phpmyadmin

        Include /etc/phpmyadmin/apache.conf

        ErrorLog ${APACHE_LOG_DIR}/phpmyadmin.error.log
        CustomLog ${APACHE_LOG_DIR}/phpmyadmin.access.log combined

</VirtualHost>

2. Reset apache config and restart server

Disable the /etc/apache2/conf-enabled/phpmyadmin.conf file due to which phpmyadmin is accessible from any domain on apache using the command:

sudo a2disconf phpmyadmin

Now, enable the new config that we create at /etc/apache2/sites-available/phpmyadmin.conf

sudo a2ensite phpmyadmin

Restart the server

sudo systemctl restart apache2.service

3. Optional step

Go to /etc/phpmyadmin/apache.conf directory and comment out the Alias so that phpmyadmin should not provide identical results for both localhost:port/phpmyadmin and localhost/phpmyadmin

#Alias /phpmyadmin /usr/share/phpmyadmin

After commenting out the above mentioned line phpmyadmin will only be accessible using port.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment