[Tutorial] How to add wp-cli to Laragon
Adding additional command line tool like
wp-clito Laragon is easy. We will use
C:\laragon\usr\binto store our tool. Here's how:
Download wp-cli.phar and put it to
Create a file called
C:\laragon\usr\bin\wp-cli.pharwith following content:
@ECHO OFF php "%~dp0wp-cli.phar" %*
That's all folks!
To test, open Laragon's Terminal (CTRL + ALT + T), and type:
You should see something like this: WP-CLI 1.5.1
To check info, type:
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
Should I add
C:\laragon\usr\binto the PATH variable in order to use it from the normal windows command prompt/GIT bash?
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
@leokhoa What if i need to use wp-cli out of laragon terminal . lets say i need to use in my IDE Terminal. ?
@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 ..)
@P-Mo Thanks but i just added it to Windows PATH and i am sure i have not added PHP path and it worked.!
"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?
@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
So, not the Terminal Button on the Laragon control window? Because that is what I used for all of this. Never win cmd.
@patbell101 : They are the same.
Can you show me an image when you type "php -v" in Terminal?
fwiw ctrl alt T doesnt work in laragon v.4.0.14 afaics