简体   繁体   English

Laravel 不同环境 git .env Xampp & Mamp

[英]Laravel different environment git .env Xampp & Mamp

i'm using github in combination with laraval for the first time.我第一次将 github 与 laraval 结合使用。

I have 2 local environments :我有 2 个本地环境:

  • a) i use MAMP Pro for local development (Mac) a) 我使用 MAMP Pro 进行本地开发(Mac)
  • b) i use XAMPP for local development (Windows) b) 我使用 XAMPP 进行本地开发 (Windows)

I made a new repository and pushed to github on environment a) , I cloned this repository on setup b) and added a .env file to setup my database.我创建了一个新的存储库并在环境 a) 上推送到 github,我在设置 b) 上克隆了这个存储库并添加了一个 .env 文件来设置我的数据库。 However i'm a bit confused what to do with the app_key value, do i need to just copy it form my initial environment?但是我有点困惑如何处理 app_key 值,我是否需要从我的初始环境中复制它? or need a new one?.还是需要一个新的?。

The second part of my question is that i seem to have problems with xampp vs mamp pro because they rewrite a couple of urls, wich means my project won't run on environment b).我的问题的第二部分是我似乎对 xampp 与 mamp pro 有问题,因为他们重写了几个 url,这意味着我的项目不会在环境 b) 上运行。 Are there other settings i need to adjust?我还需要调整其他设置吗? and will it brake again if i commit on environment b) ?如果我对环境 b) 做出承诺,它会再次刹车吗?

Error message when running the project on environment b)在环境 b) 上运行项目时的错误消息

Warning: require(D:\dev.local\ADifferentDesign\bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in D:\dev.local\ADifferentDesign\bootstrap\autoload.php on line 17

Fatal error: require(): Failed opening required 'D:\dev.local\ADifferentDesign\bootstrap/../vendor/autoload.php' (include_path='.;C:\xampp\php\PEAR') in D:\dev.local\ADifferentDesign\bootstrap\autoload.p

I'm really confused , i saw other questions like this but none are quite what i was looking for.我真的很困惑,我看到了其他类似的问题,但没有一个是我想要的。

A good aproach for future projects would also be very much appreciated对未来项目的好方法也将不胜感激

Progress update 1 : I updated my .env file with the same key.进度更新 1 :我使用相同的密钥更新了我的 .env 文件。 But the error shown above still persists.但是上面显示的错误仍然存​​在。 I dont want to change te path in autoload every time i switch environments either.我也不想在每次切换环境时更改自动加载中的路径。

It depends.这取决于。 If you are sharing any resources that hold encrypted data between the two environments, like a database, then you must copy the app_key .如果您要在两个环境之间共享任何保存加密数据的资源,例如数据库,则必须复制app_key This is because Laravel uses the app_key whenever it encrypts something like a user's password or a session ID.这是因为 Laravel 在加密用户密码或会话 ID 之类的app_key时会使用app_key

If you don't need to share a database, sessions, etc then you can and should generate a new key for every environment.如果您不需要共享数据库、会话等,那么您可以并且应该为每个环境生成一个新密钥。

You generate a new key by running this command in your site root:您可以通过在站点根目录中运行此命令来生成新密钥:

php artisan key:generate

Ideally, you would run this command as the first step in setting up a new environment, before running database seeds or other stuff.理想情况下,在运行数据库种子或其他内容之前,您可以将此命令作为设置新环境的第一步。 This is because if you generate a new key after seeding your database then any password you created in the seeds will be invalid and you'll have to reseed the database.这是因为如果您在为数据库做种后生成新密钥,那么您在种子中创建的任何密码都将无效,您必须重新为数据库做种。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM