I need help executing a php script via CLI. Not sure if this is a Linux or PHP problem.
When I execute /usr/bin/php /var/www/backup.php in Ubuntu I get:
You are not permitted to execute this script
The code in backup.php is:
<?php
// Set default paths
define ("DOCUMENT_ROOT","/var/www");
define ("DATABASE_PATH","/var/lib/mysql/livedb");
define ("BACKUP_PATH","/var/sitebackups");
$filename_suffix = "_" . date("Ymd_his") .".tar.gz";
if ($_GET['key']!="xxx") {
die ("You are not permitted to execute this script");
}
//change working directory to backup directory
if (!chdir(BACKUP_PATH)) {
die ("Failed to change to working directory.");
}
// Tar the web files
$cmd = "tar -cvzf " . BACKUP_PATH. "/webfiles" . $filename_suffix . " " .DOCUMENT_ROOT ;
echo $cmd . "<br/>";
//echo shell_exec($cmd);
// Create link to web files backup
// Tar the mysql DB
$cmd = "tar -cvzf " . BACKUP_PATH. "/dbfiles" . $filename_suffix . " " .DATABASE_PATH ;
echo $cmd . "<br/>";
//echo shell_exec($cmd);
// Move to backup folder
// Create link to DB backups
// Email backup confirmation
?>
I even tried to add this is a scheduled task via crontab and I still get the same error in the logs.
Please help!
I can’t see a problem at all. The code is working correct.
The variable
$_GET['key']isn’t set in CLI and is always not the same as ‘xxx’, so the code stops by printing out your string.Delete the if-clause and the code will do the rest, if permissions on files and folders are set correct.