从存储库运行 laravel sail 的项目

发布于 2025-01-11 05:38:19 字数 907 浏览 0 评论 0原文

在进一步讨论之前,我一直在到处寻找如何在没有任何本地环境的情况下克隆存储库后正确运行 laravel sail 的项目(包括 MySQL、Redis 等)。 我已经阅读了其他一些问题和解释,但仍然没有任何完整/正确的答案。

我尝试使用 sail 创建一个新的 laravel 项目,然后上传到 git,并使用不同的方法将其再次克隆到我的本地计算机文件夹,然后尝试了上述所有链接。

  • 例如,对于 MySQL,我尝试添加 php artisan migrate 或运行 sail artisan migrate 并显示连接被拒绝。
  • 我尝试在运行sail up之前先构建
  • 我尝试复制env示例文件

到目前为止,我只能运行sail(我可以访问网页),但不能运行数据库等。

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故事未完 2025-01-18 05:38:19

我尝试使用 sail 创建一个新的 Laravel 项目,然后上传到 git,并使用不同的文件夹再次将其克隆到我的本地计算机,然后尝试上述所有链接。

根据您提供的信息重现步骤,这就是我所做的:

注意:我假设您已经安装了 docker。

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

  • 转到项目并sail up(等到输出停止)只是为了测试它,您可以在之后sail down
cd test-app
 
./vendor/bin/sail up

./vendor/bin/sail down

  • 在项目并将其推送到您的主机(我假设您已配置 git):
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

  • 将存储库克隆到不同的文件夹:
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

  • 使用 docker ps 检查是否有任何容器正在运行(如果不更改,运行容器可能会导致问题端口)。如果任何容器正在运行,请使用 docker container stop <容器名称或容器 ID> 停止它们,

  • .env.example 复制到 .env 。我将其 127.0.0.1 更改为 localhost。在DB_HOST中将值更改为mysql

  • 运行./vendor/bin/sail/up,应用程序将启动。在浏览器上打开应用程序(如果未更改端口,则为 localhost:80)。

  • 生成应用程序密钥,方法是在浏览器中打开应用程序时单击“生成密钥”按钮,或者运行 ./vendor/bin/sail artisan key:generate

  • 运行迁移以测试数据库是否正常工作./vendor/bin/sail artisan migrate

一切顺利。希望对您有所帮助!

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!

旧人 2025-01-18 05:38:19

有时我对现有卷有问题,这些卷存在但已经构建了所有内容。因此,即使我添加一个新项目,它仍然使用不正确的卷。

请阅读下面的内容,它解释得更好。
Laravel Sail 重建默认数据库

所以我通常做的是在本地使用代理服务器开发人员。这样我就可以使用不同的项目并让它们一起交流。

编辑:: 我用于本地开发的解决方案
https://blog.devgenius.io/multi- laravel-sail-sites-with-custom-domain-e13c07d9dd0c

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文