I am LOST - pi > docker > nginx > php > install Composer for phpseclib

  • pi > docker > nginx > php > install Composer for phpseclib


    Really need some expert guidance here. I have been researching and reading and I just can't see this clearly with my limited knowledge and understanding.


    I have a Pi4, OMV6, with Docker. Portainer in my browser.


    As far as I understand it, the Docker consists of Containers, and each Container operates as a separate entity.


    One of the Containers is for nginx. nginx runs a web server and uses php.


    I have a shared folder on the pi ssd, at /srv/dev-disk-by-label-NAShd1/www

    This directory contains the php scripts that I can access from my browser, like : http://192.123.1.123/MYdata/phpinfo.php


    All working great so far.


    One of my php scripts creates a data file ( 1 - 4 mb ) that I need to upload to 2 remote FTP servers.

    The 2 remote FTP servers recently changed that uploads can only be done using SFTP.


    To do the SFTP upload, I need to use the phpseclib library.

    Version 3 of the phpseclib library requires 'composer' to use the library.


    So I am completely lost on where or how to install 'Composer'.

    Do I ssh to the pi IP and do it there ?

    or in a different directory ?

    or do I need to Console in to the nginx Docker Container and install there ? which directory ?

  • I'd just add the following to your Dockerfile:

    PHP
    RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
        && php composer-setup.php \
        && php -r "unlink('composer-setup.php');" \
        && mv composer.phar /usr/local/bin/composer \
        && apt-get -y install git unzip
    RUN composer require phpseclib/phpseclib:~3.0

    You might need to cd into the appropriate directory if your Dockerfile's WORKDIR isn't set.


    Also, in theory, with Composer, you ought to be doing "composer install" every time you clone the repo, which would mean that doing RUN composer require phpseclib/phpseclib:~3.0 in the Dockerfile is *not* what you should be doing but tbh idk that you are.

  • I'd just add the following to your Dockerfile:

    Thanks neubert

    I did ( to a point ) get it working late last night, and I think I have recalled the steps correctly and listed below :



    I now have, in my MYdata folder ( where all my php script files reside that I can run from my browser ), the following :


    now it breaks my test php script, which is to upload the file to the SFTP server ( all previously working with phpseclib v1 ) :

    It seems to be so close, but unless I can find more brain cells, it seems the solution is constantly just out of reach.

  • update :

    Found I was missing the autoload.php line at the start - but still not working :


  • by trial and error and completely by accident, I found that this code works :


    I just can not figure out what / where phpseclib3 is ??


    Code
    $CodeRoot = dirname(__FILE__);
    
    
    require __DIR__ . '/composer/vendor/autoload.php';
    
    
    use phpseclib3\Net\SFTP;
    
    
    $ftp_conn11 = new SFTP($ftpServer);

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!