简体   繁体   中英

PHP execute shell command permission denied

I installed an application (bagit) via homebrew and am trying to execute a shell command from my local Apache server (installed on OSX).

My PHP looks like this:

$cmd =  'bag create '.$targetFolder.' '.$sourceFolder.' --baginfotxt '.$bagInfoFile ." 2>&1";
$output = shell_exec($cmd);

However, I am getting the following error message:

/bin/bash: /usr/local/bin/bag: Permission denied

How can I give Apache access to the bash command located in `/usr/local/bin?

Your apache install will need to be running as the same user/group as the files its trying to execute.

You can either change the file permissions of the application you are trying to execute to the same as apache/php current user/group (or 777 etc..)

or you can change apache/php to run as a more priviliaged user/group.

  • Alternatively

You could change the method of your application to SSH into your executable environment and execute the application over SSH.

When PHP tries to exec something, it will do as the default web server user ( apache , www-data or httpd ). Make sure that the command to run has the right ownership / permissions. The easiest way to reach this is to add your web server user to a new group, lets say test , and chgrp test /usr/local/bin/bag

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM