douqiaotong8682 2015-03-31 06:21
浏览 45

如何将HTTP身份验证添加到基于PHP的Heroku应用程序?

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?

  • 写回答

1条回答 默认 最新

  • dsff788655567 2015-03-31 06:35
    关注

    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:

    • Create an .htaccess file in the main directory of your git repo (on your local machine) per the instructions at https://gist.github.com/bbrewer97202/3316425. For my app, I left out the /www part of the AuthFile line because there is no /www/ folder on my Heroku instance.
    • Using terminal on your local machine, create an .htpasswd file in the main directory of your git repo by typing 'htpasswd -c .htpasswd [username]' once you are in that directory.
    • Commit everything to git and then push to the Heroku server.
    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行