..
In this short article we will see how to use Apache to restrict access to a folder to only users with a username and password.
To achieve our purpose we can simply resort to the usual. Htaccess file in combination with. Htpasswd.
First we set the contents of the file. Htaccess as follows:
AuthUserFile / home / sites / www.sito.com / private / .htpasswd AuthName "Protected Area" AuthType Basic Require valid-userIt 'very important to correctly specify the path to the AuthUserFile. Htpasswd file.
Now we see how to create the file. Htpasswd whose content should have the following syntax:
user1: password1_criptata user2: password2_criptata user3: password3_criptataTo create the file. Htpasswd can follow two paths:
1) if we have access to the shell of we make our server log on the machine and go to the folder where we create the file in question:
cd / home / sites / www.sito.com / private /and type:
htpasswd-c. htpasswd usernamenow the system will ask password to associate with this user, password, which will then need to confirm.
2) If you do not have access to the shell of the server you will need to use a little trick.
Basically we can create "by hand" our. Htpasswd file used by one of the many scripts and tools available on the Web Here are some links:
Because everything is working properly, of course, you must have. Htaccess file is in the same folder that you want to protect, but it is not necessary that you are in the same folder. Htpasswd (the important thing is that it is correctly indicated the path to get there) .
Now try to access the protected folder via http, if it works the web-server should return a logon prompt to insert the username and password.
| |
Linux (Course)
Complete guide to open-source system. From 49 €. |
| |
MySQL (Course)
Management of open-source database. From 39 €. |
| |
PHP (Course)
Full course for creating dynamic Web sites. From 49 €. |