In our website hosting activities, we must have encountered a situation where we need to put our
website under password protection to restrict the access.
We can make our website password protected using our apace web-server itself by adding few lines in the websites's web-server (apache) configuration file.
Step1: Make changes to apache configuration file:
Step2: After apache configuration file is updated, we need to create the AuthUserFile at the specified location, as per the above configuration, we need to create passwd file under /var/local/sites folder.
To create the password file use the below command:
htpasswd -c /var/local/sites/passwd nixvilla
where,
Step3: Now, we need to check the permission and the ownership of the AuthUserFile, in our case it is /var/local/sites/passwd.
ls -l /var/local/sites/passwd
using above command, we can check the permission and ownership.
Normally apache uses www-data user, so we need to change the ownership to www-data.
chown www-data:www-data /var/local/sites/passwd
chmod 0660 /var/local/sites/passwd
Step4: Now, we need to restart the apache process to make the changes reflected.
In debian based systems, like in Ubuntu:
"apache2ctl configtest" command will check the configuration error and will display error message else will show Syntax OK.
If Syntax is Ok then we can gracefully restart the apache.
sudo apache2ctl configtest
sudo apache2ctl graceful
In Redhat/CentOS:
We can use "apachectl configtest" to check the configuration issues. And if all configuration is Ok, we can restart the service:
sudo apachectl configtest
sudo apachectl graceful
Now, we can open our website to test the password protection. If everything goes right, website will ask the password using a password pop-up.
If any issue, we can troubleshoot by referring the error log, whose path is defined in apache configuration file.
tail -f /var/log/apache2/nixvilla-error.log/
Bazinga.... All Done !!
Many thanks for reading the article. Keep visiting and post your comments/suggestions/queries.
Happy New Year...
![]() |
| Password Protect Website |
We can make our website password protected using our apace web-server itself by adding few lines in the websites's web-server (apache) configuration file.
Step1: Make changes to apache configuration file:
In the below sample configuration file, you can make require changes as per your setup Like: we can change the document root path with our code-base location, in my case it is /var/www and website name is www.nixvilla.com.
![]() |
| Sample apache configuration file. |
Step2: After apache configuration file is updated, we need to create the AuthUserFile at the specified location, as per the above configuration, we need to create passwd file under /var/local/sites folder.
To create the password file use the below command:
htpasswd -c /var/local/sites/passwd nixvilla
where,
- -c : Create the password file, if exists then rewritten and truncated.
- nixvilla: nixvilla is the username, you can replace this with your own username, but same must be changed in the apache configuration file( Require user <username>).
Step3: Now, we need to check the permission and the ownership of the AuthUserFile, in our case it is /var/local/sites/passwd.
ls -l /var/local/sites/passwd
using above command, we can check the permission and ownership.
Normally apache uses www-data user, so we need to change the ownership to www-data.
chown www-data:www-data /var/local/sites/passwd
chmod 0660 /var/local/sites/passwd
Step4: Now, we need to restart the apache process to make the changes reflected.
In debian based systems, like in Ubuntu:
"apache2ctl configtest" command will check the configuration error and will display error message else will show Syntax OK.
If Syntax is Ok then we can gracefully restart the apache.
sudo apache2ctl configtest
sudo apache2ctl graceful
In Redhat/CentOS:
We can use "apachectl configtest" to check the configuration issues. And if all configuration is Ok, we can restart the service:
sudo apachectl configtest
sudo apachectl graceful
Now, we can open our website to test the password protection. If everything goes right, website will ask the password using a password pop-up.
If any issue, we can troubleshoot by referring the error log, whose path is defined in apache configuration file.
tail -f /var/log/apache2/nixvilla-error.log/
Bazinga.... All Done !!
Many thanks for reading the article. Keep visiting and post your comments/suggestions/queries.
Happy New Year...








0 comments:
Post a Comment