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...

jww
  • 97,681
  • 90
  • 411
  • 885
r0skar
  • 8,338
  • 14
  • 50
  • 69
  • 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. – DaveRandom Jun 15 '12 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! – r0skar Jun 15 '12 at 15:26
  • I upped its comment! :-) – dAm2K Jun 15 '12 at 15:40

1 Answers1

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.

dAm2K
  • 9,923
  • 5
  • 44
  • 47
  • 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). – r0skar Jun 15 '12 at 15:21
  • Try to use absolute path for dd: /bin/dd if=/dev/urandom of=test.test bs=1048576 count=2 – dAm2K Jun 15 '12 at 15:23
  • 3
    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! – r0skar Jun 15 '12 at 15:27