Answer the question
In order to leave comments, you need to log in
Ubuntu how to create user for webserver?
Problem with writing files on apache and nginx web servers.
The web servers run as the www-data user.
I add my user Developer , I create a script.
<?php
ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . 'test.txt', 'test');
Answer the question
In order to leave comments, you need to log in
In this case, I do this: developer user, www-data group.
Files 664, folders 775 read/write rights.
the simplest temporary option is to change the Developer user's group to www-data:
- find out the gid of the www-data group by executing cat /etc/group | grep www-data
;
- change the gid of the Developer user in the /etc/passwd file - Developer will no longer be a member of the group whose gid you removed (this may not be acceptable to you);
- add a line to the Developer user's .profile file umask 0002
- any newly created file by the user will get the rights rwxrwxr-- instead of the default rwxr--r-- (may also be unacceptable);
- go to the web server's files directory (i.e. the directory where you have problems creating the test.txt file) and execute chmod g+w .
- this will allow members of the www-data group to create files in the directory;
- relogin.
in order to solve the problem "more correctly" one should use acl support in the file system; key points:
- undo all the changes that are written above;
- add the xattr mount option to fstab for a partition with a webserver file directory (ext3, ext4, btrfs, reiserfs support them) and remount the partition (for example, reboot);
- use setfacl to set default attributes for newly created files in the webserver file directory.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question