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.
- 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 migrate
or runsail 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.
- 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 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
- 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 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 withdocker container stop <name of container OR ID of container>
- Copy
.env.example
to.env
. I changed where it has127.0.0.1
tolocalhost
. In theDB_HOST
change the value tomysql
- 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)