charleskwakye's avatar

Running existing laravel project with laravel sail and docker

I want to open an existing laravel project with laravel sail. But while following the steps in the laravel sail documentation I get an error[ Could not open input file: artisan] when I run [php artisan sail:install]. The project folder does not contain artisan and I have tried adding this manually but I get other errors.

0 likes
14 replies
MohamedTammam's avatar

You need to have php and composer to install project packages including sail. If you don't have those installed in your machine, Which I suppose, you should do the following.

  1. Run your docker composer docker compose up -d
  2. Run docker compose run [your_php_service_name] php composer install
  3. Now you can kill your container docker compose down
  4. Then use sail normally vendor/bin/sail up -d
  5. The is according to normal Laravel setup like creating .env file and running migrations etc. ...
1 like
Sinnbeck's avatar

@charleskwakye try this. Open the project in the terminal and run

docker run --rm --interactive --tty \
  --volume $PWD:/app \
  --user $(id -u):$(id -g) \
  composer install

After that try vendor/bin/sail up

1 like
charleskwakye's avatar

@Sinnbeck I got this error [Composer could not find a composer.json file in /app To initialize a project, please create a composer.json file. See//getcomposer.org/basic-usage] I checked the website but it is a bit confusing. Any help will be appreciated

johnrem10's avatar

@MohamedTammam hello I have a question when I'm running the docker and add a phpmyadmin container in the docker yml the docker is not detecting the database credentials in my .env, that's why i can't open the phpmyadmin. Can you help me with that one? Thank you

MohamedTammam's avatar

@johnrem10 That's phpmyadmin setup for docker and sail

phpmyadmin:
        image: 'phpmyadmin:latest'
        ports:
            - '${PHPMYADMIN_PORT:-8080}:80'
        networks:
            - sail
        environment:
            PMA_USER: "${DB_USERNAME}"
            PMA_PASSWORD: "${DB_PASSWORD}"
            PMA_HOST: 'mysql'
        depends_on:
            - mysql
        restart: always

Please create new thread if you have further questions. I would be happy to help more.

martinbean's avatar

@charleskwakye Laravel has came with artisan for as long as I can remember, so this sounds like you either have an incomplete repository, trying to run artisan from the wrong directory, or just doing something else wrong.

1 like
charleskwakye's avatar

@martinbean my mates were able to run it with homestead but you can take a quick look at it [//github.com/pverhaert/learn_php8]. Any help will be well appreciated.

Sinnbeck's avatar

@charleskwakye sadly not. So you might be able to set up some custom docker for it but sail won't work sadly

You could try lando instead. It's an alternative to sail but works with any php project. I use it myself for various non laravel projects

1 like
Zuby's avatar

Ok so I saw this in the laravel documentation 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 and I used it. It was successful. But now I don't know what to do next. composer require laravel/sail --dev doesn't work. I did docker run composer require laravel/sail --dev and it ran and installed stuff but I still can't run vendor/bin sail anything, its instead trying to access the php stored on my windows system (I'm working in the WSL Ubuntu environment)

Please or to participate in this conversation.