0

Ok i'm having a nightmare with permissions..

I've got /var/www/src/myshell.sh which is executable

#!/bin/bash
echo "It's working" > /var/www/html/myshell.txt

This works fine from the CLI, the txt file is created containing the "It's working" text.

But when I try to run it from /var/www/html/test.php

<?php
$message=shell_exec("/var/www/src/myshell.sh 2>&1");
print_r($message);
?>

It returns the following in the browser :

/var/www/src/myshell.sh: line 3: /var/www/html/myshell.txt: Permission denied 

And myshell.txt isn't created in /var/www/html

I spent all of last night trying every possible way I could find here on SO and elsewhere to set the correct permissions to no avail so I've given up trying to figure it out and would like to know if it's possible to run this shell script WITHOUT it trying to return anything to the browser as that seems to be causing the permission error.

So basically test.php starts the .sh script and then forgets about it. The processes I intend to use here don't need to be sent back to the browser anyway.

Could this be achieved by NOT using shell_exec and by using another php command instead maybe?

Many thanks

1 Answer 1

1

apache user does not have permission to write on "/var/www/html/".

Also instead of write there, create another folder and set permissions of write to it, something like "/var/www/html/var/", set to that folder writing privileges and use it for any dynamic content.

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

6 Comments

You sir are an absolute legend.. If I had known this simple fact last night it would have saved me the 4hrs of pulling my hair out! Thank you so much!
Ok this is working now but it's still showing the results of the sh output in the web browser. Can I suppress the results? I don't need to see them at all.
Please remove print_r($message);, print_r is an "output" function, it internally does something like echo $var;
Ahh sorry i'm not using that message anymore. Now i'm running a program called wav2png to create a waveform from an audio file. The .sh now looks like this - #!/bin/bash exec wav2png -o /var/www/html/dump/waveform.png /var/www/html/mywav.wav; exit; It's working, but it's displaying the conversion process in the browser. Can I send that process display to /dev/null maybe?
I'm not following exactly your issue since shell_exec does not output anything. If you mean the content of $message, yeah probably you want your shell script to point to /de/null
|

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.