Laravel different environment git .env Xampp & Mamp

时间:2022-10-18 17:52:41

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. 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? or need a new one?.

我创建了一个新的存储库并推送到环境a)的github,我在安装程序b)上克隆了这个存储库并添加了一个.env文件来设置我的数据库。但是我有点困惑如何处理app_key值,我是否需要从初始环境中复制它?还是需要一个新的?

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). Are there other settings i need to adjust? and will it brake again if i commit on environment b) ?

我的问题的第二部分是我似乎与xampp vs mamp pro有问题,因为他们重写了几个url,这意味着我的项目不会在环境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. But the error shown above still persists. I dont want to change te path in autoload every time i switch environments either.

进度更新1:我使用相同的密钥更新了我的.env文件。但上面显示的错误仍然存​​在。每次我切换环境时,我都不想在自动加载中更改te路径。

1 个解决方案

#1


1  

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. This is because Laravel uses the app_key whenever it encrypts something like a user's password or a session ID.

这取决于。如果要共享在两个环境(如数据库)之间保存加密数据的任何资源,则必须复制app_key。这是因为只要加密用户的密码或会话ID之类的东西,Laravel就会使用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.

理想情况下,在运行数据库种子或其他内容之前,您将运行此命令作为设置新环境的第一步。这是因为如果在为数据库播种后生成新密钥,则在种子中创建的任何密码都将无效,您必须重新设置数据库。

#1


1  

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. This is because Laravel uses the app_key whenever it encrypts something like a user's password or a session ID.

这取决于。如果要共享在两个环境(如数据库)之间保存加密数据的任何资源,则必须复制app_key。这是因为只要加密用户的密码或会话ID之类的东西,Laravel就会使用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.

理想情况下,在运行数据库种子或其他内容之前,您将运行此命令作为设置新环境的第一步。这是因为如果在为数据库播种后生成新密钥,则在种子中创建的任何密码都将无效,您必须重新设置数据库。