Change DB_USER and DB_PASSWORD depending on whether I'm on server or not

huangapple go评论58阅读模式
英文:

Change DB_USER and DB_PASSWORD depending on whether I'm on server or not

问题

在本地计算机上开发。因此,我在本地主机和服务器之间交换文件。

在wp-config中,我想要检查我是否在服务器上。
根据结果,我想要更改DB_USER和DB_PASSWORD。

目前我是手动操作的。

wp-config.php

define( 'DB_USER', 'root' );
// define( 'DB_USER', 'gr_academ' );

define( 'DB_PASSWORD', '' );
// define( 'DB_PASSWORD', 'secret' );

接下来我可以尝试什么?

英文:

I'm developing at my local computer. Therefore I exchange files between the localhost and server.

In wp-config I'd like to check if I'm on the server or not.
Depending on the result I'd change DB_USER and DB_PASSWORD.

Right now I do it manually.

wp-config.php

define( 'DB_USER', 'root' );
// define( 'DB_USER', 'gr_academ' );

define( 'DB_PASSWORD', '' );
// define( 'DB_PASSWORD', 'secret' );

What can I try next?

答案1

得分: 0

This is a common problem.

Is local site on port 80?

if ($_SERVER['SERVER_PORT'] == 80) { define( 'DB_USER', 'root' ); }

Are sites using different versions of PHP?

if (PHP_VERSION_ID == 70424) { define( 'DB_USER', 'root' ); }

Or detect by host.

if ($_SERVER['HTTP_HOST'] == 'something.local') { define( 'DB_USER', 'root' ); }

Or check server directory

if (strstr($_SERVER['DOCUMENT_ROOT'], '/Volumes/')) { define( 'DB_USER', 'root' ); }

Note: PHP Version is best, if you use WP-CLI.

英文:

This is a common problem.

Is local site on port 80?

if ($_SERVER['SERVER_PORT'] == 80) {
define( 'DB_USER', 'root' );
}

Are sites using different versions of PHP?

if (PHP_VERSION_ID == 70424) {
define( 'DB_USER', 'root' );
}

Or detect by host.

if ($_SERVER['HTTP_HOST'] == 'something.local') {
define( 'DB_USER', 'root' );
}

Or check server directory

if (strstr($_SERVER['DOCUMENT_ROOT'], '/Volumes/')) {
define( 'DB_USER', 'root' );
}

Note: PHP Version is best, if you use WP-CLI.

huangapple
  • 本文由 发表于 2023年2月19日 02:16:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75495407.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定