V
V
vxk7m2013-02-18 16:52:41
linux
vxk7m, 2013-02-18 16:52:41

Is the user having trouble accessing files created by Apache?

Hello, dear habravchane! Here's the problem: Apache is running on the server as the www-data user, and the www_user user is also created on the server, which has a home directory and this directory is accessible via the web. The user www_user, as shown below, creates a script in his directory that is available to be run by the web server and generates an arbitrary file during its work. The problem is that the generated file is owned by the web server, i.e. www-data and for this reason the www_user user does not have access to it. How to make sure that the www_user user does not have problems accessing the generated files?

/home/www_user/ # ls -l<br>
total 8<br>
-rw-r--r-- 1 www_user users 88 Feb 18 14:31 file.php<br>
-rw-r--r-- 1 www_user users 13 Feb 18 11:33 index.html<br>
/home/www_user/ # cat file.php<br>
<?<br>
        $file='file.txt';<br>
        $fh=fopen($file, 'w');<br>
        fwrite($fh,'Hello habr!');<br>
        fclose($fh);<br>

Next, follow the link example.com/file.php to generate the file. And we see this
/home/www_user/ # ls -l<br>
total 12<br>
-rw-r--r-- 1 www_user users    88 Feb 18 14:31 file.php<br>
-rw-r--r-- 1 www-data www-data 11 Feb 18 14:32 file.txt<br>
-rw-r--r-- 1 www_user users    13 Feb 18 11:33 index.html<br>
/home/www_user/ #<br>
<br>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
@
@sledopit, 2013-02-18
@vxk7m

Add the www_user user to the www-data group and grant permissions to 0664.
And there is also apache-mpm-itk, where you can use your own user for each virtualhost.

A
Alexey Zhurbitsky, 2013-02-18
@blo

$file='file.txt';
$fh=fopen($file, 'w');
fwrite($fh,'Hello habr!');
fclose($fh);
chmod($file, 0666);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question