3

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!

Kubus
  • 43
  • 4
  • Many typical `docker run` paths don’t actually read `.bashrc`, and putting things there in a Dockerfile isn’t a great practice. Just put things in directories that are already in the search/loader paths. – David Maze Nov 27 '18 at 15:07
  • Thanks for you comment. I moved the executable to `/usr/bin` and the lib to `/usr/lib`. The result is still the same. I found out that even if the lib is in a standard folder it is not found: `ldconfig -p | grep libassimp.so` in the php-fpm container delivers no result. Doing this in the workspace container works and the lib is found. Is it possible to tell php to execute a file from the workspace container and not from the php-fpm container? – Kubus Nov 27 '18 at 15:37

1 Answers1

3

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

smaftoul
  • 2,375
  • 17
  • 14
  • @reply Thanks for your hint. I tried what you suggested but still get the same error. What I did: `docker-compose stop workspace php-fpm` Added these lines to the .env file: ENV PATH="/usr/local/bin:${PATH}" ENV LD_LIBRARY_PATH=/usr/local/lib `docker-compose up -d workspace php-fpm` The issue is still the same, my php file returns 127. – Kubus Nov 27 '18 at 17:06
  • I can confirm now that it is an issue with the library path. When I build the executable without the need for an external library, everything works fine. So this is a usable workaround for me. – Kubus Nov 28 '18 at 09:20