简体   繁体   English

带有环境变量的警告。 无法连接到数据库

[英]warning with environmental variables. can't connect to database

I just finished making an .env file for my wordpress project and when I finished typing in all the values the backend of my wordpress won't work. 我刚刚为wordpress项目制作了一个.env文件,当我输入完所有值后,wordpress的后端将无法工作。 It says it can't connect to the database. 它说它无法连接到数据库。 this is the error: 这是错误:

Warning: mysqli_real_connect(): (HY000/1045): Access denied for user ''@'localhost' (using password: NO) in /home/vagrant/Code/creativeforces/wp-includes/wp-db.php on line 1489

Here is my wp-config.php: 这是我的wp-config.php:

define('DB_NAME', getenv('DB_NAME'));

// /** MySQL database username */
define('DB_USER', getenv('DB_USER'));

// /** MySQL database password */
define('DB_PASSWORD', getenv('DB_PASSWORD'));

// /** MySQL hostname */
define('DB_HOST', getenv('DB_HOST'));

// /** Database Charset to use in creating database tables. */
define('DB_CHARSET', getenv('DB_CHARSET'));

// /** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', getenv('DB_COLLIATE'));

define('AUTH_KEY', getenv('AUTH_KEY'));
define('SECURE_AUTH_KEY', getenv('SECURE_AUTH_KEY'));
define('LOGGED_IN_KEY', getenv('LOGGED_IN_KEY'));
define('NONCE_KEY',    getenv('NONCE_KEY'));
define('AUTH_SALT',  getenv('AUTH_SALT'));
define('SECURE_AUTH_SALT', getenv('SECURE_AUTH_SALT'));
define('LOGGED_IN_SALT',   getenv('LOGGED_IN_SALT'));
define('NONCE_SALT',    getenv('NONCE_SALT'));

I'm not sure why it's not connecting to my env file. 我不确定为什么它没有连接到我的环境文件。 Here is an image of my file structure: 这是我的文件结构的图像: 在此处输入图片说明

also this is what my .env file looks like but these are not the values I have. 这也是我的.env文件的外观,但这些不是我的值。 These are just examples. 这些仅仅是示例。

DB_NAME=cupcakelife
DB_HOST=44.33.22
DB_DATABASE=cupcake
DB_USER=cupcake
DB_PASSWORD=bakinglife
DB_CHARSET=dewqdwe
DB_COLLIATE='dewqdfwrfvgerwfgrewfvwerferw'

any help would be appreciated! 任何帮助,将不胜感激!

Ok, so getenv() gets the value of environment variables. 好的,因此getenv()获取环境变量的值。 AFAIK, Vagrant's vars from .env aren't populated to that scope unless you specifically tell it to. AFAIK,.env中的Vagrant的var不会填充到该范围,除非您明确地告诉它。 Check this out: https://github.com/vlucas/phpdotenv it should do the trick for you. 检查一下: https : //github.com/vlucas/phpdotenv,它应该为您解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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