[Ubuntu] Disable or enable access to phpmyadmin in apache http server

Most time ‘phpmyadmin’ doesn’t have to be on the web and it can be a huge security risk if someone obtains an adminstor.of the ‘phpmyadmin’

To simply avoid this, one could control access to phpmyadmin with the following script.


sudo nano /usr/bin/adminphp


[ paste the following script ]


currentdir=`echo $PWD`

if [ "$1" = "up" ];then
  cd /etc/apache2/conf.d/
  ln -s -T /etc/phpmyadmin/apache.conf phpmyadmin.conf
  service apache2 reload
else if [ "$1" = "down" ];then
  rm /etc/apache2/conf.d/phpmyadmin.conf
  service apache2 reload

    rm /etc/apache2/conf.d/phpmyadmin.conf
    service apache2 reload

cd `echo "$currentdir"`

exit 0


then make the file excutable


sudo adminphp up

This ables access to phpmyadmin

sudo adminphp down

This disables access to phpmyadmin

sudo adminphp

This also disables access to phpmyadmin



Basically this script removes the simbolic link of the apache configuration file for phpmyadmin if a server administor wants to disable access to phpmyadmin (gives 404 Not Found error message).

And creates a link to the configuration file if the administor wants to enable access

11 thoughts on “[Ubuntu] Disable or enable access to phpmyadmin in apache http server

    1. It looks like the phpmyadmin in your server isn’t installed at ‘/etc/phpmyadmin/’

      You gotta find the phpmyadmin directory in the server and change the location of the symbolic link target(apache.conf in your phpmyadmin directory) in ‘ln -s -T /etc/phpmyadmin/apache.conf phpmyadmin.conf’

      In my understanding, the symbolic link is created from the script above but the created link ‘/etc/apache2/conf.d/phpmyadmin.conf’ is pointing nowhere because ‘/etc/phpmyadmin/apache.conf’ doesn’t exist; and therefore the apache server does nothing

      I guess ‘locate apache.conf’ may help you to find the phpmyadmin directory

  1. I don’t see why the else if is needed if you are going to have an blanket else for anything that isn’t “up.” Also, I would recommend a service reload instead of restart since it is just a config change. Thanks for the script though! Was going to write one myself, but this saved sometime.


    1. Because ‘else’ part is added after I got tired of typing ‘down’ at the end of command.

      And the post has been changed as you suggested

  2. thanks a bunch, i change “up” to “start” and “down” to “stop” (like services) so it will be more easier to remember :)

  3. Hi, the script is not working for me, it seems like there is no folder in /etc/apache2/ named config.d. What should I do?

    1. I don’t know which version of Ubuntu you are using, but in Ubuntu 14.04 LTS, there are commands (a2enconf / a2disconf) you can enable or disable an apache2 configuration file.
      Since the phpmyadmin webpage is configured by the apache2 configuration file, which is at /etc/apache2/conf-available/phpmyadmin.conf, you can simply disable it by entering

      sudo a2disconf phpmyadmin

      in your terminal

      to enable phpmyadmin

      sudo a2enconf phpmyadmin

      Hope this works for you

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>