Answer the question
In order to leave comments, you need to log in
How to properly mount cifs (ubuntu 14.04) with write access for nginx/php (www-data)?
I have some kind of vicious circle, I can’t google the answer for the second day.
Given:
//192.168.20.115/filesfolders$ /mnt/filesfolder cifs user=guest,pass=,iocharset=utf8,dir_mode=0777,file_mode=0777,sec=lanman 0 0
$ cat /etc/mtab
//192.168.20.115/filesfolders$ /mnt/filesfolder cifs rw 0 0
$ ls -ld /mnt/filesfolder/
drwxrwxrwx+ 28 nobody nogroup 0 февр. 18 11:40 /mnt/filesfolder/
$ echo "hello" > /mnt/filesfolder/1.txt
-bash: /mnt/filesfolder/1.txt: Permission denied
$ ls -l /mnt/filesfolder/1.txt
-rwxr--r--+ 1 nobody nogroup 0 февр. 18 11:40 /mnt/filesfolder/1.txt
<?php
file_put_contents('/mnt/filesfolder/test_from_php.txt', 'Hello from PHP');
Warning: file_put_contents(/mnt/filesfolder/test_from_php.txt): failed to open stream: Permission denied in /usr/share/nginx/html/test.php on line 2
$ ls -l /mnt/filesfolder/test_from_php.txt
-rwxr--r--+ 1 nobody nogroup 0 февр. 18 11:56 /mnt/filesfolder/test_from_php.txt
$ whoami
ad
$ id ad
uid=1000(ad) gid=1000(ad) groups=1000(ad),4(adm),24(cdrom),27(sudo),30(dip),33(www-data),46(plugdev),112(lpadmin),113(sambashare)
//192.168.20.115/filesfolders$ /mnt/filesfolder cifs user=guest,pass=,iocharset=utf8,uid=ad,gid=ad,dir_mode=0777,file_mode=0777,sec=lanman 0 0
$ ls -ld /mnt/filesfolder/
drwxrwxrwx+ 28 ad ad 0 февр. 18 11:56 /mnt/filesfolder/
$ echo "hello" > /mnt/filesfolder/2.txt
$ ls -l /mnt/filesfolder/2.txt
-rwxr--r--+ 1 ad ad 6 февр. 18 12:05 /mnt/filesfolder/2.txt
Warning: file_put_contents(/mnt/filesfolder/test_from_php.txt): failed to open stream: Permission denied in /usr/share/nginx/html/test.php on line 2
$ ls -l /mnt/filesfolder/test_from_php.txt
-rwxr--r--+ 1 ad ad 0 февр. 18 12:07 /mnt/filesfolder/test_from_php.txt
<?php
print exec('whoami')
$ ls -ld /mnt/filesfolder/
drwxrwxrwx+ 28 www-data www-data 0 февр. 18 12:07 /mnt/filesfolder/
$ echo "hello" > /mnt/filesfolder/3.txt
-bash: /mnt/filesfolder/3.txt: Permission denied
$ ls -l /mnt/filesfolder/3.txt
-rwxr--r--+ 1 www-data www-data 0 февр. 18 12:15 /mnt/filesfolder/3.txt
$ ls -l /mnt/filesfolder/test_from_php.txt
-rwxr--r--+ 1 www-data www-data 14 февр. 18 12:16 /mnt/filesfolder/test_from_php.txt
$ cat /mnt/filesfolder/test_from_php.txt
Hello from PHP
Answer the question
In order to leave comments, you need to log in
I read this manual linux.die.net/man/8/mount.cifs and added the noperm parameter to the mount options in /etc/fstab - suddenly both users got write access (my console and web server www-data) .
In total, the connection string in fstab looks like this: //192.168.20.115/filesfolders$ /mnt/filesfolder cifs user=guest,pass=,iocharset=utf8,noperm,uid=www-data,gid=www-data,dir_mode=0777 ,file_mode=0777,sec=lanman 0 0
However, this does not remove general questions for understanding: why do I see drwxrwxrwx rights for a directory, but in fact only the owner can write to it? Why files are still created with permission denied messages, but empty (if there is no access, then it should not be at all, right?)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question