V
V
Vladislav Soprun2015-01-31 16:39:39
Nginx
Vladislav Soprun, 2015-01-31 16:39:39

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');

Everything works great, the test.txt file will be created as www-data ww-data .
But if I previously created a file on behalf of Developer , then the file will not be overwritten and will give an error that there are no rights!
Tell me how to create a new user Developer correctly , that there were no problems that the web server could not overwrite the files created by my users.
Also, authorization via SSH must go through authorized_keys.
PS Earlier there was a crutch, started a web server from the user, but I do not like this approach.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Osher, 2015-01-31
@miraage

In this case, I do this: developer user, www-data group.
Files 664, folders 775 read/write rights.

V
vreitech, 2015-01-31
@fzfx

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 question

Ask a Question

731 491 924 answers to any question