Uncaught Error: Call to undefined method Dotenv\Dotenv::createUnsafeImmutable() - 500 Error

Hi,

I’ve recently inherited a number of projects from a dev that has left the company, and I’m trying to start up a local version of a site. I’m using MAMP and this is a Sage / Bedrock based WordPress site.

When i try to the view the site I get a 500 server error. When I check the php_error.log I get -

PHP Fatal error: Uncaught Error: Call to undefined method Dotenv\Dotenv::createUnsafeImmutable()

Do you have any advice for fixing the error?

I’m a bit new to Sage / Bedrock so please let me know if you need more information about the problem :slight_smile:

Thanks!

Is there a .env file in the project? Environment Variables | Bedrock Docs | Roots

Hi,

Yes and it appears to be setup correctly, correct url, database details correct.

Just as a sanity check, have you run composer install from the project root? If so, maybe check the version of vlucas/dotenv that’s installed and compare the requirements of that with the composer version on your machine.

Hi,

Thanks for your help and patience!

I have version 2.3.5 of composer installed, and I have run it in the root.

Can you tell me how I would check the version of vlucas/dotenv I have installed? I can see Dotenv.php but there appear to be no version details in there.

composer show vlucas/phpdotenv

I’m asking because I remember the transition to composer 2.0 required a version update to phpdotenv. I think phpdotenv v5+ is needed. See: Upgrade to vlucas/phpdotenv:5.2 (#563) · roots/bedrock@a623416 · GitHub

My initial thought was that if this was an old site, it could have used the older version of phpdotenv, but looking over your error again, it looks like you’re using a newer version of bedrock so that might not be the issue.

Have you tried setting up a fresh bedrock install in your dev environment? That might give you a clue about whether or not the issue is in your inherited project or on your machine

1 Like

Thanks, yes I’m working my way through a fresh install, if nothing else I’m learning about sage and bedrock :slight_smile: Thanks for your help!