Cannot exec in my own directory

Cannot exec in my own directory

am 16.08.2009 19:16:38 von Dotan Cohen

I have a script in /home/username/script.sh with permissions 777. I
can SSH into the server and execute ./script.sh to run the script, but
calling it from exec in PHP does not run it. What should I start
checking?

Thanks.

--
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Cannot exec in my own directory

am 16.08.2009 19:29:45 von Sudheer Satyanarayana

Dotan Cohen wrote:
> I have a script in /home/username/script.sh with permissions 777. I
> can SSH into the server and execute ./script.sh to run the script, but
> calling it from exec in PHP does not run it. What should I start
> checking?
>
> Thanks.
>
>
Check the include path. Try using the complete path to the file. And
make sure the user PHP is running has read permissions to the
directories upwards the hierarchy.


--

With warm regards,
Sudheer. S
Business: http://binaryvibes.co.in, Tech stuff: http://techchorus.net, Personal: http://sudheer.net


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Cannot exec in my own directory

am 16.08.2009 20:45:36 von Dotan Cohen

> Check the include path. Try using the complete path to the file. And make
> sure the user PHP is running has read permissions to the directories upwards
> the hierarchy.
>

Thanks. I am using the complete path to the script:
exec("/home/username/script.sh");

In the /home/username/ directory there are other files, such as
database_connection.inc that I regularly include_once in my PHP
scripts, so I know that PHP has read access to that directory.

--
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Cannot exec in my own directory

am 16.08.2009 20:59:57 von Caner Bulut

Dotan,

Please copy your script in the Linux include paths. Such as /usr/local/bin
and give it neccecary permission and try your script again.

If you still have any problem, we understand that it is no related script
path problem and permissions.

Maybe there is some problems on your php script.

Thanks


-----Original Message-----
From: Dotan Cohen [mailto:dotancohen@gmail.com]
Sent: Sunday, August 16, 2009 9:46 PM
To: Sudheer Satyanarayana
Cc: php-general.
Subject: Re: [PHP] Cannot exec in my own directory

> Check the include path. Try using the complete path to the file. And make
> sure the user PHP is running has read permissions to the directories
upwards
> the hierarchy.
>

Thanks. I am using the complete path to the script:
exec("/home/username/script.sh");

In the /home/username/ directory there are other files, such as
database_connection.inc that I regularly include_once in my PHP
scripts, so I know that PHP has read access to that directory.

--
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Cannot exec in my own directory

am 16.08.2009 21:36:56 von Dotan Cohen

> Please copy your script in the Linux include paths. Such as /usr/local/bin
> and give it neccecary permission and try your script again.
>

I do not have root access on this machine. That is why I run the
script from /home/username/

--
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Cannot exec in my own directory

am 17.08.2009 12:17:48 von kranthi

see if can run the same php file via CLI. does script.sh run without
any problems ? then, probably something linke SELinux is preventing
httpd from running scripts. you have to contact your system
administrator to get this fixed.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Cannot exec in my own directory

am 17.08.2009 15:06:04 von Dotan Cohen

> see if can run the same php file via CLI. does script.sh run without
> any problems ? then, probably something linke SELinux is preventing
> httpd from running scripts. you have to contact your system
> administrator to get this fixed.
>

You are right. Running the php script from the CLI in an SSH session
results in the expected behaviour: the script specified in the exec
command is run. Not so if I call the php script from a web browser.

Thanks for the tipoff.

--
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Cannot exec in my own directory

am 17.08.2009 15:53:27 von kranthi

Did you check SELinux options ??

I have a similar problem. For some unknown reason scan_dir() is not
able to read /home/user when run as Apache module. but the CLI is
giving expected results. I did not find any work around, but had to
read /var/www which is the home directory of 'apache' (this is the
user under which apache runs by default. hence you script needs 777 to
execute)

So if every thing else fails I'll recommend you to move the script to
/var/ww (usually your server root) instead of /home/user

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Cannot exec in my own directory

am 17.08.2009 15:57:33 von Ashley Sheridan

On Mon, 2009-08-17 at 19:23 +0530, kranthi wrote:
> Did you check SELinux options ??
>
> I have a similar problem. For some unknown reason scan_dir() is not
> able to read /home/user when run as Apache module. but the CLI is
> giving expected results. I did not find any work around, but had to
> read /var/www which is the home directory of 'apache' (this is the
> user under which apache runs by default. hence you script needs 777 to
> execute)
>
> So if every thing else fails I'll recommend you to move the script to
> /var/ww (usually your server root) instead of /home/user
>
That's a potential security flaw waiting to happen. A script like this
shouldn't be kept in a web-accessible directory.

Thanks,
Ash
http://www.ashleysheridan.co.uk




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Cannot exec in my own directory

am 17.08.2009 16:01:59 von Dotan Cohen

> Did you check SELinux options ??
>

I do not have root access to that server.

> I have a similar problem. For some unknown reason scan_dir() is not
> able to read /home/user when run as Apache module. but the CLI is
> giving expected results. I did not find any work around, but had to
> read /var/www which is the home directory of 'apache' (this is the
> user under which apache runs by default. hence you script needs 777 to
> execute)
>

Actually, it currently is 777. I thought it might be a permissions
problem so I 777ed it as a troubleshooting measure.


> So if every thing else fails I'll recommend you to move the script to
> /var/ww (usually your server root) instead of /home/user
>

I have no access to that directory.


--
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Cannot exec in my own directory

am 17.08.2009 16:02:47 von Dotan Cohen

> That's a potential security flaw waiting to happen. A script like this
> shouldn't be kept in a web-accessible directory.
>

Thanks, Ash. That directory is HTTP-password protected.

--
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Cannot exec in my own directory

am 17.08.2009 16:08:04 von Ashley Sheridan

On Mon, 2009-08-17 at 17:01 +0300, Dotan Cohen wrote:
> > Did you check SELinux options ??
> >
>
> I do not have root access to that server.
>
> > I have a similar problem. For some unknown reason scan_dir() is not
> > able to read /home/user when run as Apache module. but the CLI is
> > giving expected results. I did not find any work around, but had to
> > read /var/www which is the home directory of 'apache' (this is the
> > user under which apache runs by default. hence you script needs 777 to
> > execute)
> >
>
> Actually, it currently is 777. I thought it might be a permissions
> problem so I 777ed it as a troubleshooting measure.
>
>
> > So if every thing else fails I'll recommend you to move the script to
> > /var/ww (usually your server root) instead of /home/user
> >
>
> I have no access to that directory.
>
>
> --
> Dotan Cohen
>
> http://what-is-what.com
> http://gibberish.co.il
>

Just out of curiosity, have you been able to run even the most basic of
scripts from PHP, like a plain old BASH 'echo' statement or something? I
only ask, because sometimes within the shell scripts themselves are
calls to other command line programs (even something as simple as 'ls')
which need to be called using their full path because Apache has a
different path for shell scripts. Also, you said you used include files
in that same area. Is it possible that you are also trying to use one of
them inside your shell script, but because the paths are different, the
system cannot find the things you expect it to?

Thanks,
Ash
http://www.ashleysheridan.co.uk




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Cannot exec in my own directory

am 17.08.2009 16:23:30 von Dotan Cohen

> Just out of curiosity, have you been able to run even the most basic of
> scripts from PHP, like a plain old BASH 'echo' statement or something? I
> only ask, because sometimes within the shell scripts themselves are
> calls to other command line programs (even something as simple as 'ls')
> which need to be called using their full path because Apache has a
> different path for shell scripts.

ls, pwd, and other commands run fine. The only command in the called
shell script is /usr/bin/mysqldump which for some reason out of habit
I always type with the full path!


> Also, you said you used include files
> in that same area. Is it possible that you are also trying to use one of
> them inside your shell script, but because the paths are different, the
> system cannot find the things you expect it to?
>

No, there are no other files included in this instance. I only
mentioned it to show that PHP can read from that directory.

Thanks.

--
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Cannot exec in my own directory

am 17.08.2009 16:46:42 von kranthi

>> That's a potential security flaw waiting to happen. A script like this
>> shouldn't be kept in a web-accessible directory.
/var/www is not the document root. document root is /var/www/html so I
dont think there's a problem.

>> /var/www (usually your server root)
I am mistaken regarding this.

for details (the location of httpd.conf may vary depending on your
distro, but it is definitely located in /etc/)
$ cat /etc/passwd | grep apache
$ cat /etc/httpd/conf/httpd.conf | grep ^ServerRoot
$ cat /etc/httpd/conf/httpd.conf | grep ^DocumentRoot
$ cat /etc/httpd/conf/httpd.conf | grep ^User

>> I have no access to that directory.
seems you do not have access to any directory other than /home/user.
but i dont think there's a work around, you'll have to request your
administrator to move that file to /var/www directory (and retain
777).

>> ls, pwd, and other commands run fine.
i dont think "ls /home/user" will work fine.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Cannot exec in my own directory

am 17.08.2009 16:54:03 von Ashley Sheridan

On Mon, 2009-08-17 at 20:16 +0530, kranthi wrote:
> >> That's a potential security flaw waiting to happen. A script like this
> >> shouldn't be kept in a web-accessible directory.
> /var/www is not the document root. document root is /var/www/html so I
> dont think there's a problem.
>
> >> /var/www (usually your server root)
> I am mistaken regarding this.
>
> for details (the location of httpd.conf may vary depending on your
> distro, but it is definitely located in /etc/)
> $ cat /etc/passwd | grep apache
> $ cat /etc/httpd/conf/httpd.conf | grep ^ServerRoot
> $ cat /etc/httpd/conf/httpd.conf | grep ^DocumentRoot
> $ cat /etc/httpd/conf/httpd.conf | grep ^User
>
> >> I have no access to that directory.
> seems you do not have access to any directory other than /home/user.
> but i dont think there's a work around, you'll have to request your
> administrator to move that file to /var/www directory (and retain
> 777).
>
> >> ls, pwd, and other commands run fine.
> i dont think "ls /home/user" will work fine.

Why move the script to somewhere that he can't access? If the existing
PHP scripts are all in /home/user then Apache is set up to allow the
local user filespace to be used as a web server area. As such, there
wouldn't be much point in trying to put the script in /var/www (assuming
that Apache is set up to use /var/www at all, on Suse for example it
uses /srv/www/)

Thanks,
Ash
http://www.ashleysheridan.co.uk




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php