K
K
karpo5182020-04-30 12:24:00
Web servers
karpo518, 2020-04-30 12:24:00

How to create a cron job on behalf of www-data user in vestacp panel?

Given: Ubuntu 18.04 web server + Vestacp + Nginx + php-fmp

The essence of the problem: All site files belong to the user user1. They are in his directory /home/user1/... php runs as user www-data. Directories are created in the php code of the site. Cron runs php in cli mode and writes files to the created directories. In addition to direct writing from php, Linux commands are launched via shell_exec, which also write to the created directories. I create a cron job in vestacp panel to execute php script in cli mode and it runs as user1. As a result, the cron script and the bash commands it runs do not have write permissions to the created directories. User1 has been added to the www-data group. But it doesn't help. Although I create folders by calling the mkdir('/path/to/folder',0775, true) function, the permissions are ignored. The folder is created with permissions 0755.

Solutions that I would not like to use:

1. Set the nginx user to user1. I've always done this before and had no problems. Now I want to configure the server differently.
2. Use curl or wget to run php script. I would not want to do this either in order to avoid security problems and other crutches.

What do you advise?

PS I solved my problem in the following way:

// было 
$status = mkdir($dir, $rules, $recursive);
// стало
$oldmask = umask(0);
$status = mkdir($dir, $rules, $recursive);
umask($oldmask);


Still, I would like to understand if vestacp allows you to run a task on behalf of a web server user

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question