[SOLVED] Running laravel sail's project from repository

Issue

Before going any further, I’ve been looking everywhere on how to run laravel sail’s project (including MySQL, Redis, etc) properly after cloning a repository without any local environments.
I have read some another questions and explanations, but still didn’t have any completed/proper answers.

I have tried to create a new fresh laravel project by using sail, then upload to git, and clone it again to my local machine with using different folder, then tried all of above links.

  • e.g For MySQL, I have tried to add php artisan migrate or run sail artisan migrate and it showed connection refused.
  • I have tried to build first before run sail up
  • I have tried to copy env example file

Until now, I only can run the sail (I can access the webpage) but not the databases and so on.

Thank you.

Solution

I have tried to create a new fresh laravel project by using sail, then upload to git, and clone it again to my local machine with using different folder, then tried all of above links.

Reproducing the steps based on the information you provided this is what I did:

Note: I will assume you already have docker installed.

curl -s https://laravel.build/test-app | bash

  • Go to project and sail up (wait until the output stops) just to test it out, you can sail down after:
cd test-app
 
./vendor/bin/sail up

./vendor/bin/sail down

  • Create a git repo in the project and push it to your host (I will assume you have git configured):
git init

git add .

git commit -m "Test app"

git remote add origin https://github.com/<your-username>/teste-app.git

git push --set-upstream origin master

  • Clone the repo to different folder:
git clone https://github.com/<your-username>/teste-app.git download_test-app

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

  • Check with docker ps if there is any container running (running container can cause issues if you don’t change Ports). If any container is running stop them with docker container stop <name of container OR ID of container>

  • Copy .env.example to .env. I changed where it has 127.0.0.1 to localhost. In the DB_HOST change the value to mysql

  • Run ./vendor/bin/sail/up and the app will start. Open the app on the browser (localhost:80 if you didn’t change ports).

  • Generate the app key either by clicking in the "Generate Key" button when you open your app in the browser or by running ./vendor/bin/sail artisan key:generate

  • Run migrations to test if database works ./vendor/bin/sail artisan migrate

And you are good to go. Hope that it helps!

Answered By – DGF

Answer Checked By – Willingham (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.