Levi
Levi

Reputation: 301

rsync does not have permissions to be triggered by php

I'm trying to sync two local folders by triggering rsync from a php script. The following error is produced:

rsync error: some files could not be transferred (code 23) at /SourceCache/rsync/rsync-42/rsync/main.c(992) [sender=2.6.9]
rsync: recv_generator: mkdir "/Library/xxxxxxx" failed: Permission denied (13)

How do I give php/apache permissions to trigger the rsync process?

Thanks!

Upvotes: 1

Views: 458

Answers (2)

Adder
Adder

Reputation: 5878

The Apache/PHP process usually does its work as user www-data. To allow user www-data to write to a directory, you could manually change owner or group to www-data, and give write permission to the directory for either user or group. This however might break other processes which work with the directory.

chgrp www-data /Library && chmod g+a /Library

If you will rsync multiple times, i.e. when the directory already exists:

chgrp -R www-data /Library/directory && chmod -R g+a /Library/directory

Another approach would be to use a setuid script. This is a script which is called by user www-data but executes as the owner of the script. But that might be a security problem.

http://www.krenel.org/setuid-and-shell-scripts-explained/

Upvotes: 1

Sal00m
Sal00m

Reputation: 2916

The problem is that you do not have permissions to create directory.

Use chown on directory /Library and assign to the same user that is executing Apache server, and give permission of 755 to all files and directories, for example, if the user executing Apache is daemon:

sudo chown daemon.daemon -R /Library
sudo chmod 755 -R /Library

Upvotes: 1

Related Questions