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.

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

报告相同问题?

悬赏问题

  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程