Search code examples
laravellaravel-sail

Laravel Sail Paradox - There are any way to install without php and composer installed?


Laravel Sail, has a good premisse to create a zero dependency environment, with, php, redis, mariadb etc...

But its instalation require composer, composer require php installed,

is this a paradox?

There are some way to achieve zero dependency, with docker installed?


Solution

  • edit

    I was listening to the laravel news podcast yesterday and the people from Laravel created a solution for this problem. They now have a section with a command that spins up a php container to install php dependencies through a container first and move them to your host computer.

    docker run --rm \
        -u "$(id -u):$(id -g)" \
        -v $(pwd):/var/www/html \
        -w /var/www/html \
        laravelsail/php81-composer:latest \
        composer install --ignore-platform-reqs
    
    

    As Sail gives you the option to manage the container from the host through Artisan, then no.

    If you don't mind to give up the ability to use Sail in this way and just want to set up a dockerized environment for Laravel, then yes. You can make a container for php in which you copy your project and through volumes maps to the host. You can enter a container (as if using ssh) through docker-compose exec <service> <command>, in the repo I linked, the php Dockerfile uses Alpine as the linux distro, which comes with the ash (instead of bash) shell. Because of his you can run

    docker-compose exec php ash
    

    to enter the container and run commands inside it.