Reputation: 2084
I am attempting to add HTTP authentication to my php-based Heroku app. I found a great Github gist here that provides code for creating .htaccess and .htpasswd files in my Heroku directory. I currently have both files within the /app/ directory (so .htaccess is located at /app/.htaccess and .htpasswd is located at /app/.htpasswd). However, when I navigate to my app and enter in the username and password, I get a 500 internal server error. Checking the Heroku logfile, I can see only that my .htpasswd file was not found:
(2)No such file or directory: [IP removed] AH01620: Could not open password file: /app/.htpasswd
Here is the full contents of my .htaccess file:
AuthUserFile /app/.htpasswd AuthType Basic AuthName "My Files" Require valid-user
If I run bash on heroku and 'ls -a', I can see that my .htpasswd file is definitely in the /app/ directory.
Someone has any idea what is going on here? Is there something that I'm missing in terms of getting this set up?
Upvotes: 2
Views: 3801
Reputation: 2084
Figured it out! I needed to create the .htpasswd file in my project's main directory (on my local machine), then add the file to my git repo and push the whole thing to Heroku. For some reason, when I used "heroku run bash" and then executed the command to add the .htpasswd file, it seems that Heroku added that file on a temporary dyno / instance and not on the permanent version of my app.
For other rookies who are trying to do this and need an easy end-to-end explanation:
Upvotes: 4