1

I want to use s3cmd from my PHP script. Everything is working from shell but same not working from my PHP script.

shell_exec('s3cmd --config=/root/s3cmd.conf ls');

this is not working, and then i gave full path to my s3cmd installation

shell_exec('/usr/sbin/s3cmd --config=/root/s3cmd.conf ls');

Not working in PHP script but the same is working in command,

The PHP file which is calling the shell_exec is in webroot.

Might be the problem that s3cmd is configured as a root user and i am running from PHP which is www-data. if this is the problem how can i create config file for www-data.

Help me what i am doing wrong.

Thanks

EDIT I am using S3cmd. To run commands in my cron script. cron Script is a PHP script. The user running the cron is web11 and the s3cmd is configured using the root user.

so when i run s3cmd using shell_exec() in my PHP script it fails. But when i run in shell it works fine.

s3cmd ls

This works fine. as i am login using root user.

i tried to run it using runuser command

runuser -l root -c "s3cmd ls"

This works fine and displays list of buckets. But when i run using

runuser -l root -c "s3cmd ls"

This does not work. I tried by giving full path of the s3cmd

/usr/bin/s3cmd ls

this works in shell but not in my PHP script.

I changed permissions 777 for the php script and made root the owner of that user. but still does not work.

How can i run s3cmd from PHP script. ? i am on amazon Ec2 Instance.

Community
  • 1
  • 1
Asghar
  • 2,336
  • 8
  • 46
  • 79

2 Answers2

1

Why not use the AWS SDK for PHP? You can have the same functionality using the S3Client.listObjects() method

David Rabinowitz
  • 29,904
  • 14
  • 93
  • 125
  • Actually i want to perform tasks in the cronjob, like get size of the all objects, and deleting objects. – Asghar Feb 07 '13 at 11:39
0

shell_exec('s3cmd --config=/root/s3cmd.conf ls');

What might be missing here is the target of the S3 command "ls" ?!

It's working fine in PHP scripts like this :

exec("/usr/bin/s3cmd --config=.s3cfg info s3://YOUR-BUCKET/YOUR-FILE 2> /dev/null", $s3output, $s3return);

// switch due to return code (of shell !)
if($s3return == "0"){
    echo "my file exists";
}
else {
    echo "Error Code : " . $s3return;
}

This asumes, you ran "s3cmd --configure" successfully.

domi27
  • 6,903
  • 2
  • 21
  • 33