I use XAMPP for windows (Apache, MySQL and PHP) on my dev machine. Recently I made
htdocs public. This runs the dashboard by default. Obviously, this is a big
security hole. Here is a guide on how to fix this. My path to XAMPP's htdocs is
F:\xampps
. I am going to use $X
to represent this. You need to substitute your path.
In the directory $X\htdocs
is index.php
which invokes
dashboard
using the PHP header
command. Replace this to
whatever you would like to display. On my PC, I am displaying a list of all the
websites that I am working on. You may chose to leave it as is, so that it still runs
dashboard
.
I am protecting the $X\htdocs\dashboard
directory. But you can protect
any directory. There are two parts to this :
The first task is to find a program that will do the work for you. This is
htpasswd.exe
and here are the steps :
cmd.exe
. You can do this using WIN+R
and typing in cmd.exe.htpasswd is the name of the new password file. In this example it will create
it in the bin
directory. It should not be under htdocs
. You
can put in whatever directory and file name you like.
-c creates a new file.
-b accepts the password from the command line. If you omit it, you will be asked twice to enter the password to confirm.
user is whatever username you want. It is best to not use admin.
password is whatever password you want. It is best to make this complex.
I did not need to restart Apache for this to work. You may need to restart for this to take effect.
The second task is to protect the directory. I am protecting the
$X/htdocs/dashboard
directory. But you can protect any directory.
This is achieved by creating a file .htaccess
in that directory.
$X\dashboard
directory..htaccess
is missing then create a new text file.
AuthName "Protected $X\apache\htdocs\dashboard"
AuthType Basic
AuthUserFile $X\apache\bin\.htpasswd
Require valid-user
.htaccess
Forward slashes work for me. On your system, they may need to be backslashes.
AuthUserFile should be the location of the password file you just created. I am using an absolute path, it could be relative.
AuthName is quoted and contains the protected directory name. I have shown it
as an absolute path. Just dashboard
works for me.
If you have multiple users in the password files, then any of those users can gain access using their own passwords.