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=\"mypass\" db_name > /var/www/vhosts/mydomain.com/httpdocs/tools/dbbackup-2011-12-17.sql");
I get no errors or warnings or anything. but if I copy that string and execute it exactly as is on the server via SSH it works perfectly.
/usr/bin/mysqldump --opt --host=localhost --user="myuser" --password="mypass" db_name > /var/www/vhosts/mydomain.com/httpdocs/tools/dbbackup-2011-12-17.sql
I tried using exec() and system() instead of passthru() but same results. This is really strange and I can’t focure out what could be the problem. Any ideas?
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.
STDERRandSTDOUTTo see if there is anything printed to
STDERRthat is relevant to the problem, use the below snippet!Check the log files!
Have you checked the
error_logassociated with yourhttpd?