简体   繁体   中英

Laravel different environment git .env Xampp & Mamp

i'm using github in combination with laraval for the first time.

I have 2 local environments :

  • a) i use MAMP Pro for local development (Mac)
  • b) i use XAMPP for local development (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?.

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) ?

Error message when running the project on environment 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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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