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>
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
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.