[Tutorial] How to add wp-cli to Laragon


  • administrators
    | 108237 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
      https://raw.github.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

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

    @ECHO OFF
    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
    | 108237 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
    
    

  • | 4005 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
    | 108237 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 :)


  • | 957 points

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


  • | 703 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 ..)
    https://github.com/cmderdev/cmder/wiki/Seamless-VS-Code-Integration


  • | 957 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.!


Log in to reply
 

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