Page 1 of 1

PHP CONNECTION WITH SHELL

Posted: Mon Apr 16, 2007 3:48 pm
by luyznascimento
Hi All !!!


I am facing a huge problem, at least to me, a newbie in Linux and a "newbie" with PHP related to this aspect specifically.

The main goal of my post is: TRY TO UNDERSTAND WHY I CAN T KEEP CONNECTED the necessary time to execute a communication with a developed shell programm.

If in the command line at linux - the code below when its called works PERFECTLY. It's divided in two parts: a) changes the actual directory to the "dynamic one"; b) TAR the content of that directory.

Code: Select all

#!/bin/sh
#

if test -z $1

then

        echo "empty directory - please inform one..."

else

        cd "$1/"

        tar -cf "$1.tar" cbq*

        #ls -al
fi
I tried different approaches with PHP like: shell_exec, system... but none of them seems to work. I am imagining that the problem comes by the fact I have two actions with this shell and php "get confused with it" when try to deal with it. The shell is called: cd.sh and chmod 755 .

I really need a help with this.

Thank you very much for your reading and forgive my "english".

Kind Regards,
Luyz Nascimento.

Posted: Mon Apr 16, 2007 3:58 pm
by arturm
you can try:

Code: Select all

exec( "/path/to/program/your_program.sh" , $output);

print_r($output);
remember that php scripts from the browser are run as apache user (www-data or nobody) and you have to give permissions to that user.

Posted: Mon Apr 16, 2007 4:48 pm
by feyd
Duplicated thread. Locked.

viewtopic.php?t=65977