Local Community

Start site through command line

Is it possible to start/stop a site through the command line? I would like to set up a shell script and one of the steps would be starting a site, but I wasn’t sure if that was possible.

Thanks!

Hi Andrew,

Unfortunately it’s not possible at the moment but this is definitely on the radar :slight_smile:

I’ve moved this topic to “Feature Requests”

3 Likes

+1 for that feature request :wink: That would give a lot for “hardcore” command line using developers

2 Likes

+1 This is even more important now that Local shuts down sites when Local is shutdown, i.e., need to start up sites more often now.

+1 - this would be an awesome feature to have, especially for super users. Thanks!

Thanks for the feedback!

If you have specific dreams of how Local works in the CLI, be sure let us know! By that I mean actual commands and arguments :slight_smile:

+1 for this. I would love to be able to just launch the site from the integrated terminal in my IDE. I already made myself a one-liner command to drop me into the “SSH” for sites, launching the sites this way would be great as well. Actually, this feature would best if it were something like a lbf start and lbf stop command that determined which site to start or stop based on the current directory. If that were to happen (this is just me dreaming a little) you could also include a lbf shell command that drops you into the shell of the site whose path you are within (what I wrote for myself in bash and php a few weeks back, but would rather be something provided officially by Local).

1 Like

You have my vote. A feature like this will certainly attract ‘hardcode’ developers who don’t like pretty user interfaces. At the moment I have a hard time convincing back-end developers to migrate, whereas Front-End devs are easily convinced thanks to Local’s attractive design.

I think @alexclst is on the right track with lbf start etc. commands…

Something like lbf new to create a new site, the user would then be presented with options, i.e. title, directory, server type, php/mysql versions, multisite etc… Have a look at how Lando does it - https://docs.devwithlando.io/

Some commands:

  • lbf new - Create site
  • lbf start - Start site
  • lbf stop - Turn site off
  • lbf status - Check run status of site
  • lbf remove - Delete site, also presented with confirmation, and option to remove files from dir.
  • lbf edit - Update server, php or mysql options
  • lbf update core - Update WordPress
  • lbf update plugins - Update All Plugins
  • lbf update plugin contact-form-7 - Update specific plugin, i.e. “contact-form-7” (directory slug)
  • lbf update themes - Update All Themes
  • lbf update theme twentyseventeen - Update specific theme, i.e. “twentyseventeen” (directory slug)
  • lbf update all - Update WordPress, plugins and themes
  • lbf mysql - Open database in preffered tool (i.e. Sequel Pro)
  • lbf mail - Open MailCatcher
  • lbf push - Push to Flywheel (presented with option for database)
  • lbf pull - Pull from Flywheel (presented with option for database)
  • lbf export - Zip and export site
  • lbf import - Import site

Just some examples…

3 Likes

@clay just mentioning you so you see my comment :grinning:

Saw it! I dig the ideas! :smiley:

+1 Another vote for this, especially with wp-cli integration.

On a side note. The latest LBF releases have been super solid so thanks!

would you be willing to share your scripts?

The script I wrote can be found at the Bitbucket repository for it. The sh script is intended for the Bash shell. I later switched to the Fish shell, and so the following is what I now use, which still depends on the PHP script, but is included as a function in my Fish config folder:

function lbf
    # get the LBF container id using the PHP script from the Bash lbf-container
    set container (command php $HOME/bin/lbf-container/lbf-container.php $PWD $HOME)

    if test -n "$container"
        # if we have a container attempt to enter it's bash shell
        eval ("/Applications/Local by Flywheel.app/Contents/Resources/extraResources/virtual-machine/vendor/docker/osx/docker-machine" env local-by-flywheel)
        "/Applications/Local by Flywheel.app/Contents/Resources/extraResources/virtual-machine/vendor/docker/osx/docker" exec -it $container /bin/bash
    else
        # if we don't have a container just alert the user of that
        echo "Not a Local by Flywheel site folder."
    end
end
1 Like

If you have the WP CLI command installed on your computer (like via Homebrew), you can add two files to the root folder for the local site that enable using the WP CLI directly from the shell on your regular computer, without even going into the shell of the local site, so long as your CWD is within the folders of the local site.

One is wp-cli.local.yml:

path: app/public
require:
  - wp-cli.local.php

The second is wp-cli.local.php:

<?php
define('DB_HOST', ‘192.168.95.100:XXXX');
define('DB_USER', 'root');
define('DB_PASSWORD', 'root');

error_reporting(0);
@ini_set('display_errors', 0);
define( 'WP_DEBUG', false );

Just replace XXXX with the port for the DB that is shown in the main Local window.

I find that this is even more convenient than going into the local machine’s shell if all I’m trying to do is use the WP CLI. In fact, another feature request, I guess, could be Local just creating these files for us on new sites.

1 Like