Dump MySQL From Client to Server in PHP / Symfony

3

I have this code with which I create backups of my database

    $dbname = $this->getParameter('database_name');
    $host = $this->getParameter("database_host");
    $user = $this->getParameter("database_user");
    $pass = $this->getParameter('database_password');

    $route = '/usr/moseDump';
    $separador = '/';

    if (!file_exists($route . $separador)) {
        mkdir($separador . $route, 077);
    }

    $backup_file = $route . $separador . $dbname . "_" . date("dmYHis") . ".sql";
    $command = "mysqldump --opt -h " . $host . " -u " . $user . " -p" . $pass . " " . $dbname . " > $backup_file";

    exec($command);

If I run it locally, it works perfectly, but when executing it from a client, it simply does not generate the file. I'm using apache2 on ubuntu 16.

    
asked by Cero 31.07.2017 в 19:05
source

1 answer

0

As Murianno says, I am almost convinced that it is a privilege problem.

When you execute a command in local on development servers we usually use the root user or another with x privileges, while the web server when executing the requests uses the user www-data and group www-data in apache and nginx.

The solution is simple, you have several options:
1- Add the www-data group to the copies folder and assign the permissions

chown USUARIO:www-data -R /usr/moseDump -> Asignar grupo a la carpeta  
chmod -R X7X -R /usr/moseDump -> Asigna privilegios al grupo en la carpeta

2- (less recommended) Modifies the Nginx or Apache execution user that has privileges in that folder.

    
answered by 13.09.2017 в 23:45