• I have a container deployed in an Azure App Service that has WP-CLI also installed. My wp-config.php gets the database info using the getenv_docker environment variables. And therefore WP CLI fails to establish a connection to the mysql database also running in Azure.

    I have spent 2 days searching and obviously am not searching for the right info as I can not find a solution to allow wp-cli to be able to read the wp-config.php correctly or find another way to pass the database info to wp-cli to know where the database exists.

    Can someone please help point me into the right direction?

    My wp-config.php looks like this for the DB info.
    ==================================================================================
    /** MySQL hostname */
    define( ‘DB_HOST’, getenv_docker(‘WORDPRESS_DB_HOST’, ‘mysql’) );
    /** The name of the database for WordPress */
    define( ‘DB_NAME’, getenv_docker(‘WORDPRESS_DB_NAME’, ‘wordpress’) );

    /** MySQL database username */
    define( 'DB_USER', getenv_docker('WORDPRESS_DB_USER', 'example username') );
    /** MySQL database password */
    define( 'DB_PASSWORD', getenv_docker('WORDPRESS_DB_PASSWORD', 'example password') );
    ==================================================================================
    
    Additional note... it appears since getenv_docker is not working it is trying to use default info...   Of course that will not work. :(
    
    

    # wp config list –allow-root
    +———————+——————————————+———-+
    | name | value | type |
    +———————+——————————————+———-+
    | table_prefix | bv_ | variable |
    | configExtra | | variable |
    | DB_NAME | wordpress | constant |
    | MYSQL_CLIENT_FLAGS | 2048 | constant |
    | DB_USER | example username | constant |
    | DB_PASSWORD | example password | constant |
    | DB_HOST | mysql | constant |
    | DB_CHARSET | utf8 | constant |`

    • This topic was modified 2 years, 10 months ago by grifgr10.
Viewing 2 replies - 1 through 2 (of 2 total)
  • > My wp-config.php gets the database info using the getenv_docker environment variables

    Have you deifned the same set of env variables in your yml file in both the WordPress container and the CLI container? They need to match.
    Make sure you provide a password for root – we can’t use root no password anymore. ??

    Btw, are you tied in to use Docker?
    I drank the koolaid a few years ago, and finally bailed on it. Was too much of a barrier / time sucker most of the time. Back to good ol’ reliable VM.

    Thread Starter grifgr10

    (@grifgr10)

    I have wp-cli setup in the same container as WP is running. If I change the wp-config.php to have the values for the database connection everything works fine. But if the wp-config.php has the getenv_docker function to pull the values wp-cli fails to connect to the database. But the WP site works just fine.

    As a note on docker, we were pushed to begin using it for this project and had a consultant come in and help us build this out. I do not see any specific yml files for the environment other than the pipeline yml. I am having issues using what they setup as it writes an docker image out there but then changing info that is dependent on environment is a challenge. Meaning dev, qa and prod have some different params needed…

    Grant

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Error establishing a database connection using wp-cli’ is closed to new replies.