Make a .phar file & commands available from command prompt ?

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Make a .phar file & commands available from command prompt ?

Postby Debugged » 09. August 2015 16:49

I have downloaded WP-CLI

Code: Select all
https://github.com/wp-cli/wp-cli


to my Windows box to

Code: Select all
D:\WEBDEV\WP-CLI


and added

Code: Select all
D:\xampp\mysql\bin;D:\xampp\php


to the Windows Path.


Being in

Code: Select all
D:\WEBDEV\WP-CLI


I can open a command prompt and type

Code: Select all
php wp-cli.phar --info


and it will correctly show me:
Code: Select all
D:\WEBDEV\WP-CLI>php wp-cli.phar --info
PHP binary:     D:\xampp\php\php.exe
PHP version:    5.6.8
php.ini used:   D:\xampp\php\php.ini
WP-CLI root dir:        phar://wp-cli.phar
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 0.19.2

D:\WEBDEV\WP-CLI>


Now I have various work folders with WP installations where I would like to use the WP-CLI.
Though this also implies that I have to copy the wp-cli.phar file into every one of those folders and when wanting to use it always prepend PHP to the command.

What I am trying to do is have the xyz.phar file and its commands available from any location in the system or at least from anywhere on partition D:\.

So for example I have one WP installation in
Code: Select all
D:\work\wp1\
and perhaps another one in
Code: Select all
F:\work_work_always_work\wp3\
.

Now I simply like to open the command prompt/CLI in the root of these WP installations and for example type
Code: Select all
wp-cli --info

and it should display me info similar to above and ideally I can then also run other commands from the wp-cli.phar on that WP installation/root.

I have done research about this before asking here.
So far I have come to read
Code: Select all
https://trepmal.com/2014/02/22/getting-started-with-wp-cli/
https://stackoverflow.com/questions/10753024/how-to-access-the-command-line-for-xampp-on-windows
https://stackoverflow.com/questions/11082337/how-to-make-an-executable-phar
https://superuser.com/questions/737602/run-script-from-powershell-in-the-same-window


The last link in that list of links suggests making a .bat file and linking the .phar file to the local PHP install.
Upon exploring the php dir of my XAMPP portable 5.6.8-0-VC11 install I find such .bat files, one in particular
Code: Select all
phar.phar.bat
.

In that file I find
Code: Select all
"%~dp0php.exe" "%~dp0pharcommand.phar" %*

and this seems terribly close to what is mentioned in the last link from the list of links above.

But when I create a
Code: Select all
wpcli.bat

file and put
Code: Select all
"%~dp0php.exe" "D:\WEBDEV\WP-CLI\wp-cli.phar" %*

I cannot seem to run the wp-cli.phar from a command prompt opened in D:\ for example.

What do I need to write exactly to link this wp-cli.phar file to php in my portable XAMPP install please?

How could I possibly "rename" the command from
Code: Select all
php wp-cli.phar [option]

to something like
Code: Select all
wp [option]

please?

I would be super happy if you can point me in the right direction or have further links that would lead to a solution.

Thank you for your help.
100% pure perseverance, nothing else!
Debugged
 
Posts: 21
Joined: 07. August 2015 23:26
Operating System: Win 7 Ultimate 64 SP1

Re: Make a .phar file & commands available from command prom

Postby Altrea » 09. August 2015 18:09

Do you use the XAMPP Shell from the XAMPP control panel? If not try to use it.
It registers some local environment variables and add some folders to the Windows PATH variable like the php bin folder.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Make a .phar file & commands available from command prom

Postby Debugged » 09. August 2015 18:56

Thank you for your reply.

The xampp_shell.bat does the following.
Code: Select all
@ECHO OFF

GOTO weiter
:setenv
SET "MIBDIRS=%~dp0php\extras\mibs"
SET "MIBDIRS=%MIBDIRS:\=/%"
SET "MYSQL_HOME=%~dp0mysql\bin"
SET "OPENSSL_CONF=%~dp0apache\bin\openssl.cnf"
SET "OPENSSL_CONF=%OPENSSL_CONF:\=/%"
SET "PHP_PEAR_SYSCONF_DIR=%~dp0php"
SET "PHP_PEAR_BIN_DIR=%~dp0php"
SET "PHP_PEAR_TEST_DIR=%~dp0php\tests"
SET "PHP_PEAR_WWW_DIR=%~dp0php\www"
SET "PHP_PEAR_CFG_DIR=%~dp0php\cfg"
SET "PHP_PEAR_DATA_DIR=%~dp0php\data"
SET "PHP_PEAR_DOC_DIR=%~dp0php\docs"
SET "PHP_PEAR_PHP_BIN=%~dp0php\php.exe"
SET "PHP_PEAR_INSTALL_DIR=%~dp0php\pear"
SET "PHPRC=%~dp0php"
SET "TMP=%~dp0tmp"
SET "PERL5LIB="
SET "Path=%~dp0;%~dp0php;%~dp0perl\site\bin;%~dp0perl\bin;%~dp0apache\bin;%~dp0mysql\bin;%~dp0FileZillaFTP;%~dp0MercuryMail;%~dp0sendmail;%~dp0webalizer;%~dp0tomcat\bin;%Path%"
GOTO :EOF
:weiter

IF "%1" EQU "setenv" (
    ECHO.
    ECHO Setting environment for using XAMPP for Windows.
    CALL :setenv
) ELSE (
    SETLOCAL
    TITLE XAMPP for Windows
    PROMPT %username%@%computername%$S$P$_#$S
    START "" /B %COMSPEC% /K "%~f0" setenv
)


From what I can understand from what this does it registers the environment variables, like you said, and adds the mentioned folders to the Windows PATH, though I cannot find a php bin folder anywhere. As far as I can see the portable version of XAMPP does not have a bin folder under the php folder and I added the php folder to the Windows PATH already, so what use would it be to run the xampp_shell script with regards to what I am trying to get done? Not undermining your suggestion, just trying to understand in what way I could benefit from your proposed action towards a solution of what I am trying to get done.

Would running this .bat enable me to "link" the .phar, in this case the WP-CLI.phar to php (in the portable XAMPP folder), so that I can use it from anywhere on partition D:\?

You see what I am trying to do is use the WP-CLI.phar from anywhere on D:\ as that is where I also have my work folders and projects, in this case WP installs.

For example I can open a command prompt anywhere on partition D:\ and run
Code: Select all
phpdoc
and it works.

In a similar manner I would love to be able to just run
Code: Select all
wp-cli [option]

from anywhere on partition D:\.

I will happily research any input or next things towards a solution to what I am trying to get done.
Thank you.
:wink:
100% pure perseverance, nothing else!
Debugged
 
Posts: 21
Joined: 07. August 2015 23:26
Operating System: Win 7 Ultimate 64 SP1

Re: Make a .phar file & commands available from command prom

Postby Altrea » 09. August 2015 19:47

You could create the bat file you mentioned and add the path to this file to the windows path variable or the xampp shell.
Maybe this will make it a little bit more clear:
viewtopic.php?f=16&t=56990
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Make a .phar file & commands available from command prom

Postby Nobbie » 09. August 2015 20:36

Debugged wrote:I have downloaded WP-CLI

Code: Select all
https://github.com/wp-cli/wp-cli


... and what is the relation to Xampp??
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04

Re: Make a .phar file & commands available from command prom

Postby Debugged » 09. August 2015 22:51

Altrea wrote:You could create the bat file you mentioned and add the path to this file to the windows path variable or the xampp shell.
Maybe this will make it a little bit more clear:
viewtopic.php?f=16&t=56990

Thank you heaps! I will give all this a good read and guess learn tons while doing do, just what I was looking for, thank you.

Are there more 101 threads that are a must read and most know for someone that likes to find out more and get involved??

I am all self-thought so finding good resources like that is worth quite a lot to me.

Nobbie wrote:
Debugged wrote:I have downloaded WP-CLI

Code: Select all
https://github.com/wp-cli/wp-cli


... and what is the relation to Xampp??

Belive me or not but I was thinking about this before creating the thread and expected you to voice concern.

Nevertheless I dared to ask since PHP is a part of XAMPP and mostly because I am using the portable version, thinking things are a bit different there. Looking at it from your perspective I can see that clearly you could write "this is not a PHP support forum" or something along the line, and yes in that sense you are 100% right.

You see I am trying to learn and happy to read and try hard and so my first point for this would be this great community since after all I am using XAMPP and not another solution.

Last not least finding .bat files doing pretty much what I like to achieve with the .phar file in the php dir finally made me decide to ask here first and I must say I don't regret that in any way looking at the 101 thread.

Likewise, if you feel you could contribute to me wanting to learn and perhaps also have a link you like to share I would be tremendously happy to read that as well.

You two must have an in-depth knowledge of all these matters so hearing it from you means it is the right thing to do, though be aware I will always have one more question.. ;)
100% pure perseverance, nothing else!
Debugged
 
Posts: 21
Joined: 07. August 2015 23:26
Operating System: Win 7 Ultimate 64 SP1

Re: Make a .phar file & commands available from command prom

Postby Altrea » 09. August 2015 23:07

Debugged wrote:Are there more 101 threads that are a must read and most know for someone that likes to find out more and get involved??

There is only one other [101] i have wrote. viewtopic.php?f=16&t=57054
I am still searching new topics for 101 threads, so if you have an idea let me know :D
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Make a .phar file & commands available from command prom

Postby Debugged » 10. August 2015 16:21

Bookmarked both!

There are a few ideas which are covered already like this one for example viewtopic.php?f=16&t=69784 but I will let you know in due time what I was thinking about.
100% pure perseverance, nothing else!
Debugged
 
Posts: 21
Joined: 07. August 2015 23:26
Operating System: Win 7 Ultimate 64 SP1


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 87 guests