Create .htpasswd file in your magento root directory
Go to following URL and generate the encrypted password for your .htpasswd file:
Note: after generating your username and password should be looks like as follows:
Copy this line and paste in your created .htpasswd file.
Open your .htaccess file in magento root and paste following piece of code bottom of the file:
AuthName "Restricted Area"
AuthUserFile /var/www/PATH_TO_YOUR_MAGENTO_INSTALLATION_PATH/.htpasswd #this should be full path to your previously created .htpasswd file.
That’s it. Now when you open your pre-production server URL, you will prompt to entering your http password. If you forget your encrypted password then again regenerate new password and paste it your .htpasswd file in your Magento root.
Please note that sometimes you may need to clear your Magento cache, your web browser cache to view that password popup dialog box. Also you may need to restart your web server. To restart your apache in Linux box you can use following command:
sudo /etc/init.d/apache2 restart
sudo service apache2 restart
If you use nginx, the command is:
sudo service nginx restart
(This list can help in case of problems).
Enter your root password when asked.