Call   0208 3131682   Mon-Fri 9am-6pm
Monthly Archives

August 2020

Setup WordPress WP-CLI on Docker ( the simple way )

By | Uncategorized | No Comments

In this post I’ll run over how to setup WP-CLI on a Docker web server image ( so you can easily use it todo a Database find and replace , would is handy when you need to migrate a site from one place to another ).

This presumes you have PHP setup on the command line (which my image did have ). Anyway here goes:

  1. First in your Docker folder run ‘docker ps’ ( to get the name of the web server image CONTAINER ID )
  2. Pop that into this command e.g. ‘docker exec -it fdghye5742252 bash’
  3. You’ll be in a shell on the web server now
  4. navigate to your web root of the site you want ( my image puts me there already eg /var/www/html )
  5. download wp-cli and install see https://make.wordpress.org/cli/handbook/guides/installing/
    1. you can also do this on a volume if you have your webroot setup as a volume linked to your local hard drive
  6. I didn’t bother with moving it to the bin dir (which would put it on the global path)
  7. I just did ‘mv wp-cli.phar wp’
  8. you can then run eg
    1. ‘./wp –info’
    2.  do your find and replace ‘./wp search-replace ‘https://www.somesite.co.uk’ ‘http://localhost’ –allow-root’

 

Disclaimer – Obviously with anything like this be careful and make sure you have a backup, use at your own risk.