简体   繁体   中英

Docker: calling an executable from php does not work

I have set up a Laradock environment with Nginx and php-fpm containers running. From PHP I want to call an executable:

<?php
    print exec('whoami'); // www-data
    echo "<br>";
    exec('/usr/local/bin/assimp version', $output, $returnValue);
    print $returnValue;   // 127
    echo "<br>";
    print_r($output);      // Array ( ) 
?>

The return value 127 sounds to me as if the file is not found...

But when I enter the container with the user "www-data" everything works fine:

docker-compose exec --user www-data php-fpm bash
assimp version // -> valid info response

As I was unsure if the executable has to be placed in "workspace" or in the php-fpm container I tried both with the same result. Also putting the executable in the /var/www directory did not help.

The executable was added by the Dockerfile:

USER www-data
COPY ./assimp /usr/local/bin/assimp
COPY ./libassimp.so.4.1.0 /usr/local/lib/libassimp.so.4.1.0
RUN ln -s /usr/local/lib/libassimp.so.4.1.0 /usr/local/lib/libassimp.so
RUN chmod 777 /usr/local/bin/assimp
RUN echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc
RUN echo 'export LD_LIBRARY_PATH=/usr/local/lib' >> ~/.bashrc

Any ideas how to fix this issue or how to continue with the debugging? Thanks in advance!

Return code 127 is for a file not found, but not necessarily the one your are executing. Here you setup some libs, but when the docker container is executed, your bashrc is not read, thus, the dynamic loader ( /lib/ld-linux[...].so ) doesn't find your libassimp.so.4.1.0 thus, the process returns 127.

You should set your PATH and LD_LIBRARY_PATH with Dockerfile's ENV directives like this:

ENV PATH="/usr/local/bin:${PATH}" ENV LD_LIBRARY_PATH=/usr/local/lib

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM