doujia1988 2018-01-21 15:10
浏览 46
已采纳

如何检查在终端(PHPUnit)中运行的php代码,如果在Apache中运行的php代码能够写入文件夹?

I have file_put_contents code in PHPUnit that can always successfully write a file to a folder with permissions 744.

I have identical file_put_contents website code that cannot write to the same folder unless I max out permissions to 777.

The PHPUnit code is giving me a sort of false positive.

  • 写回答

1条回答 默认 最新

  • dongqiao8502 2018-01-21 15:16
    关注

    You are running the unit test and the website under two different user accounts. The one you use for your unit tests has permission to write to your folder, the other one doesn't.

    There are two possibilities I see here:

    • Run the unit test with the webserver-user
    • Change the folder permissions

    Running as a different user

    Using sudo (or su), you can change the user which will run the command. In doing so, both operations have the same permissions. If one fails, the other will too.

    sudo -u username command
    

    Change the folder permissions

    Unix has a user and a group assigned to each file and folder. First, create a group for both your users:

    groupadd WebsiteGroup
    

    The add your users to that group

    usermod -aG WebsiteGroup user1
    usermod -aG WebsiteGroup user2
    

    Now assign the group to your folder using chown/chgrp. Now when you run your tasks, the group permission is the one that determines success or failure for both.

    Man Pages for

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作