I'm currently experimenting with WP-CLI (http://wp-cli.org) - I have finally managed to get it to run on my basic command line by downloading/moving it to a PATH variable directory (i.e C:\xampp\php) and then updating my PATHSPEC to include .PHAR.
I have renamed the original file from wp-cli.phar to wp.phar in order to be able to reference it as wp in my cmd.exe.
Prior to this method I installed wp-cli using CURL and chmod in my Git Bash installation then renaming the file to wp (without an extension) and adding the path containing file to the PATH variable. This caused the .PHAR file to work in Git Bash but not to work on the command line.
MY ISSUE:
Whenever I try to use my wp.phar in the native CLI I get a php error report - it does recognise the command and does show a list of suggestions (which is usually given when syntax is incomplete or incorrect).
How do I even start to figure this out?
1 - I've attempted to look for a git batch file in my Git Bash directory to see if I can find a dependency I'm missing but no dice.
2 - My Git Bash is now not recognizing the wp command and I now need to refer to wp.pharand then add any sub-commands/arguments after. However using the Git Bash CLI wp.phar doesn't cause errors
After a few months I found a solution.
Make sure that your PHP root folder path and the folder path containing your phar files are added to the Windows PATH Environment Variable (to allow us to just use the filename to refer to them).
CMD Line Options (Run as Administrator):
assoc .php=phpfile and assoc .phar=pharfile
Next is adding the program that opens this file. Adding an ftype command allows us to open .php/.phar files without using the php.
ftype pharfile=php.exe %1 %* (The %1 is a placeholder for the file called and %* refers to any other arguments that many be input).
FINALLY
The key issue was getting the .phar scripts to execute in the command line as windows ends up trying to open these files in it's Open With Dialog
So what I did was wrap my .phar in a batch file with this command (in the same folder as the phar
echo php "%~dp0wp-cli.phar" %* > [name of file].cmd
I then run this file as [name of file] with any arguments and it works as usual.
Related
exec("lame audio.mp3 audio.wav")
Similar questions didn't helped.
This is the command that should be executed via PHP.
The audio.mp3 file presents in the directory and no permission issues.
Lame encoder is present at: C:\Program Files (x86)\Lame. This path is added into System Environmental Variables PATH.
lame command works in cmd, it displays the version as 3.99.3. (This means lame is installed and added to the PATH properly).
The PHP file present in the folder D:\XAMPP\htdocs\demo.php. Executing lame audio.mp3 audio.wav via cmd in the directory D:\XAMPP\htdocs runs properly and the mp3 file is converted to wave file without any issue.
The PHP exec is alone not working. Where I am missing?
Edit: The error.log file have the following error:
'lame' is not recognized as an internal or external command, operable
program or batch file.
I am trying to install extension by command.
In server already configure the PHP CLI and I'm using this code :
shell_exec('php-cli '.$SitefilePath.' --package='.$packagePath.'');
I have upload the file:
https://raw.githubusercontent.com/akeeba/vagrant/master/vagrant/files/joomla/install-joomla-extension.php
In the CLI folder and pass path as SitefilePath into command.
but its not working.
I have checked with all option :
http://www.php-cli.com/php-cli-options.shtml
Let me know how to get this work.
All of these issues have been properly debugged in the install-joomla-extension.php script I wrote.
First, create a new plain text file and paste that code in it. Save it as install-joomla-extension.php in your Joomla! site's cli directory. The name is not important, the location (cli directory) is.
Now you can call it like this:
cd /path/to/site/cli php ./install-joomla-extension.php --package=/where/is/your/extension.zip
The script returns one of the following exit statuses:
The extension was installed successfully.
The package file was not found.
The package file could not be extracted.
The extension could not be installed.
You can copy this file to your site's cli directory and install extensions and extension updates any time you want.
Source: https://www.dionysopoulos.me/238-installing-joomla-extensions-from-the-command-line.html
Let me know if this works.
To install Composer in my shared host, I ran from my home directory:
$ curl -sS https://getcomposer.org/installer | php -- --install-dir=bin
Then I was told to run: $ php bin/composer.phar
And following that I was able to use Composer, confirmed by running:
$ composer.phar -V
Composer version 1.0-dev
Can someone please explain the command php bin/composer.phar?
Is it simply telling php to unpack the .phar file? If so, where does it unpack it to? I see bin/bin/composer.phar* after having run it. Then I have to run composer using the entire path to the phar file, unless I'm in the home directory.
A .phar file is a ZIP-like file that contains all the files that make up a PHP application, and some initial code in the file header that sets up some stuff and then transfers execution to the first zipped file.
The command php bin/composer.phar is calling PHP and gives the phar file as a parameter to make PHP execute that file. This will make PHP read that file, find the header with the bootstrapping code and execute that. PHP will initialize PHAR execution and go further into that compressed file.
The command composer.phar will only work if that file has been marked with the x file flag to make it executable, and it is placed in a directory that is mentioned in the $PATH environment variable. Part of the PHAR file is the first line of the file header that is called "shebang". This line is used in all script files for the command line to specify the interpreter that should be used to execute the file. In case of composer.phar, this interpreter is PHP. So in essence, the same thing happens as with the first call: PHP is "running" the PHAR file, but with less typing on the command line.
Everytime I try to load a file through command line I get this message:
Could not open input file: dummy.php
I have tried everything,
php C:\Program Files (x86)\Zend\Apache2\htdocs\dummpy.php
php dummy.php
php htdocs\dummy.php
I can't run a file! I can get php information and all other stuff, so I belive my CLI is ok.
I actually need this to run phpwebsocket, but I can't run anything through CLI.
You either need to enter the path without spaces, like this:
php c:\progra~2\Zend\Apache2\htdocs\dummy.php
Or, you can put quotes around the whole thing since your path does have spaces, like this:
php "C:\Program Files (x86)\Zend\Apache2\htdocs\dummy.php"
Or, when you open your command prompt, make sure to navigate to the folder that your PHP file exists in. For example, a simple navigation might look this this (type enter after each line):
cd \
cd Program Files (x86)
cd zend
cd apache2
cd htdocs
php dummy.php
If you write
php dummy.php
you must be sure that your current directory is
C:\Program Files (x86)\Zend\Apache2\htdocs\
I'm trying to run composer on windows with wamp. I installed composer using the cmd prompt, and now I'm trying to run "composer update" for an SDK. However, when I type in "composer.phar update," windows asks what app I want to use to run this program. I want the command prompt to deal with it! How do I just run it through cmd, without this "what app" window coming up?
You have to set php.exe as your default application for phar files.
.phar stands for PHP Archive
Usually .phars take some arguments, so they are intended to be run from command prompt. Linux/BSD/OS X shell or Windows command prompt.
Linux .phar use case scenarios assume .phars are copied to some /bin and renamed to be without .phar extension, so you can use a php archive as if you would use any other linux command. So I recommend following way of doing the same thing with Windows:
Put all your .phar files to one directory like C:\php\phars
Add C:\php\phars to system environment variables (right-click my Computer -> Properties -> Advanced System Settings -> Environment variables)
Start the elevated command prompt (find command prompt in start menu then right-click and select Run as Administrator)
Type the following commands, replacing the path C:\phpdev\php\php542\php.exe with full path to your PHP executable:
ftype PHARFile=C:\phpdev\php\php542\php.exe "%1" %*
assoc .phar=PHARFile
set PATHEXT=%PATHEXT%;.PHAR
Next time your should be able just to run Windows console (keyboard Win+R and type cmd.exe) and type any of your .phar's like apigen.phar followed by any command and it will work
C:\Users\acosonic>apigen.phar help
Usage:
...
Arguments:
command The command to execute
command_name The command name (default: "help")
Options:
--xml To output help as XML
--format To output help in other formats (default: "txt")
--raw To output raw command help
--help (-h) Display this help message.
--quiet (-q) Do not output any message.
--version (-V) Display this application version.
Help:
The help command displays help for a given command:
php C:\phpdev\phars\apigen.phar help list
You can also output the help in other formats by using the --format option:
php C:\phpdev\phars\apigen.phar help --format=xml list
To display the list of available commands, please use the list command.
C:\Users\acosonic>
So this way lets you run .phar archives in a directory where you need to work, for example generating documentation in C:\myproject\controller without specifying full path to .phar as if you would if it's run without adding it to Windows path.
To explain what commands in step 4 did:
Created mapping HKCR.phar → HKCR\PHARFile
Created HKCR\PHARFile\shell\open\command = 'php.exe "%1" %*' [REG_EXPAND_SZ]
Extended HKCU\Environment\PATHEXT = '%PATHEXT%;.PHAR' [REG_EXPAND_SZ]
*.phar gets treated like binary/script, and *.phar execution works as long as a *.phar file is located anywhere in %PATH%.
One can wrap php *.phar with *.bat, then the filename will be the name of the CLI command:
#ECHO OFF
php "C:/Program Files/PHAR/phpDocumentor.phar" %*
One can also use such a wrap to pass along default arguments; eg. wp.bat:
#ECHO OFF
php "C:/Program Files/PHAR/wp-cli.phar" --path="D:/SDK/wordpress" %*
Where pattern %* will capture and forward CLI arguments, as it is supposed to.
Alike this one can run phar alike any other CLI command, in a terminal window.
Keep it simple. Instead of changing .phar's default program, which is not always easy in Windows, try just typing "php" in front of your command.
php composer.phar update