英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论