cytopia / devilbox

A modern Docker LAMP stack and MEAN stack for local development
http://devilbox.org
MIT License
4.39k stars 654 forks source link

wp-cli db commands are not fully supported? #668

Closed dmorbidi closed 4 years ago

dmorbidi commented 4 years ago

ISSUE TYPE

SUMMARY

The docs states that wp-cli can be used but this seems not really true since if we try for example to export a database:

wp db export

We got: "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' "

Seems this is due to how devilbox works. And if so, is really a pity to loose these wp-cli functionalities. Or am I missing something?

Goal

In order to align the docs to the current situation would be very useful to access database through wp-cli. Otherwise, maybe the statement in the docs should be properly updated.

cytopia commented 4 years ago

Is your wordpress installation working? I just tried it and it works fine:

devilbox@php-7.4.1 in /shared/httpd/wp/wp $ wp db export
Success: Exported to 'wordpress-2020-01-22-86916e3.sql'.
dmorbidi commented 4 years ago

I'm sorry, you are right. If I consider a classic wp installation it works.

But now I'm using wpstarter and I get this error:

Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /shared/httpd/shops/shops-website/public/wordpress/wp-includes/wp-db.php on line 1612

Do you have any suggestion? I'm trying to understand where is the problem.

cytopia commented 4 years ago

What is the code in /shared/httpd/shops/shops-website/public/wordpress/wp-includes/wp-db.php on line 1612?

dmorbidi commented 4 years ago

This:

mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );

cytopia commented 4 years ago

But now I'm using wpstarter and I get this error:

Tried to reproduce, but I am getting this:

devilbox@php-7.4.1 in /shared/httpd/wp/wp $ wp wpstarter
Error: 'wpstarter' is not a registered wp command. See 'wp help' for available commands.
dmorbidi commented 4 years ago

Wp starter is not a wp-cli command. check this: https://wecodemore.github.io/wpstarter/docs/quick-start.html .

Wp starter let to create a wordpress env directly from composer.

Currently after installing everything (composer install) under project dir in devil box, I have this situation: -- data/www/my-project/prj_name/public/wordpress -- data/www/my-project/prj_name/public/wp-content -- data/www/my-project/prj_name/public/wp-config.php -- data/www/my-project/prj_name/public/index.php

I created htdocs dir as a link to the data/www/my-project/prj_name/public dir.

And if I try to perform

wp db export

I'm gettin the error mysqldump: Got error: 2002: "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)" when trying to connect

If instead I go in the site I get this error: Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /shared/httpd/shops/shops-website/public/wordpress/wp-includes/wp-db.php on line 1612

cytopia commented 4 years ago

Can you add the exact commands issued and also the directory from where you issued them.

dmorbidi commented 4 years ago

devilbox@php-7.3.13 in /shared/httpd/shops/htdocs $ wp db export

dmorbidi commented 4 years ago

right before that: ln -s shops-website/public/ htdocs

cytopia commented 4 years ago

I actually meant how you installed it exactly, as this command works on my machine (discussed above)

dmorbidi commented 4 years ago

Ok I set the devilbox as explained in the docs. I also created a standard wordpress site as explained in doc and all was fine.

Then I created another wordpress project, but this time instead of cloning wordpress.git I cloned a project of mine which works with wp starter and I did :

devilbox@php-7.3.13 in /shared/httpd/shops/shops-website $ composer install devilbox@php-7.3.13 in /shared/httpd/shops $ ln -s shops-website/public/ htdocs devilbox@php-7.3.13 in /shared/httpd/shops/htdocs $ wp db export

And got mysqldump: Got error: 2002: "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)" when trying to connect

If instead I go in the site I get this error: Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /shared/httpd/shops/shops-website/public/wordpress/wp-includes/wp-db.php on line 1612

cytopia commented 4 years ago

I would assume that the wp-config.php has wrong settings to connect to the database.

science695 commented 4 years ago

the mysqld.sock line implies that its trying to connect to a mysql instance on that same host, not through the networking stack, but through a local socket.

That would not use any of the port forwarding Devilbox has setup so that the php container can access the mysql container.

@dmorbidi What host name / address is in your config to connect to the database?

dmorbidi commented 4 years ago

Hey @cytopia you were right: was a configuration issue.

wpstarter read configuration on .env file and so updates the wp-config.php accordingly. But also it creates a env.cache.php file and uses always the info stored there...so the wrong db credentials were always used.

I deleted that file and he read the .env again grabbing the actual values...and it worked. Thanks a lot for the support. And thanks also to @science695 .