I found some code in a previous Stackoverflow post that is very simple and runs a mysqldump command. I can run this command in the shell as root with no problem. But when I go through PHP the backup file never gets created.
<?php
$backupFile = "/var/www/html/mysql-bak/my_dbname-".date("Y-m-d-H-i-s").".sql";
$command = "mysqldump --opt -u root -pmypassword my_dbname > $backupFile";
system($command);
?>
It must be a permissions problem when the Apache service tries to write the file, right? I created a directory /var/www/html/mysql-bak/ and did chgrp and chown to make the owning user “mysql” and the owning group “mysql”. In desperation I added the user “apache” as a member of the group “mysql” but that still didn’t fix it.
Actually I was able to fix it by just chown “apache” as the owner of that directory.