Password protect locally hosted site

Discussion in 'Web Design and Development' started by pezmannen, Jan 23, 2010.

  1. pezmannen macrumors newbie

    Joined:
    Jan 23, 2010
    #1
    Hi

    This is my first post at MacRumors (long time reader though), so please be kind and helpfull :)

    I recently bought my first Mac (mac mini) and I'm lovin it. Yesterday I tried iWeb and made a site containing photos of me and my friends. I'm not that enthustiastic about MobileMe (expensive) and would rather host the site on my own mac mini.

    In iWeb, it's only possible to password protect sites that you upload to MobileMe. But as I understand it, the built-in web server is an Apache server? Shouldn't I be able to password my locally hosted site by using functions in Apache?

    If anybody has a good guide I'd appriciate it!

    Thanks
     
  2. pezmannen thread starter macrumors newbie

    Joined:
    Jan 23, 2010
    #3
    I've created the .htpasswd-file and the .htaccess file but it doesn'nt work. Do I need to activate them?
     
  3. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    One of the typical problems run into is not using the correct full path to the htpasswd file. In the .htaccess file, you've got a line like,
    Code:
    AuthUserFile /full/path/to/.htpasswd
    That path has the be the full path for the system, not just your web zone. If it's on a Linux server it'll likely have the form

    Code:
    /home/username/.htpasswd
    To get the full path, if you SHH into your domain, is to run the command pwd (it may be cwd (current working directory) on some systems).

    If that isn't the issue we'll need to know more about what you tried. They don't need activating though. Apache looks for the .htaccess file at each file request.
     
  4. pezmannen thread starter macrumors newbie

    Joined:
    Jan 23, 2010
    #5
    I downloaded Mamp and it worked out of the box. This should mean that I got the files correct I think?
     
  5. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #6
    That's irrelevant really. What did you use for the path of the htpasswd?
     
  6. pezmannen thread starter macrumors newbie

    Joined:
    Jan 23, 2010
    #7
    My point was that Mamp uses the htaccess and htpasswd-files correctly...


    This is my .htaccess file

    In my .htaccess (which is placed in /Users/MyUser/Sites/MySite
    AuthUserFile(placed in folder above /MySite) /Users/MyUser/Sites/.htpasswd
     
  7. designguy79 macrumors 6502

    Joined:
    Sep 24, 2009
    Location:
    Michigan
    #8
    Yes, MAMP includes Apache and unless something changed recently, it does load .htaccess

    Where is the rest of your .htaccess file? You need something like this...

    Code:
    AuthUserFile /full/path/to/.htpasswd
    AuthType Basic
    AuthName "My Secret Folder"
    Require valid-user
     
  8. pezmannen thread starter macrumors newbie

    Joined:
    Jan 23, 2010
  9. designguy79 macrumors 6502

    Joined:
    Sep 24, 2009
    Location:
    Michigan
    #10
    Try this... drop in to Terminal and run the following commands to make sure that the files are indeed named and in place where you think they are...

    Code:
    cd /Users/MyUser/Sites/MySite
    cat .htaccess
    then

    Code:
    cat /Users/MyUser/Sites/.htpasswd
    If everything appears in order, I could check file permissions and make sure they are readable by the user Apache is running as, but NOT world-writable. (e.g., 777)

    Lastly, check the Apache error logs. Mine were at

    Code:
    tail -n 100 /Applications/MAMP/logs/apache_error_log
     

Share This Page