[Tutorial] How to add wp-cli to Laragon

  • administrators
    | 131219 points

    Adding additional command line tool like wp-cli to Laragon is easy. We will use C:\laragon\usr\bin to store our tool. Here's how:

    1. Download wp-cli.phar and put it to C:\laragon\usr\bin\wp-cli.phar

    2. Create a file called wp.bat in C:\laragon\usr\bin\wp-cli.phar with following content:

    php "%~dp0wp-cli.phar" %*

    That's all folks!

    To test, open Laragon's Terminal (CTRL + ALT + T), and type:

    wp --version

    You should see something like this: WP-CLI 1.5.1

    To check info, type:

     wp --info

  • administrators
    | 131219 points

    Or you can do the lazy way (paste it in Laragon's Terminal) and enter:

    cd C:\laragon\usr\bin && curl -L -O https://raw.github.com/wp-cli/builds/gh-pages/phar/wp-cli.phar &&  echo @ECHO OFF > wp.bat && echo php "%~dp0wp-cli.phar" %* >> wp.bat

  • | 6284 points

    Should I add C:\laragon\usr\bin to the PATH variable in order to use it from the normal windows command prompt/GIT bash?

  • administrators
    | 131219 points

    No, you should not. Because you also need to add PHP to PATH.
    You may think it is not a matter. However, what if you want to change to another PHP version in the future?
    Doing things like that in a long term will pollute your PATH.

    Laragon's Terminal manages PATH for us. Therefore, we can add another PHP, Apache, Nginx, Node.js, Ruby, Python, Golang, Java, MongoDB, PostgreSQL,... without any headache :)

  • | 1109 points

    @leokhoa What if i need to use wp-cli out of laragon terminal . lets say i need to use in my IDE Terminal. ?

  • | 1008 points

    @varunsridharan you need to provide path to it in your Windows PATH.

    I have multiple PHP versions installed in Laragon (5.6,7.0,7.1,7.2,7.3 and one more 7.1 as "php7"). The "php7" is in my path together with ./bin/pear where I also keep phpcs and wp.bat. The wp-cli.bat is in ./usr/bin for easier updates. So when you have one stable PHP and WP-CLI in PATH, it will work from any terminal in Windows, including your IDE. The reason I have php7 is that I keep only one version of PHP in my PATH and I don't touch it. I also use it in VS Code for PHP Mess Detector and running php directly from folder.

    But a good tip, if you only want to have WP-CLI accessible from your IDE. I use VS Code so it may be different for you, but I replaced cmd.exe with cmder in VS Code and it works flawlessly without need to have anything in PATH (because it uses cmder's init.bat ..)

  • | 1109 points

    @P-Mo Thanks but i just added it to Windows PATH and i am sure i have not added PHP path and it worked.!

  • | 1379 points

    I ran
    "cd C:\laragon\usr\bin && curl -L -O https://raw.github.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && echo @ECHO OFF > wp.bat && echo php "%~dp0wp-cli.phar" %* >> wp.bat"

    It all ran ok but I still get
    "'php' is not recognized as an internal or external command,
    operable program or batch file."
    when I try to run "wp --version"

    It doesn't look like Laragon IS managing PHP path does it?

  • administrators
    | 131219 points

    @patbell101 : Laragon is isolated with the OS environment, so you should use wp-cli in Menu > Laragon > Terminal
    If you want to use on Windows Command Prompt, you can add Laragon to System Path in Menu > Tools

  • | 1379 points

    So, not the Terminal Button on the Laragon control window? Because that is what I used for all of this. Never win cmd.

  • administrators
    | 131219 points

    @patbell101 : They are the same.
    Can you show me an image when you type "php -v" in Terminal?

  • | 1379 points

    fwiw ctrl alt T doesnt work in laragon v.4.0.14 afaics

  • administrators
    | 131219 points

    @patbell101 : The first line said init.bat,....
    You should install Laragon over to fix this first.

  • | 1379 points

    @leokhoa sorry I don't understand - "install laragon over"? Over what? Laragon (lite) was installed and functions fine APART from terminal. Anyway what does "...init.bat" is not recognised mean? I can run another bat file such as wp.bat with no such error. php -v also works now. Am I missing another "path"?

  • administrators
    | 131219 points

    @patbell101 : Please follow my instructions:

    1. Rename bin\cmder to bin\cmder.old
    2. Install Laragon over = Install Laragon to your current installation dir C:\laragon to update with a new bin\cmder

    Note: php -v works because you managed to add PHP to Windows System Path.
    Laragon tends to isolate from the OS environment to not pollute the System Path.
    Ref: https://laragon.org/docs/terminal.html

  • | 1379 points

    Ok I have done that and added git. But I still get told SED isn't installed.

    So how do I install SED?

  • | 32 points

    After following the instructions above this is what I get. I'm stuck any help will be appreciated.


  • | 1379 points

    @jraborar I gave up in the end it nearly works for me I cant get the tables so I guess some database issue.

    λ wp mu-migration export all lamasferat.zip --themes --plugins --uploads
    Exporting site meta data...
    Exporting users...
    Exporting tables
    Error: Unable to get the list of tables to be exported

  • | 500 points

    I personally wouldn't recommend installing WP CLI any other way than through Composer. This is the way I've installed it on numerous machines and it always works perfectly fine for me.

    1. Install Laragon.
    2. Add your preferred PHP version to your PATH variable. This is very useful outside of Laragon.
    3. Install Composer. Plenty of projects need this anyway.
    4. Install WP CLI via Composer global require.
      • composer global require wp-cli/wp-cli-bundle
      • Official documentation here.

Log in to reply

Looks like your connection to Laragon was lost, please wait while we try to reconnect.