1

In addition to my previous question, another problem appeared and I decided to make a new question for it:

I am currently calling a php script that than runs a bash script. The php script looks like:

chdir('/home/');
$output = shell_exec('./do.sh');
echo "<pre>$output</pre>";

The do.sh contains:

#! /bin/bash

echo 12;
dd if=/dev/urandom of=test.test bs=1048576 count=2

The problem is following:

When I call ./do.sh from the terminal everything works fine: test.test is created and the ouput is 12

However, when I call it from my php file, the output is 12 aswell, but no file is being created. Since I know almost nothing about bash scripting, I have no idea why this is happening...

3
  • 6
    That would probably be because the user that PHP is running as does not have write permissions on the /home/ directory. You will have to chmod nnn /home where nnn is the appropriate permissions structure - remember to make it as restrictive as possible. You might want to look at the ownership and group memberships to get the best setup. To test you can chmod 777 /home, and if it works then you have your answer. Commented Jun 15, 2012 at 15:18
  • Thanks a lot! I did forget to put the correct permissions for the home folder. I only thought about the actual php file and changed its permission, but didnt do the same for the folder it is in! I hope you dont mind me marking @dAm2K ´s answer, since he also suggested to look at the permissions! Commented Jun 15, 2012 at 15:26
  • I upped its comment! :-) Commented Jun 15, 2012 at 15:40

1 Answer 1

3

Check if PHP safe_mode is enabled. You have to turn it off in your /etc/php.ini file, and obviously check filesystem permissions.

Sign up to request clarification or add additional context in comments.

3 Comments

Safe mode is off and the php aswell as the .sh file have all permissions to write. However, I am not sure about the user(see @DaveRandom ´s comment).
Try to use absolute path for dd: /bin/dd if=/dev/urandom of=test.test bs=1048576 count=2
It was the permissions after all! Thanks a lot! I did forget to put the correct permissions for the home folder. I only thought about the actual php file and changed its permission, but didnt do the same for the folder it is in!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.