You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 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 / :
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.
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
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.
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
/
: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
:The text was updated successfully, but these errors were encountered: