Snipe-it: Upgrading to v5 - The environment file is invalid!

Created on 20 Oct 2020  路  24Comments  路  Source: snipe/snipe-it

Expected Behavior (or desired behavior if a feature request)

For upgrade to work


Actual Behavior

After upgrading to v5, web browser view is empty. Caches/cookies cleared. Performed composer commands, but cannot perform php commands because it says "The environment file is invalid!"

App was working fine prior to upgrading to v5, so I don't believe .env file is broken in any fashion.


Please confirm you have done the following before posting your bug report:


Provide answers to these questions:

  • Is this a fresh install or an upgrade? Upgrade
  • Version of Snipe-IT you're running. 5.0
  • Version of PHP you're running - Zend OPcache v7.2.31-1+ubuntu18.04.1+deb.sury.org+1
  • Version of MySQL/MariaDB you're running - Ver 10.1.47-MariaDB-1~bionic
  • What OS and web server you're running Snipe-IT on
  • What method you used to install Snipe-IT (install.sh, manual installation, docker, etc) - install.sh
  • WITH DEBUG TURNED ON, if you're getting an error in your browser, include that error - Nothing appears in browser
  • What specific Snipe-IT page you're on, and what specific element you're interacting with to trigger the error - Cannot get anything to appear in browser
  • If a stacktrace is provided in the error, include that too.
  • Any errors that appear in your browser's error console.
  • Confirm whether the error is reproducible on the demo: https://snipeitapp.com/demo.
  • Include any additional information you can find in storage/logs and your webserver's logs.
  • Include what you've done so far in the installation, and if you got any error messages along the way.
  • Indicate whether or not you've manually edited any data directly in the database - No

Please do not post an issue without answering the related questions above. If you have opened a different issue and already answered these questions, answer them again, once for every ticket. It will be next to impossible for us to help you.

https://snipe-it.readme.io/docs/getting-help

Most helpful comment

what I don't understand is that they kept saying they were postponing launching 5 to make sure everything works right. I cannot fathom that no one had this issue during dev/qa.

I got the impression that this was extensively tested.

Hi, I'm "they".

It was extensively tested. When you run a project as large as ours that handles as many different platforms, OS's, versions of software, etc, I'd be happy to learn from you how to do it better. In the meantime tho...

In (literally) months of testing, we have not seen this issue. I promise you, I would not have released this if it were a thing we ever encountered.

We have already upgraded several customers, and they have not had this issue. While I believe you, and I agree it's important to fix, without the ability to reproduce it (which we have not yet been able to do), it makes this very difficult.

If you can post your .env file (redacting passwords, etc but keeping quotes (single and double, should they exist) intact, that would help a lot.

We did add some additional variables (which can be found in the docs), but they were all designed to fail properly, where if you didn't add that new env var, it still should work.

Please try deleting your vendors directory and running composer install --no-dev again, and let me know how you fare.

And also please try being less of an ass.

All 24 comments

馃憢 Thanks for opening your first issue here! If you're reporting a 馃悶 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

I got this & commented out the REDIS_PORT=null in my file (which the upgrade script did not seem to like). Then re-ran the upgrade and got a whole host of other issues (including the db issue in #8541). I rolled back to v4.

I got the impression that this was extensively tested. How do I roll back?

@WELLBOREIS I installed via git so I checked out the commit for 4.9.5, re-ran the manual upgrade process (composer install, etc.), cleared all the caches, and it came back up on 4.9.5 just fine. I don't think the script managed to migrate the db for v5 initially, so I narrowly avoided having to restore the old db from backups.

@nbently, what I don't understand is that they kept saying they were postponing launching 5 to make sure everything works right. I cannot fathom that no one had this issue during dev/qa.

@WELLBOREIS I suspect our environments are slightly different from what was being tested. Not a huge deal, I didn't expect a major upgrade to go off without a hitch. I am sure we'll get it figured out soon. I only wish I had saved the logs from the initial upgrade attempt. That said the first problem I encountered was definitely what @cmaliwat references in this issue and the second problem (after re-running the upgrade script) was definitely the database connection error. Hopefully that is enough to start narrowing down the potential cause.

@cmaliwat Any news?

what I don't understand is that they kept saying they were postponing launching 5 to make sure everything works right. I cannot fathom that no one had this issue during dev/qa.

I got the impression that this was extensively tested.

Hi, I'm "they".

It was extensively tested. When you run a project as large as ours that handles as many different platforms, OS's, versions of software, etc, I'd be happy to learn from you how to do it better. In the meantime tho...

In (literally) months of testing, we have not seen this issue. I promise you, I would not have released this if it were a thing we ever encountered.

We have already upgraded several customers, and they have not had this issue. While I believe you, and I agree it's important to fix, without the ability to reproduce it (which we have not yet been able to do), it makes this very difficult.

If you can post your .env file (redacting passwords, etc but keeping quotes (single and double, should they exist) intact, that would help a lot.

We did add some additional variables (which can be found in the docs), but they were all designed to fail properly, where if you didn't add that new env var, it still should work.

Please try deleting your vendors directory and running composer install --no-dev again, and let me know how you fare.

And also please try being less of an ass.

@cmaliwat @WELLBOREIS check out https://github.com/snipe/snipe-it/issues/8553#issuecomment-713214909, it may help you fix the issues you've been having.

After changing REDIS_PORT-null into REDIS_PORT=null and running upgrade.php again, I can now get into the Web UI, however, I can't see any assets. I tried all the steps posted by @nbently but that did not help resolve the issue.

Edit:
After putting it into debug mode, I can see assets.

Here are the logs in debug:
https://pastebin.com/djFJuiHH

Also try clearing the various caches.

php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear

And I also deleted the vendor/ directory & did a fresh install of all dependencies using php composer.phar install --no-dev --prefer-source

Well we were going to buy the support plan until @snipe called me an ass. Very professional by the way. What I was getting at was more that I did something wrong than you as so many people had tested already and that you would not release a buggy version.

@nbently thank you for your help which led to fixing the issue. You were very professional and courteous.

I had the same issue as @cmaliwat and @WELLBOREIS. Luckily, my install is on a VM and I just rolled back to a snapshot I created before upgrading.
Will try again with @nbently's suggestion.

I had the same issue as @cmaliwat and @WELLBOREIS. Luckily, my install is on a VM and I just rolled back to a snapshot I created before upgrading.
Will try again with @nbently's suggestion.

@nbently's suggestion fixed that issue but caused another one regarding public storage directories files. Replacing the public/upload files with the ones from storage/app/public didn't help for me. In the meantime, I guess I will roll back until this gets figured out.

I didn't have any images either though copying them over to public/uploads but looking at the path I noticed they were http and not https which my site is running over. So I just changed the .env APP_URL=https://yoursite.com
A couple of flaws still but its new and computers are hard :) I'm pretty happy after all :)

Btw was this behavior commented anywhere? Is it a server misconfiguration or a problem with the upgrade.php script?

"Step 11: Checking for v5 public storage directories:

  • Public storage directory already exists. Skipping...

  • Copying files into storage/app/public.

PHP Warning: unlink(/var/www/html/snipeit/public/uploads/companies): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/companies): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/categories): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/categories): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/assets): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/assets): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/departments): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/departments): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/models): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/models): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/accessories): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/accessories): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/avatars): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/avatars): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/manufacturers): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/manufacturers): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/suppliers): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/suppliers): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/barcodes): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/barcodes): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/components): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/components): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/locations): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/locations): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/consumables): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/consumables): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(public/uploads): Is a directory in /var/www/html/snipeit/upgrade.php on line 249

  • Copy failed - you should do this manually by copying the files from public/uploads into the storage/app/public directory."
YourSite.com
Start Your Site & Connect With The World. Create your website and go online now! All plans include custom mailboxes and web hosting.

@jovibroz thanks so much for these error messages. I think I have an idea of what may be happening. The errors there wouldn鈥檛 be related to the env file, but I definitely need to take a look there as I think it might be related to some image issues some folks are seeing. Laravel wants you to use the app/storage/public dir, but we didn鈥檛 want people to have to move files around, so we override that. It鈥檚 possible that the upgrade script never got changed to reflect the overrides.

All - there are a few other issues that have been raised in this ticket, so I just wanted to give a bit of a roundup for this particular issue.

If you're seeing an "environment file is invalid" error, it most likely is what it says on the tin. Since Laravel's .env parser is more strict in later versions, it means that where some inconsistencies might have been permitted before, they might not be now. That error comes from the framework itself, not from us, so it means it can't even load the .env file because there is some kind of syntax error.

The first thing to check would be to make sure your values in your .env file are enclosed in quotes if they have any "weird" characters in them. (We mention this in the docs since v3, but sometimes stuff gets missed.) Also check for trailing spaces or funky hidden characters, and mismatched quotes (opening quote with no closing quote, etc). Unfortunately, these can be hard to debug, since you basically have to eyeball it, but once it's handled, all should be well.

At the end of the day, this is kinda good news. It means the code is working, and your env just needs a little cleanup. Whenever you do an upgrade, especially a big fat one like this where nearly every library has changed, you'll always want to run the commands listed here: https://snipe-it.readme.io/docs/common-issues

If you're using the upgrade.php script, it does a lot of that for you, but if you're not, you can run those commands manually. (They will never cause issues - you can run them over and over, and they won't break anything.) Also if you're using the upgrade.php script, it's possible it won't be able to complete some of those tasks (if there are permissions issues, etc) so it's never a bad idea to run them manually.

And one more thing you can try is to delete the contents of the vendors directory and then re-run composer install --no-dev. This will remove the libraries we use, and then re-add them. (Composer is a great system, but I've definitely seen it happen where it upgrades the library but doesn't remove some of the old files, which can cause issues.) You typically shouldn't need to do this, but it will never hurt to try it. Also pay attention to any output that you might see during that composer install, as it might try to tell you that you're missing a PHP extension that's required.

Snipe-IT Documentation
These commands should be run from your Snipe-IT project root, just like every other cli command we mention. They should not need to be run as root/sudo/admin.These commands clear out cached service files that help speed up modern PHP applications but can also very occasionally be out of date, resu...

I also realize this all seems like quite a pain in the ass - and it kinda is. But that's just kinda how modern frameworks work these days. Sigh. It's not a choice we make, nor anything we can mitigate. It's just the ecosystem. (I can complain a lot, but node/npm is worse lol)

On the upside, you typically only ever need to go through these steps during very significant upgrades. Point releases don't usually require this level of care and feeding. It's just that everything tries to cache stuff to make things faster (yay, helping!), and sometimes those caches don't get blown out/updated/refreshed as expected.

As they say...

There are only two hard things in Computer Science: cache invalidation and naming things. -- Phil Karlton

Now that 5.0.1 has rolled out, all I had to do was change REDIS_PORT-null in the .env file and run php upgrade.php again. I am not getting the public storage directories error again. Works great now.
Thanks @snipe

I didn't have any images either though copying them over to public/uploads but looking at the path I noticed they were http and not https which my site is running over. So I just changed the .env APP_URL=https://yoursite.com
A couple of flaws still but its new and computers are hard :) I'm pretty happy after all :)

Btw was this behavior commented anywhere? Is it a server misconfiguration or a problem with the upgrade.php script?

"Step 11: Checking for v5 public storage directories:

  • Public storage directory already exists. Skipping...
  • Copying files into storage/app/public.

PHP Warning: unlink(/var/www/html/snipeit/public/uploads/companies): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/companies): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/categories): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/categories): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/assets): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/assets): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/departments): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/departments): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/models): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/models): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/accessories): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/accessories): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/avatars): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/avatars): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/manufacturers): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/manufacturers): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/suppliers): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/suppliers): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/barcodes): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/barcodes): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/components): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/components): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/locations): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/locations): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/consumables): Is a directory in /var/www/html/snipeit/upgrade.php on line 249
PHP Warning: unlink(/var/www/html/snipeit/public/uploads/consumables): Is a directory in /var/www/html/snipeit/upgrade.php on line 246
PHP Warning: unlink(public/uploads): Is a directory in /var/www/html/snipeit/upgrade.php on line 249

  • Copy failed - you should do this manually by copying the files from public/uploads into the storage/app/public directory."

YourSite.comBest Website Builder Online | YoursiteStart Your Site & Connect With The World. Create your website and go online now! All plans include custom mailboxes and web hosting.

I tired running php upgrade.php again after 5.01 and got the same PHP unlink warning and the results are images getting moves to the app dir instead of public/uploads
Easily fixed by cp them back but would rather not have to :)

YourSite.com
Start Your Site & Connect With The World. Create your website and go online now! All plans include custom mailboxes and web hosting.

I tired running php upgrade.php again after 5.01 and got the same PHP unlink warning and the results are images getting moves to the app dir instead of public/uploads

That code was removed though, so I'm not sure why you'd be seeing that

https://github.com/snipe/snipe-it/commit/90dddee923f4274400dde794e5d008e55f4720c4#diff-dea6e5c43f67267b15b05bd95702fd29f4a146561e47dc7ca424832b6ee0ab20

I was very "tired" when I tried apparently :)
I somehow thought I was already on 5.01 when the script reached Step 11 in the v5.0 upgrade.php...
Sorry.
All good and no Step 11 present in 5.01
Going for 5.02 right about.. now!

Everything seems to be fine now with newer versions of v5.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ericdude101 picture ericdude101  路  5Comments

sbenoit89 picture sbenoit89  路  5Comments

snipe picture snipe  路  3Comments

snipe picture snipe  路  3Comments

alextheberge picture alextheberge  路  4Comments