Simple Apache htaccess/htpasswd – Remote Access

Sometimes it is useful to give out htpassword protected access to
certain areas of your web server (say if you are developing an app for
someone and want to give them a preview). Here is a simple way to do it:

  1. Log into your router – forward port 61233 (or whatever) through to your local Apache webserver
  2. Jump
    into your Apache config file (# vi /usr/local/apache2/conf/httpd.conf)
    find the “Listen” directive. Make a new line under the existing “Listen
    80” and type “Listen 61233” – this will tell apache to listen on both
    the normal port 80 and your new port 61233
  3. Somewhere else in the conf file (usualy after any other <VirtualHost> directives) put the following:
    DocumentRoot /path/to/directory/to/expose
    ServerName myname
    <Directory "/path/to/directory/to/expose">
    AllowOverride All
  4. Now when someone accesses your apache server on port 61233 (eg: they will be shown the content within the
    path you specified, next step is to password protect this content so
    that not everybody can see it.
  5. Create a file in the path you exposed called .htaccess and put the following content in it:
    AuthName "SiteDemo"
    AuthUserFile /path/to/directory/to/expose/.htpasswd
    AuthType basic
    Require valid-user
    Order deny,allow
    Deny from all
    Allow from
    Satisfy Any
  6. Then creata the .htpasswd file:
    # htpasswd -c /path/to/directory/to/expose/.htpasswd Bob
  7. Restart Apache
    # /usr/local/apache2/bin/apachectl restart
  8. And
    your all done. If you visit your site localy at you will not require a password, but if
    anybody else visits it from the outside world they will be required to
    enter the password you configured in the .htpasswd file.

Leave a Reply

Your email address will not be published.