Jump to content
shogun

Where do you update the database username and password?

Recommended Posts

I usually setup ProcessWire locally and my remote server has a different username and password.

After completing all testing locally, where can I update the database credentials in the processwire files to match my remote server before pushing files?

Share this post


Link to post
Share on other sites

Just update site/config.php

If you want to keep the same config.php locally and remote, add a simple if statement or switch/case

if ($_SERVER['SERVER_NAME'] === 'dev.mysite.com') {
    $config->dbHost = 'foo.mysql.db.host.com';
    $config->dbName = 'xxxxx';
    $config->dbUser = 'xxxxx';
    $config->dbPass = 'xxxxx';
    $config->dbPort = '3306';
}

 

  • Like 2

Share this post


Link to post
Share on other sites

Perfect, but then where do you go to update the main url in the database? When I uploaded, it's still using the https://localhost url as the root url

Share this post


Link to post
Share on other sites

Everything seems ok except this variable is still pointing to localhost for some reason

$pages->get(1)->httpUrl

Share this post


Link to post
Share on other sites
1 hour ago, shogun said:

where do you go to update the main url in the database

Nowhere. PW doesn't store any such thing anywhere. You define allowed hosts in the config, but that's it.

This is most probably a caching issue. Try to delete everything inside site/assets/cache/, your browser cache and try again.

Share this post


Link to post
Share on other sites

I do it this way: i define a config->local then :

/**** Config Enviroment **********/
$config->local = true;

if($config->local == true) {
    $config->debug = false;
    $config->dbHost = 'localhost';
    $config->dbName = 'dbname_on_local';
    $config->dbUser = 'user_on_local';
    $config->dbPass = '*********';

else {
    $config->debug = false;
    $config->dbHost = 'localhost';
    $config->dbName = 'dbname_on_server';
    $config->dbUser = 'user_on_server';
    $config->dbPass = '***********';
}

And just toggle $config->local value between true / false

  • Like 1

Share this post


Link to post
Share on other sites

You can have a site/config-dev.php with all config for your local dev environment. If this file exists, all config values will be pulled from it instead of site/config.php. This is the common PW-way of having separate configs for live and development environments. This info can be found on this page in the docs at the very bottom.

  • Like 1

Share this post


Link to post
Share on other sites
On 3/5/2020 at 6:02 PM, gebeer said:

You can have a site/config-dev.php with all config for your local dev environment. If this file exists, all config values will be pulled from it instead of site/config.php. This is the common PW-way of having separate configs for live and development environments. This info can be found on this page in the docs at the very bottom.

I never knew, but I prefer my way: I keep config.php and then will have a config.dev.php and/or config.www.php and require whichever is appropriate via a switch conditional in config.php depending on the hostname. So in config.dev.php debug is true, and both have their respective DB credentials, and any other variations can be specified/distributed very easily and cleanly this way without repetition.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...