Running mysqldump from a PHP script doesn't work but works on SSH

后端 未结 1 766
故里飘歌
故里飘歌 2021-01-23 00:59

I\'m trying to back a database via a PHP script using this one simple line:

passthru(\"/usr/bin/mysqldump --opt --host=localhost --user=\\\"myuser\\\" --password         


        
1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-23 01:37

    An educated guess

    If I can make an educated guess it's because the user that runs the php-script (ie. user the httpd is run as) doesn't have permission to write to /var/www/vhosts/mydomain.com/httpdocs/tools/.

    Though the user you are using to execute the command has.


    STDERR and STDOUT

    To see if there is anything printed to STDERR that is relevant to the problem, use the below snippet!

    $tubes = array(
      0 => array("pipe", "r"),
      // print contents on STDOUT to file
      1 => array("file", "/var/www/vhosts/mydomain.com/httpdocs/tools/dbbackup-2011-12-17.sql", "w"),
      2 => array("pipe", "w")
    );
    
    $p_handle = proc_open (
      "/usr/bin/mysqldump --opt --host=localhost --user=\"myuser\" --password=\"mypass\" db_name",
      $tubes, $pipes
    );
    
    if (is_resource ($p_handle)) {
        fclose ($pipes[0]);
    
        $stderr_data = stream_get_contents ($pipes[2]); fclose($pipes[2]);
    
        $proc_ret    = proc_close ($p_handle);
    
        echo "--------- STDERR:\n$stderr_data\n";
        echo "------------ RET: $proc_ret\n";
    } else {
      die ("Unable to execute external resource, aborting!");
    }
    

    Check the log files!

    Have you checked the error_log associated with your httpd?

    0 讨论(0)
提交回复
热议问题