'Running laravel sail's project from repository
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.
- this answer only tell of how to have sail in that project
- this question has no answers until this question posted
- this one also only tell of how to have sail in that project
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 migrateor runsail artisan migrateand 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 1:[1]
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.
- Install a new laravel project (https://laravel.com/docs/9.x#your-first-laravel-project):
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 cansail downafter:
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
- Install composer dependencies without having local dependencies (https://laravel.com/docs/9.x/sail#installing-composer-dependencies-for-existing-projects):
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 psif there is any container running (running container can cause issues if you don't change Ports). If any container is running stop them withdocker container stop <name of container OR ID of container>
- Copy
.env.exampleto.env. I changed where it has127.0.0.1tolocalhost. In theDB_HOSTchange the value tomysql
- Run
./vendor/bin/sail/upand 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!
Solution 2:[2]
Sometimes I have issues with existing volumes, those volumes exist but already have everything build. So even if i add a new project it still uses the incorrect volume.
please read below it explains it a lot better. Laravel Sail rebuild default database
So what I normally do is use a proxy server on my local dev. so I can use different projects and can let them communicate together.
Edit:: the solution i used for local development https://blog.devgenius.io/multi-laravel-sail-sites-with-custom-domain-e13c07d9dd0c
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Marcel Santing |
