I am trying to make a simple program in Laravel that would allow the user to click a button and a backup SQL for their database would be generated locally.
$command = "/usr/local/mysql/bin/mysqldump --user=" . env('DB_USERNAME') ." --password=" . env('DB_PASSWORD') . " --host=" . env('DB_HOST') . " " . env('DB_DATABASE') . " > " . storage_path() . "/" . $filename;
$returnVar = NULL;
$output = NULL;
exec($command, $output, $returnVar);
This is my current code and as you can see I have specified the entire path of mysqldump, if I don't it just returns an empty .sql
. The same command (without the entire path) runs flawlessly when I run it in terminal, now this code is going to run on locally different environments (Windows, Linux, Mac) and the path to mysqldump would be different in each.
Is there a way I can make this happen without specifying the entire path?