Ryan-Neal Mes
Ryan-Neal Mes

Reputation: 6263

Apache localhost authentication

I am trying to setup up basic authentication to a folder on my localhost running apache. Currently the app runs fine without authentication. I have setup a virtual host so I can access my application through dev.myapp.com

The code I add to my .htaccess file to force authentication is:

<Directory "/Users/myusername/Sites/dev.myapp.com">
  AuthType Basic
  AuthName Test
  AuthBasicProvider file
  AuthUserFile /etc/apache_users
  Require valid-user
</Directory>

I have created a user.

When I type dev.myapp.com into the browser I get an internal server error. I am fairly new to apache. A point in the right direction would be appreciated.

Thanks.

Upvotes: 0

Views: 635

Answers (1)

gpwclark
gpwclark

Reputation: 66

First off, using .htaccess is a bit slower and requires that you have set the AllowOverride directive accordingly. It is recommended that you instead use httpd.conf to establish basic authentication. The Apache documentation explains all of this so check out this link http://httpd.apache.org/docs/2.2/howto/auth.html.

Regardless, I think I see the error. Your <Directory> tag looks a little odd. I understand the name of your site is dev.my.app.com but is that the actual name of the folder where the site dev.myapp.com points to on your server? Your httpd.conf file should have an entry like this:

<VirtualHost *>
DocumentRoot "document/root/path"
Other directives here
</VirtualHost>

The DocumentRoot is where Apache directs all incoming web traffic. If you are trying to establish authentication for your entire site, the value of DocumentRoot is most likely what you would want in your Directory tag ... making it <Directory /document/root/path>.

To locate httpd.conf look in in /etc/apache2/. Make sure to restart your server after you change the file (sudo /etc/init.d/apache2 restart). Hope that helps, please update if you haven't already resolved the problem.

Upvotes: 1

Related Questions