[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 ]

#!/bin/bash

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

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

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

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

    -G

    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 :)

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>