SteveEdson
SteveEdson

Reputation: 2495

PHP Linux + Windows - Shares and Permissions

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.

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

Any help would be appreciated, thanks.

Upvotes: 2

Views: 1110

Answers (1)

Benny Hill
Benny Hill

Reputation: 6240

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.

Upvotes: 3

Related Questions