Page 1 of 1

shell_exec problem! [Solved]

PostPosted: 04. December 2011 21:01
by said_fox
Hi,
I have xampp 1.7.4 on Ubuntu 11.10. I have problem with shell_exec function. It does not work for third party commands such as pdftotext. There is no any error message are returned from the script. Another thing, it is not return any errors for wrong commands such as:
shell_exec('blahblah').

It may run some original command such as dir. I don't know how to fix this problem? Does it permissions? does it PHP settings? I don't know!

Please help!

Re: shell_exec problem!

PostPosted: 04. December 2011 21:03
by Sharley
Would you be so kind as to add your XAMPP version and Operating System to your profile as per:
viewtopic.php?f=17&t=48626
Thanks. :)

Re: shell_exec problem!

PostPosted: 05. December 2011 15:17
by JonB
That is probably because on XAMPP the owner of httpd is 'nobody' - and thus lacks sufficient rights for system calls. Although you must START Apache as root on *nix systems, there is a de-escalation to prevent using httpd for hijacking. (for exactly the reasons that would be apparent).

You can use the 'top' command to validate this is true.

Google:
httpd process owner

There are a lot of discussions out there about the side-effects and how to tackle this, what can and cannot be done.

As LAMPP is not a standard LAMP Stack, you may not be able to change this behavior. (XAMPP/LAMPP is run by a bash script)

Good Luck
8)

Re: shell_exec problem!

PostPosted: 05. December 2011 18:01
by said_fox
JonB wrote:That is probably because on XAMPP the owner of httpd is 'nobody' - and thus lacks sufficient rights for system calls. Although you must START Apache as root on *nix systems, there is a de-escalation to prevent using httpd for hijacking. (for exactly the reasons that would be apparent).

You can use the 'top' command to validate this is true.

Google:
httpd process owner

There are a lot of discussions out there about the side-effects and how to tackle this, what can and cannot be done.

As LAMPP is not a standard LAMP Stack, you may not be able to change this behavior. (XAMPP/LAMPP is run by a bash script)

Good Luck
8)


I have got a way that allow error messages to be shown when using shell_exec, it is something like the following:
Code: Select all
echo shell_exec("pdftotext $path/1694.pdf $path/1694php.txt 2>&1");

The error messages shown are:
Code: Select all
pdftotext: /opt/lampp/lib/libjpeg.so.62: no version information available (required by /usr/lib/libpoppler.so.13)
pdftotext: /opt/lampp/lib/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /usr/lib/i386-linux-gnu/libstdc++.so.6)

I'm sure that the same command is run correctly from the terminal. So, is there any way to overcome this?

Re: shell_exec problem!

PostPosted: 05. December 2011 18:27
by JonB
Under the assumption (becasue you discussed PHP) you want these calls echoed to a web app/script - I don't know if it can be done. It 'might be' if the owner was apache as it is on a traditional LAMP stack - but that is not possbile with XAMPP. That would be because apache is a 'standard' user and is a member of the 'apache' group.

The user 'nobody' is a special user under unix derivatives - therein lies the problem. You could Google it or read through the bash files for lampp to see the notes. Its specifically to prevent webusers from inheriting special system privileges. I think its one of the few users that never belongs to a group (thus no inheitance).

What you (a user) can do at the term/console is a function of your (and the groups you belong to) privileges and ownership on the filesystem and the OS within itself - that does not directly translate over to being do-able by a script (the owner of the script process controls that). It WOULD translate to being do-able got a PHP script in CGI mode, as you would own the process - its an executable at that point. "My guess".

You might want to think about outputting those errors to a file that could be parsed.

This is all just what "I think" and as such is unsubtantiated.

Good Luck.

Re: shell_exec problem!

PostPosted: 07. December 2011 00:31
by said_fox
Hi,
Using shell_exec('whoami') returns www-data, I changed from, httpd.conf, User and Group to "said" and then whoami returned the user said, but the problem is still exists.

Re: shell_exec problem!

PostPosted: 07. December 2011 03:42
by JonB
That's the issue - you need almost certainly need to be root, and you SHOULD never be root running httpd. Could try assigned execute permissions on targeted commands scripts - who knows - "maybe" it will work. This is fundamentally an Apache process issue - due to the deescalation of rights once Apache is launched.

If you want to take a run at actually doing what you propose, you should build a standard Liinux LAMP stack, where you are not constrained by the 'bash' script (/opt/lampp/lampp) that runs 'XAMPP".

Good Luck
8)

Re: shell_exec problem!

PostPosted: 07. December 2011 15:17
by said_fox
said_fox wrote:
Code: Select all
echo shell_exec("pdftotext $path/1694.pdf $path/1694php.txt 2>&1");

The error messages shown are:
Code: Select all
pdftotext: /opt/lampp/lib/libjpeg.so.62: no version information available (required by /usr/lib/libpoppler.so.13)
pdftotext: /opt/lampp/lib/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /usr/lib/i386-linux-gnu/libstdc++.so.6)

I'm sure that the same command is run correctly from the terminal. So, is there any way to overcome this?


Finally, I have got the solution, I just searched for the two files ( libjpeg.so.62 and libgcc_s.so.1 ) in /usr and then I copied them and replaced them with those in /opt/lampp/lib.

Re: shell_exec problem!

PostPosted: 07. December 2011 17:28
by JonB
Well, that is a clever solution. I will need to add it to my 'tips and tricks' list.

Good Luck and thanks for posting the solution.

8)

Re: shell_exec problem! [Solved]

PostPosted: 31. August 2012 13:27
by sumit.madan
I dont find this ( libgcc_s.so.1 ) file in /usr directory.
Can anyone please tell me the path of file?

Re: shell_exec problem! [Solved]

PostPosted: 31. August 2012 20:36
by JonB
You don't mention the distribution or version of Linux you are using.

A. Its possible that you may not have libgcc_s.so.1 on your machine. Its also possible that is not a file but a symbolic link (to another location where the 'real file' is, often with another name.)

B. There should be a copy that came with your lampp distribution in /opt/lampp/lib

to locate all versions of libgcc_s.so.1,as root use the 'find' command from the filesystem root (note your actual file results will probaby be different than mine, I am on Fedora 15, with lampp 1.7.7. The process is the same.

Code: Select all
[root@localhost jonb]# cd /
[root@localhost /]# find -name libgcc_s.so.1
find: `./home/jonb/.gvfs': Permission denied
find: `./proc/2390/task/2390/ns/net': No such file or directory
find: `./proc/2390/task/2390/ns/uts': No such file or directory
find: `./proc/2390/task/2390/ns/ipc': No such file or directory
find: `./proc/2390/ns/net': No such file or directory
find: `./proc/2390/ns/uts': No such file or directory
find: `./proc/2390/ns/ipc': No such file or directory
find: `./proc/17759': No such file or directory
find: `./proc/17760': No such file or directory
./lib/libgcc_s.so.1
./opt/lampp/lib/libgcc_s.so.1
[root@localhost /]#


There may be different versions even on the same machine., and there is no way to know what 'you' need. Its not apparent form your question what the actual problem is. ("something" probably is complaining that it can't find libgcc_s.so.1)

Code: Select all
[root@localhost /]# cd /lib
[root@localhost lib]# ls -l libgcc_s.so.1
lrwxrwxrwx. 1 root root 28 Aug 15 21:13 libgcc_s.so.1 -> libgcc_s-4.6.3-20120306.so.1
[root@localhost lib]# cd /opt/lampp/lib/
[root@localhost lib]# ls -l libgcc_s.so.1
-rw-r--r--. 1 nobody root 32292 Nov 10  2009 libgcc_s.so.1
[root@localhost lib]# ls -l /lib/libgcc_s-4.6.3-20120306.so.1
-rwxr-xr-x. 1 root root 115328 Mar  6 12:24 /lib/libgcc_s-4.6.3-20120306.so.1
[root@localhost lib]# libgcc_s-4.6.3-20120306.so.1


Good Luck
8)

Re: shell_exec problem! [Solved]

PostPosted: 01. September 2012 08:00
by sumit.madan
hi @JonB I am using Ubuntu 11.04 and i checked today in /opt/lampp/lib folder both files are located there. But still my problem not solved. My Code is:
Code: Select all
shell_exec('/usr/local/bin/pdftotext test_copy.pdf test.txt');
echo file_get_contents("test.txt");

It is not creating file 'test.txt'

Re: shell_exec problem! [Solved]

PostPosted: 01. September 2012 16:17
by JonB
You have not said what the error message is...

However, I suspect you should copy those two files to /usr/local/bin/

The environment (Linux OS) does not 'know' that lampp exists (meaning that the search path does not include /opt/lampp/bin). :shock:

Good luck
:)

Re: shell_exec problem! [Solved]

PostPosted: 03. September 2012 05:04
by sumit.madan
@jonB hey my problem solved. Error message was this "/usr/local/bin/pdftotext: /opt/lampp/lib/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /usr/lib/i386-linux-gnu/libstdc++.so.6)"
and i rename my file from 'libgcc_s.so.1' to 'libgcc_s.so.1.bak' and it solved.

Re: shell_exec problem! [Solved]

PostPosted: 04. September 2012 13:33
by JonB
Ok, good - as long as it is working...

Good luck with XAMPP