Skip to content

Could not create 'wp-config.php' with wp-cli config create #5933

@iltafah

Description

@iltafah

I am trying to install Wordpress in my container, and configure it so it can connect to mysql database, and I want to do this using only wp-cli, I know the manual way.

Here is the Dockerfile that I am using for testing purpose :

FROM mariadb:10.11.5

RUN apt update && apt install curl php php-fpm php-mysqli php-phar -y
RUN mkdir -p /var/www/html
RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
RUN chmod +x wp-cli.phar
RUN cp wp-cli.phar /usr/local/bin/wp

and here is how to build it and run it :

docker build . -t wp-test
docker run -d --name wp-test-container --env MARIADB_USER=tofa7a --env MARIADB_PASSWORD=1337 --env MARIADB_DATABASE=wordpress --env MARIADB_ROOT_PASSWORD=42 wp-test

the container is running in a detachable way now, we need to access it using the following command :

docker exec -it wp-test-container bash

then I install wordpress using the wp-cli :

wp core download --path="/var/www/html" --allow-root

and when I try to run the following command which is has to create for me the wp-config.php that will contain the mysql database informations, it gives me the error below, and creates the file empty

wp config create --dbname=wordpress --dbuser=tofa7a --dbpass=1337 --path="/var/www/html" --allow-root
PHP Warning:  file_get_contents(phar://wp-cli.phar/vendor/wp-cli/wp-cli/templates/phar://usr/local/bin/wp/vendor/wp-cli/config-command/templates/wp-config.mustache): Failed to open stream: phar error: "vendor/wp-cli/wp-cli/templates/phar:/usr/local/bin/wp/vendor/wp-cli/config-command/templates/wp-config.mustache" is not a file in phar "wp-cli.phar" in phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/utils.php on line 608
Error: Could not create new 'wp-config.php' file.

the weird thing is when I try and run it within the wordpress path it works :/

firstly let's delete the empty wp-config.php file, so wp-cli won't complain about an existing file.

rm /var/www/html/wp-config.php

and then let's change the directory to the wordpress content path :

cd /var/www/html/
wp config create --dbname=wordpress --dbuser=tofa7a --dbpass=1337 --allow-root

the file has created successfully :

Success: Generated 'wp-config.php' file.

it also works by running the wp-cli.phar directly, which I download it previously in the dockerfile steps, you will find it in the root path / :

rm /var/www/html/wp-config.php
cd /
./wp-cli.phar config create --dbname=wordpress --dbuser=tofa7a --dbpass=1337 --path="/var/www/html" --allow-root

again the file has created successfully :

Success: Generated 'wp-config.php' file.

is there a way to make wp-cli work without those illogical workarounds, am I missing something, I think it has to be something about permissions.

Here is the output of wp --info :

# wp --info
OS:     Linux 5.15.49-linuxkit #1 SMP Tue Sep 13 07:51:46 UTC 2022 x86_64
Shell:
PHP binary:     /usr/bin/php82
PHP version:    8.2.18
php.ini used:   /etc/php82/php.ini
MySQL binary:
MySQL version:
SQL modes:
WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       /
WP-CLI packages dir:
WP-CLI cache dir:       /root/.wp-cli/cache
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.10.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions