welaika / wordmove

Multi-stage command line deploy/mirroring and task runner for Wordpress
https://wptools.it/wordmove
MIT License
1.87k stars 167 forks source link

WP login impossible after `pull -d`. Local installation redirects me to remote installation. #641

Closed castilma closed 2 years ago

castilma commented 2 years ago

Describe the bug I have a local wp-installation (setup with Local), and a staging server on the web at https://project.staging.foo.com.

After running wordmove pull -dv, http://project.local/ works as expected. Then I try to login by going to http://project.local/wp-admin, but that redirects me to https://project.staging.foo.com/wp-login.php?redirect_to=https%3A%2F%2Fproject.local%2Fwp-admin%2F&reauth=1, which is my staging server, of which I just pulled the database. The wp-admin username and password for my local installation are not accepted, and entering the login data for my staging server gets logged in on the staging server.

It looks like there are some settings that don't get rewritten by wordmove pull -d in the local setup. Also note the ?redirect_to part of the url, which contains the url that I originally wanted to visit.

Expected behavior

I expect to stay on http://project.local/wp-admin. After entering the login data for the local installation, I expect to be logged in to the backend of the local installation.

Unpacking an earlier backup to jan-small.sqland running mysql --host=localhost --user=[] --password=[] --database=[] --socket=/.../mysql/mysqld.sock --execute="SET autocommit=0;SOURCE wp-content/jan-small.sql;COMMIT" it works again.

movefile.yml

global:
  sql_adapter: wpcli

local:
  vhost: "https://project.local"
  wordpress_path: "/.../LocalSites/project/app/public/"

  database:
    name: []
    user: []
    password: [] # could be blank, so always use quotes around
    host: localhost
    mysql_options: --socket=/.../mysql/mysqld.sock
    mysqldump_options: --socket=/.../mysql/mysqld.sock

staging:
  vhost: https://project.staging.foo.com/
  wordpress_path: /html/project-staging # use an absolute path here

  database:
    name: []
    user: []
    password: []
    host: []

  exclude:
    - '.git/'
    - [...]

  ssh:
    host: []
    user: []
    password: [] # password is optional, will use public keys if available.

Exception/trace


▬▬ Using Movefile: ./movefile.yml ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

▬▬ Pulling Database ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

    local | mysqldump --host=[secret] --user=[secret] --password=[secret] --result-file="[secret]wp-content/local-backup-1644327719.sql" --socket=/.../mysql/mysqld.sock local
mysqldump: [Warning] Using a password on the command line interface can be insecure.

    local | gzip -9 -f "[secret]wp-content/local-backup-1644327719.sql"

   remote | mysqldump --host=[secret] --user=[] --password=[] --result-file="[secret]/wp-content/dump.sql" []

   remote | gzip -9 -f "[secret]/wp-content/dump.sql"

   remote | get: [secret]/wp-content/dump.sql.gz [secret]wp-content/dump.sql.gz

   remote | delete: [secret]/wp-content/dump.sql.gz

    local | gzip -d -f "[secret]wp-content/dump.sql.gz"

    local | mysql --host=[secret] --user=[secret] --password=[secret] --database=[] --socket=/.../mysql/mysqld.sock --execute="SET autocommit=0;SOURCE [secret]wp-content/dump.sql;COMMIT"
mysql: [Warning] Using a password on the command line interface can be insecure.

    local | adapt dump for vhost

    local | wp search-replace --path=[secret] [secret] [secret] --quiet --skip-columns=guid --all-tables --allow-[secret]

    local | adapt dump for wordpress_path

    local | wp search-replace --path=[secret] [secret] [secret] --quiet --skip-columns=guid --all-tables --allow-[secret]

    local | delete: '[secret]wp-content/dump.sql'

Environment (please complete the following information):

Doctor

Doctor ignores mysql_options and can't connect to the mysql server, but wordmove pull can connect correctly.

        .------------------------.
        |       PSYCHIATRIC      |
        |         HELP  5¢       |
        |________________________|
        ||     .-"""--.         ||
        ||    /        \.-.     ||
        ||   |     ._,     \    ||
        ||   \_/`-'   '-.,_/    ||
        ||   (_   (' _)') \     ||
        ||   /|           |\    ||
        ||  | \     __   / |    ||
        ||   \_).,_____,/}/     ||
      __||____;_--'___'/ (      ||
     |\ ||   (__,\\    \_/------||
     ||\||______________________||
     ||||                        |
     ||||       THE DOCTOR       |
     \|||         IS [IN]   _____|
      \||                  (______)
       `|___________________//||\\
                           //=||=\\
                           `  ``  `

▬▬ Using Movefile: ./movefile.yml ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

▬▬ Validating movefile section: global ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

    ✅  success | Formal validation passed

▬▬ Validating movefile section: local ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

    ❌  error | [/database/mysql_options] key 'mysql_options:' is undefined.

▬▬ Validating movefile section: staging ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

    ✅  success | Formal validation passed

▬▬ Using Movefile: ./movefile.yml ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

▬▬ Checking local database commands and connection ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

    ✅  success | `mysql` command is in $PATH

    ✅  success | `mysqldump` command is in $PATH

    ❌  error |   We can't connect to the MySQL server using credentials
                specified in the Movefile. Double check them or try
                to debug your system configuration.

                The command used to test was:

                mysql --host=localhost --user=[...] --password=[...] -e'QUIT'

    ❌  error |   We can't connect to the database using credentials
                specified in the Movefile, or the database does not
                exists. Double check them or try to debug your
                system configuration.

                The command used to test was:

                mysql --host=localhost --user=[...] --password=[...] [...] -e'QUIT'

▬▬ Checking local wp-cli installation ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

    ✅  success | wp-cli is correctly installed

    ✅  success | wp-cli is up to date

▬▬ Checking rsync ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

    ✅  success | rsync is installed at version 2.6.9

▬▬ Checking SSH client ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

    ✅  success | SSH command found

I'm not very good with WP. So I don't know, how I could pinpoint the problem. Tell me, what other info you need.

alessandro-fazzi commented 2 years ago

Let me do a first quick try: try to update your movefile.yml with

staging:
  vhost: https://project.staging.foo.com

Note the removed trailing slash. This behaviour happens when the wp option get home and/or wp option get siteurl are not correctly updated and I think the trailing slash cuold be the character avoiding the search-replace operation to properly work.

Lemme know if it helps :)

castilma commented 2 years ago

That was it.

castilma commented 2 years ago

I recommend to either report trailing slashes to the user or ignore them automatically.

alessandro-fazzi commented 2 years ago

I recommend to either report trailing slashes to the user or ignore them automatically.

As a reference, I think it would suffice to update the pattern used by doctor to validate movefile.yml. Here lib/wordmove/assets/wordmove_schema_remote.yml and here lib/wordmove/assets/wordmove_schema_local.yml.

This way a user would be warned about the trailing slash in the vhost key.

If you'd mind to open an "idea", I'd be prone to promote it to a feature request.