Cannot run shell command via php exec, but can user on shell?

I am trying to get exiftool to work on my dedicated server. The problem is that PHP exec seems to work differently than when the command is run as a user. Oddly enough, PHP appears as the same user with whom I log in, but it does not behave the same with system commands.

Oddly enough, everything works fine on my localhost, but not on my server.

As already mentioned, executing exiftool commands registered in ssh is excellent.

But it works in php testing script (note that I installed exiftool for each directory under test, and it goes through ssh), nothing is available, although it works as an orangeman user ...

And he fails

Below is the update - it's all day:

On the shell:

-bash-4.1$ which exiftool -a
~/perl5/bin/exiftool
/usr/bin/exiftool
~/perl5/bin/exiftool

In php shell_exec('exiftool -a');

/usr/bin/exiftool

And here is what this file refers to:

lrwxrwxrwx    1 root root          33 May 15 02:10 exiftool -> /home/orangeman/perl5/bin/exiftool

I also tried creating symbolic links of different types by faking the main variable $ PATH through putenv();in php ... I'm really in the dark here. It works on the local host, and not on a dedicated server.


I updated this with generosity - this is a serious development problem.

I am on a dedicated server, and the problem is as described above.


UPDATE At the suggestion of @gcb, I was able to print the error that occurs when the php function exec () runs the system command without effect.

Php

<?php
exec('exiftool 2>&1', $output, $r);
var_dump($output, $r);
?>

Conclusion:

array(2) {
  [0]=>
  string(230) "Can't locate Image/ExifTool.pm in @INC (@INC contains: /bin/lib /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /bin/exiftool line 33."
  [1]=>
  string(59) "BEGIN failed--compilation aborted at /bin/exiftool line 33."
}

UPDATE

Decision

@gcb. Thank you very much.

+4
source share
4

, php, perl. .

http://u88.n24.queensu.ca/exiftool/forum/index.php?topic=2217.0

You either have to install the ExifTool libraries in the
standard location (ie. somewhere in the @INC directories
listed in your post), or add the location to the include path,
something like this:

Code:
#!/usr/bin/perl
BEGIN { unshift @INC, "PATH_TO_DIRECTORY_CONTAINING_LIBRARIES" }
use Image::ExifTool;

You should be able to add "Image/ExifTool.pm" to the path you add
to find the ExifTool module.

- Phil

, № 3 . , , perl script, @INC php. , , script php php shell_exec, ...

( , ) , PERLLIB var script.

, :

  • find / -name ExifTool.pm , ​​lib. , /example/perl/Image/ExifTool.pm
  • PERL5LIB=/example/perl/ exec().
  • exec ( "PERL5LIB =/example/perl/sudo/var/www/myscript/execscript.sh {$ param}" );
+5

0), . /var/log/apache/error

, " " - .

1), , - . exiftool 2>&1. stderr stdout, . , , php . passthru exec

2) exec dir

exec dir. :

http://www.php.net/manual/en/ini.sect.safe-mode.php#ini.safe-mode-exec-dir

3) , , , ssh. exec shell_exec

... , .

+2

, $PATH / $HOME/.bashrc, $HOME/.bash_profile, . PHP -, "orangeman" , , $PATH , . export PATH="what:you:want:your:PHP:path:to:be" $HOME/.bashrc?

+1

I believe this is because you have a private perl installation for the user.

Basically, @INC is an array that perl uses to find its library, and it does not contain the path to your installation library.

There are several ways to change @INC, which you can find at the following link:

http://perlmaven.com/how-to-change-inc-to-find-perl-modules-in-non-standard-locations

Hope this helps.

+1
source

Source: https://habr.com/ru/post/1540577/


All Articles