How to Change phpMyAdmin Port from 80 to Another Number
16.04Apache2phpmyadmin
How to change phpMyAdmin port from 80 to 99?
Best Answer
Just to be clear, this is not a setting of PhpMyAdmin, it is a setting of the configuration of Apache2, and we need to create new VirtualHost for this purpose.
1. Understanding of the default configuration of PhpMyAdmin. By default (within Ubuntu 16.04) PhpMyAdmin is included (and enabled) into the Apache's configuration (for all VirtualHosts!) through this additional configuration file:
/etc/apache2/conf-enabled/phpmyadmin.conf
This file is a symbolic link to the file /etc/apache2/conf-available/phpmyadmin.conf, which is a symbolic link to the file /etc/phpmyadmin/apache.conf, which will be used in the next step.
2. Create new VirtualHost configuration file. Let's call it phpmyadmin.conf and create it by nano (or you can use your favorite text editor):
ServerName localhost this directive is optional and can be customised according to your needs. (Usually there have ServerName set on the Server level - in /etc/apache2/apache2.conf);
DocumentRoot /usr/share/phpmyadmin this directive sets /usr/share/phpmyadmin as directory that forms the main document tree visible from the web, for the current VirtualHost;
Include /etc/phpmyadmin/apache.conf this directive includes the default phpMyAdmin's configuration into Apache's configuration. Thus /etc/phpmyadmin/apache.conf will be included only for the current VirtualHost! Instead of this directive you can copy/paste the content of /etc/phpmyadmin/apache.conf in this place.
a2disconf phpmyadmin will disable the default phpMyAdmin's configuration, described in 1.
a2ensite phpmyadmin will enable the new VirtualHost, described in 2.
!!. Edit /etc/phpmyadmin/apache.conf and comment (#) the first Alias directive like thath:
#Alias /phpmyadmin /usr/share/phpmyadmin
This step is optional, but otherwise http://localhost:99 and http://localhost:99/phpmyadmin will provide identical result, so I suppose we do not need that :)
!!. If you want this new VirtualHost to be accessible from the outside don't forget to add port 99 into your firewall's rules. If you use UFW you can do that by this command:
Even though Rahul's answer is correct, I'd suggest a slightly different approach. After you've installed apache2 and phpmyadmin using apt-get, do this:
The benefit of my approach is that you won't have to resolve configuration conflicts when you upgrade Apache. You need Apache 2.4 though, which is included in the repositories of Ubuntu 14.04.
Edit: Also, the message about the fully qualified domain name has nothing to do with this. Don't worry, unless you're actually setting up a site which needs a domain name.
Best Answer
Just to be clear, this is not a setting of PhpMyAdmin, it is a setting of the configuration of Apache2, and we need to create new VirtualHost for this purpose.
1. Understanding of the default configuration of PhpMyAdmin. By default (within Ubuntu 16.04) PhpMyAdmin is included (and enabled) into the Apache's configuration (for all VirtualHosts!) through this additional configuration file:
This file is a symbolic link to the file
/etc/apache2/conf-available/phpmyadmin.conf
, which is a symbolic link to the file/etc/phpmyadmin/apache.conf
, which will be used in the next step.2. Create new VirtualHost configuration file. Let's call it
phpmyadmin.conf
and create it bynano
(or you can use your favorite text editor):The content of this file should looks like:
Where:
Listen 99
instructs Apache2 to listen on port99
. Like @L.D.James says you can put this directive in/etc/apache2/ports.conf
or you can leave it here;<VirtualHost *:99>...</VirtualHost>
defines a VirtualHost which will handle the requests form all interfaces (*
) on port:99
.ServerName localhost
this directive is optional and can be customised according to your needs. (Usually there haveServerName
set on the Server level - in/etc/apache2/apache2.conf
);<Directory /usr/share/phpmyadmin>...</Directory>
this directive is optional because the access permissions for/usr/share/
are usually set in/etc/apache2/apache2.conf
. But you can add specific rules here, for example you canSet Up Password Authentication
;DocumentRoot /usr/share/phpmyadmin
this directive sets/usr/share/phpmyadmin
as directory that forms the main document tree visible from the web, for the current VirtualHost;Include /etc/phpmyadmin/apache.conf
this directive includes the default phpMyAdmin's configuration into Apache's configuration. Thus/etc/phpmyadmin/apache.conf
will be included only for the current VirtualHost! Instead of this directive you can copy/paste the content of/etc/phpmyadmin/apache.conf
in this place.3. Switch Apache's configuration and restart it.
Where:
a2disconf phpmyadmin
will disable the default phpMyAdmin's configuration, described in 1.a2ensite phpmyadmin
will enable the new VirtualHost, described in 2.!!. Edit
/etc/phpmyadmin/apache.conf
and comment (#
) the firstAlias
directive like thath:This step is optional, but otherwise
http://localhost:99
andhttp://localhost:99/phpmyadmin
will provide identical result, so I suppose we do not need that :)!!. If you want this new VirtualHost to be accessible from the outside don't forget to add port
99
into your firewall's rules. If you use UFW you can do that by this command:With iptables you can do that by this command: