Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /data/sites/web/remonpelnl/www/wp-content/themes/remonpel_nl__child__twentyfourteen/functions.php on line 32
Handy script: lbl - the missing cli for LocalWP – Remons TechNotes

Handy script: lbl – the missing cli for LocalWP

Local, the development environment for WordPress by LocalWP is great, but I am a terminal type of person. So I adapted an earlier script to work with the new Local version.

This script lets you do (nearly) all you need to do with Local from the CLI. Surely, a click of a button is not hard? true. But why use the mouse when you can use the keyboard. For instance

lbl ssh
opens a new Terminal shell specifically for the site you are in. (not chrooted, but it is set-up correctly).
lbl db
opens Sequel Pro with the correct database.

And there is much more ;)

Before we begin; dependencies

  1. Apple CommandLine Tools xcode-select --install
  2. homebrew. Install using instructions from
  3. php, node, nvm: Install using brew. brew install php node nvm
  4. LBL does NOT work with spaces in the path. This is a limitation on the Terminal application (at least in Big Sur).
    1. Set-up local to use a different folder – this will help with new sites
    2. Move the old folder to the new and symlink is – this will help with existing sites.
  5. The script allows for offloading to a secondary location (for instance an external drive, helpful when your internal drive is getting filled up). You CAN use a path with spaces as it will be symlinked to a no-spaces-containing path.

The lbf command can do the following, from within a directory controlled by Local (for instance ~/Local Sites/mywebsite/app/public)

lbl list List all sites
lbl raw View all info Local has on this site
lbl start|stop|restart Start/stop/restart a local site (this uses the local-cli node package, node v12 or newer required)
lbl mailhog Open the mailhog software for this site in your default browser
lbl db Open Sequel Pro with the database of this site
lbl ssh Open a shell of this site, in the root of the site
lbl ssh commands Open a shell of this site and execute the commands inside the shell, in the current folder
lbl wp commands Perform WP-CLI operation on site
lbl php commands Perform PHP operation on site, in the current folder
lbl wpdr Perform wp search-replace <current domain> <local domain>
lbl log Shows the error log for the site.

You can use --site, --project or -p to specify a site, either by Name, ID or Path to operate on
You can use --browser or -b to specify a WebBrowser either by AppName or AppPath to use for ‘open’ and ‘mailhog’
You can use --ssl to use https with operation ‘open’ and ‘wpdr’
You can use browser shortcuts;

Firefox Developer Edition

Of course, the browser of choice must be installed… Duh…

So, now you can do this: (while inside the app folder)

lbl wp db query < site-backup.sql
to import the database without opening a shell or application yourself
lbl db
and work with the database
lbl wpdr
to make sure the site runs on the local domain
lbl wp plugin install --activate wordpress-seo classic-editor duplicate-post what-the-file wp-smushit
ah, well, you get the idea :)

Enjoy, but as always; at your own risk :)

Author: Remon Pel

WebDeveloper though not WebDesigner

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Confidental Infomation
stop spam mail