Roots Discourse

Homestead ( vagrant ) + bedrock - Database Installation Error

Literally been troubleshooting this for hours. Not sure what I’m missing here but I haven’t been able to find a solution via google.

DB is setup in Sequel Pro, .env file is in the proper place ( …bedrock/web ).

If I create a proper wp-config file in my wp folder, the site loads fine. If I use those same DB credentials in the .env, I get a DB error. All are attached.

If you’ve seen this issue before or know what I might be doing wrong I’d really appreciate it, thanks.

Have you checked that the values from the .env file are actually used? If not, start debugging by doing that.

AFAIK the env file should not be in the web directory but instead at the top level where for example composer.json resides.

It should be in the bedrock directory, not the web directory, or at least that’s where it should be for a Trellis-made VM.

Thanks for the input so far guys. I have attempted to put this .env file in every directory ( where my bedrock folder exists, where the web folder exists, inside the web folder, even before bedrock where my code/project folder exists ). Still I get the same DB connection error.

Still, have a wp-config file renamed to wp-config2 with the same info that is contained in my .env file and if I make it a proper wp-config, the site boots up correctly.

I have not check if the values from the .env file are actually being used, but I am going to assume they’re not. Not sure how to go about debugging if the .env file is being used correctly or not, can you point me in the right direction there if you think that would get me closer to a solution?

Check config/application.php since that’s where the .env file is loaded.

Looks to be pulling in the values correctly. I have also made no edits to the applications.php file.

38%20PM|390x500

What else can be done? Must be some sort of issue on my end, maybe I’m missing some kind of install or package? Couldn’t find any similar issues to mine through google. I’ve watched just about every Youtube video on the topic. Can’t seem to target why my Sequel Pro DB won’t load through my .env file.

Any chance I can screenshare with someone and get another set of eyes on my setup/file structure?

Just to be sure: what if you var_dump(env('DB_USER')) on for example line 35?

If that does not give you the correct value, make sure that the file_exists on line 28 returns true.

You may also want to dump $root_dir to make sure that you have put the .env file in the correct location (which should be the one i mentioned in my first post).

If file is loaded correctly but the values are wrong maybe theres an issue with quotes in the .env-file? Test using double and single.

The above are the first steps I would take to try to find whats causing the error.

Great idea with the var_dump(env(‘DB_USER’)), ran a few more of them to troubleshoot. Looks like the .env file is pulling the proper data. Tested using no quotes, single quotes, and double quotes, still no success. But possibly it isn’t a DB error issue anymore since it does seem to be pulling in the correct values. Here is the error that is shown now on the wp-admin page.

I can provide all of the errors listed on the page if necessary, but most relate to - Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/vagrant/code/bedrock/web/wp/wp-includes/formatting.php on line 4768

var_dump is a good friend :slight_smile:

Disclaimer: I havent used Homestead so its possible the error is related to that and much easier to fix than I know. And I am still not at my computer to test things so I am just guessing and assuming below.

Since you said that the site works if you use a regular wp-config with hardcoded db-credentials, I would assume that the problem lies somewhere in the difference between the Bedrock way and the standard way. So thats where I would start looking.

I assume that you are using PHP 7.4 and the curly braces should have been fixed in core. https://make.wordpress.org/core/2019/10/11/wordpress-and-php-7-4/

Make sure that you are running the latest version of WP.

If you are adding any plugins in your composer files, try removing them. I doubt this will help but you never know…

The DB connection error doesnt necessarily have to do with DB connections :man_shrugging: Sometimes, if you are using the db from an existing install, the site URL is the culprit and I have had times when it was because i had enabled multisite in application.php before WP was installed.

Try backtracing the error by searching in the core files for ”Error establishing a database connection” and start debugging from there. Its also a great way to learn more about whats going on in core.

Sorry about the delay, got caught up with life. Looks like the DB error has been fixed ( hopefully if someone else gets into this situation they can read through the above as I’m not exactly sure what fixed this. ).

From there I was only able to have access to the wp-login.php page, and after submitting any values or clicking any links I was met with this 403 error "Forbidden - You don’t have permission to access this resource.

I then made an edit to my .env file changing the database key WP_HOME:
from - WP_HOME=“http://moreseconds.test
to - WP_HOME=“http://moreseconds.test:8000

Still learning here and didn’t realize I should be specifying this is a local installment, duh…

I am able to access the backend, login screen looks normal again, and I can activate the Sage theme. But I am still left with a 403 error on the front-end. Not sure what to make of this yet.

Simple cache issue, cleared it and now everything is fine. I’m a noob, thanks for the help that everyone above provided! Super excited to get deeper into developing themes from scratch/virtualbox/etc. Really cool tools, again thanks to the above comments!