LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-06-2012, 05:07 AM   #1
Bronta
LQ Newbie
 
Registered: Oct 2011
Posts: 4

Rep: Reputation: Disabled
Different results - running program from bash and PHP


Hello everybody,

I am using CentOS 5.6 and I have problems executing programs from PHP. When I run the same command from bash as root, it works fine.

Example:
PHP script I am executing:
PHP Code:
<?php

 
echo (shell_exec("/opt/bin/mediainfo --Inform=file:///var/www/html/test/media_general.txt /var/www/html/test/video/2046.flv")); 

?>
When I run this script, it does not produce any input, in error log, it shows
Code:
/opt/bin/mediainfo: error while loading shared libraries: libmediainfo.so.0: cannot open shared object file: No such file or directory
When I run command
Code:
/opt/bin/mediainfo --Inform=file:///var/www/html/test/media_general.txt /var/www/html/test/video/2046.flv
in bash as root, it works fine, gives the output it should give.

I am new to Linux, but is it because Apache does not have enough rights? The file /opt/bin/mediainfo has 0777 permissions, owner root, group root. I execute from PHP more similar programs, some run fine, but some give an error, usually they cannot load some libraries. Can it be fixed somehow?

Thanks in advance for any help.
 
Old 10-07-2012, 10:51 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
You may have different PATH variables. In bash, run

Code:
echo $PATH
and in PHP

PHP Code:
<?php echo ini_get('include_path'); ?>
and compare the results my guess is that the folder with libmediainfo.so.0 is in bash's path but not PHP's.

Hope this helps,
 
Old 10-07-2012, 02:09 PM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,397
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
It is probably an environment variable difference, but I don't think it is $PATH. $LD_LIBRARY_PATH will affect how the linking loader finds libraries. You can do something to set $LD_LIBRARY_PATH before the script runs. I don't know how to set environment variables from within PHP, but I assume it is possible. You can configure ld to search the correct directory globally and permanently by using the ldconfig tool.

--- rod.
 
Old 10-08-2012, 02:53 AM   #4
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
*facepalm* yeah, of course, we're on about libraries. Ooops.

To change the LD_LIBRARY_PATH environment variable from within PHP, you need to use putenv, but from what the page says you may have difficulty if your PHP is configured to be in 'safe mode'.

Regards,
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash: Check if a program is running naimslim89 Programming 12 05-08-2012 10:24 PM
Running a bash script in PHP Nerdstock2005 Programming 14 12-09-2008 03:28 PM
Using PHP, run bash script and see results on Server's Monitor xmrkite Linux - Software 6 10-17-2006 01:28 PM
Running bash commands from php. rookiepaul Linux - General 3 03-22-2006 02:22 AM
[bash] running a GUI program as root billiejoex Linux - General 3 01-02-2006 01:21 PM


All times are GMT -5. The time now is 10:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration