dongpu2694 2013-01-02 17:34
浏览 82
已采纳

PHP Linux + Windows - 共享和权限

We have a windows master instance that writes data to Linux nodes, currently this is working fine. The PHP files running on windows can use a simple script to write to the linux machine like so:

file_put_contents('\\\\hostname\\share\\testfile.txt', 'testing123');

The linux node has the windows php user stored, and allows the files to be written. However, we want to be able to do the same thing on the linux machines, and write to a shared folder on the windows instance. The same line as above, but with the windows host and shares, still returns true, but the file is not actually created.

  • If it didn't work, why does the line return true? This makes it very hard to debug and test errors.
  • How can we get the script to work? Is the solution to mount the windows shares in linux? This does not seem like an appropriate solution, as we might change the windows shares or add new ones, we do not want to have to keep mounting and unmounting the shares on each linux instance.

We have added the linux user to the windows share permissions, but it does not seem to work.

Any help would be appreciated, thanks.

  • 写回答

1条回答 默认 最新

  • duanluanlang8501 2013-01-02 17:45
    关注

    A project that I'm working on just mounts the Windows shares. We have entries in the /etc/fstab file that mount the shares automatically when the machine is booted. For example:

    //alpha/inetpub  /mnt/alpha  cifs  credentials=/root/credentials,_netdev,file_mode=0644,dir_mode=0755,uid=1000,gid=1000,rw  0  0
    //beta/inetpub   /mnt/beta   cifs  credentials=/root/credentials,_netdev,file_mode=0644,dir_mode=0755,uid=1000,gid=1000,rw  0  0
    

    In our environment the Windows shares won't ever change names. Our Linux instances don't need access to all Windows shares so we just update the fstab file for whichever instance(s) need access to any new shares.

    The credentials file is a simple text file of the format:

    username=SOME_USERNAME
    password=THE_PASSWORD_FOR_USERNAME
    

    It's just an easy way to keep a username/password pair secure when some other script/file might be viewed by users without root access.

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

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元