Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
iltafah opened this issue Apr 18, 2024 · 2 comments
Open

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

iltafah opened this issue Apr 18, 2024 · 2 comments

Comments

@iltafah
Copy link

iltafah commented Apr 18, 2024

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
@danielbachhuber
Copy link
Member

Thanks for the report, @iltafah

This seems similar to #5907. I'm not sure what the underlying cause is, though.

@S3B4Z1MM
Copy link

Using ln -s creates a symbolic link to the wp-cli.phar file rather than copying it in your container. This means that instead of having a separate copy of the file, you have a reference to the original file location.

When you run WP-CLI using the symbolic link, it effectively points to the original wp-cli.phar file. This could have resolved the issue because it ensures that WP-CLI is using the exact file in its original location without any potential discrepancies that might arise from copying the file.


When you change the name of a Phar file (e.g., renaming wp-cli.phar to wp), you're essentially changing the name by which you reference the Phar archive. However, the content inside the Phar file remains the same, including its internal directory structure.

If the Phar file was built with references to other files within itself using absolute paths or relative paths that depend on the Phar filename, those references might break when you rename the Phar file. This can cause issues with locating resources or dependencies within the Phar archive.

Additionally, some Phar archives might use the Phar filename for internal logic or identification purposes. Renaming the Phar file could disrupt this logic and cause unexpected behavior.

To ensure that the Phar file works correctly after renaming, you may need to update any internal references or logic that depend on the Phar filename. This could involve modifying the Phar archive itself or adjusting any scripts or configurations that interact with it.

In the case of WP-CLI, it's possible that the internal logic or references within the Phar file rely on the filename wp-cli.phar. When you rename it to wp, those references may no longer work as expected, leading to issues accessing the vendor directory or other resources within the Phar archive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants