Run shell script via PHP
Is there a way to run the following script via PHP
http://www.magentoadvisor.com/magento-backup/tutorial-magento-backup-scripts-part-2/
I have tried to use exec, shell_exec, system but none of them are working. They do work when I try exec('whois domain.com') though so it must be something I am doing wrong!!
If this is not possible does anyone know of a good way of backuping up Magento via PHP, unfortuantely I don't have SSH access.
Than开发者_JAVA百科ks
UPDATE This is the code I am trying to use
system('magento-backup-script.bin -date', $output);
var_dump($output);
Output: int(127)
Php safe mode is off
UPDATE:
I managed to get i working by copy the script into the PHP file and use the tactics operator to run the command. Thanks for all your help everyone
Use system() command of PHP.
system() is just like the C version of the function in that it executes the given command and outputs the result.
The system() call also tries to automatically flush the web server's output buffer after each line of output if PHP is running as a server module.
If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function.
(From the PHP manual: system).
It sounds like your webhost has safe mode enabled which blocks you calling system()
. Upload a php file to your webserver containing the following code then link to it here (or if the server is not publicly accessible put it on DropBox or somewhere). This will tell us what functions are disabled on your hosting / if safemode is turned on.
<?php
phpinfo();
?>
you can use system to execute commands on the system, for example:
If your string is called backup and is located in /home/rob/scripts/backup/megento you can issue the command like so:
if(false === ($line = system("/home/rob/scripts/backup/megento/backup",$result)))
{
echo "Error " . (int)$result . ": Backup failed: (" . $line . ")\n";
}
if your getting the result 127, this is known as an exit code, int 127 usually means that the bas script attempted to execute a command but the command was not found.
looking at the bash script it uses the tar command to create the archive, have you made sure tar exists and is installed on the server.
you may also want to pipe the output to an error log to see what's happening:
system("/home/rob/scripts/backup/megento/backup >> results.txt");
echo file_get_contents("/home/rob/scripts/backup/megento/results.txt");
or if that is leading to an empty file maybe its a perms problem, try the following:
exec("/home/rob/scripts/backup/megento/backup",$full_result);
var_dump($full_results);// Array I believe.
精彩评论