command line locally using wamp
When referring to this post here:
http://net.tu开发者_高级运维tsplus.com/tutorials/javascript-ajax/start-using-html5-websockets-today/
it tells you to run php -q path\to\server.php from shell using XAMPP, is there an alternative for WAMP?
It might be useful to register php.exe as an ENVIRONMENT VARIABLE so the command line can recognize the 'php' command instead of needing to enter the full path '\wamp\bin\php\php5.3.8\php' as the command.
To do this, you can follow the steps outlined on this page: http://windows.fyicenter.com/view.php?ID=60. Except for Step 5, enter the path of WAMP's php.exe instead. For example, just add in $;C:\wamp\bin\php\php5.3.8
to the Variable value field. And each time you open up your command line, just run php using
php pageYouAreRunning.php
..still keeping in mind that the pageYouAreRunning.php is relative to the current path in your command line.
It's essentially the same thing as described. You will need to open the windows cmd shell, and then you just need to find the location of the php file on your particular installation.
In the wamp installation I have it's located at \wamp\bin\php\php5.3.8\php
. So to run the php script I want, I would call...
\wamp\bin\php\php5.3.8\php pageYouAreRunning.php
Keep in mind pageYouAreRunning.php
is relative to the path you are currently in in your shell console.
It's no longer recommended to edit your environment path to directly point to the path to the PHP exe. This can cause you headaches further down the line.
A moderator named RiggsFoley over at the WampServer forum shared the following file
called phppath.cmd
:
@echo off
REM **********************************************************************
REM * PLACE This file in a folder that is already on your PATH
REM * Or just put it in your C:\Windows folder as that is on the
REM * Serch path by default
REM * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
REM * EDIT THE NEXT 3 Parameters to fit your installed WAMPServer
REM * for example I installed WAMPServer on the D: drive you may
REM * have used C:
REM * - baseWamp : is the drive and folder where you installed WAMPServer
REM * - defaultPHPver : is the version of PHP that will be pathed
REM * if no Parameter is put on the bat file
REM * - composerInstalled : Where I insatlled composerInstalled
REM * - phpFolder : The folder structure that contains the Multiple
REM * possible version of PHP I have installed
REM **********************************************************************
set baseWamp=D:\wamp
set defaultPHPver=7.0.23
set composerInstalled=%baseWamp%\composer
set phpFolder=\bin\php\php
if %1.==. (
set phpver=%baseWamp%%phpFolder%%defaultPHPver%
) else (
set phpver=%baseWamp%%phpFolder%%1
)
PATH=%PATH%;%phpver%
php -v
echo ---------------------------------------------------------------
REM IF PEAR IS INSTALLED IN THIS VERSION OF PHP
IF exist %phpver%\pear (
set PHP_PEAR_SYSCONF_DIR=D:\wamp\bin\php\php%phpver%
set PHP_PEAR_INSTALL_DIR=D:\wamp\bin\php\php%phpver%\pear
set PHP_PEAR_DOC_DIR=D:\wamp\bin\php\php%phpver%\docs
set PHP_PEAR_BIN_DIR=D:\wamp\bin\php\php%phpver%
set PHP_PEAR_DATA_DIR=D:\wamp\bin\php\php%phpver%\data
set PHP_PEAR_PHP_BIN=D:\wamp\bin\php\php%phpver%\php.exe
set PHP_PEAR_TEST_DIR=D:\wamp\bin\php\php%phpver%\tests
echo PEAR INCLUDED IN THIS CONFIG
echo ---------------------------------------------------------------
) else (
echo PEAR DOES NOT EXIST IN THIS VERSION OF php
echo ---------------------------------------------------------------
)
REM IF COMPOSER EXISTS ADD THAT TOO
REM **************************************************************
REM * IF A GLOBAL COMPOSER EXISTS ADD THAT TOO
REM *
REM * This assumes that composer is installed in /wamp/composer
REM *
REM **************************************************************
IF EXIST %composerInstalled% (
ECHO COMPOSER INCLUDED IN THIS CONFIG
echo ---------------------------------------------------------------
set COMPOSER_HOME=%baseWamp%\composer
set COMPOSER_CACHE_DIR=%baseWamp%\composer
PATH=%PATH%;%baseWamp%\composer
rem echo TO UPDATE COMPOSER do > composer self-update
echo ---------------------------------------------------------------
) else (
echo ---------------------------------------------------------------
echo COMPOSER IS NOT INSTALLED
echo ---------------------------------------------------------------
)
set baseWamp=
set defaultPHPver=
set composerInstalled=
set phpFolder=
As per the instructions, you need to edit the baseWamp
and defaultPHPver
variables. Check Wamp's bin\php
directory for the available PHP version numbers.
Put the file in your C:\Windows
directory, then open a new command window, and type phppath
. You will now have php
available during that window's session.
Not tested, but I would say it is the same...
There is a "php.exe" in your wamp/php folder...
Run it through commandline :
cd mywamp/php
php -q file.php
If php isn't running at all, create a batch file with the following code, and save it in your global folder as 'php'.
"c:\wamp64\bin\php\php7.0.29\php.exe" $1 ${2} ${3} ${4}
Of course replace php7.0.29 with whatever your php version on your machine is
Then just run any php command like normal, e.g.
php -v
If you need more arguments, just keep adding them as optional e.g. ${5} ${6}
Without modifying anything in Win. First check which version you are using in Wamp, then then run the command from PHP's Wamp folder for example:
C:\wamp64\bin\php\php7.2.33\php -v
For example, if you should run a Magento command (but this is true for any other CMS or PHP software) you place yourself in the folder where you have the CMS installation and run the command
C:\wamp64\bin\php\php7.2.33\php bin/magento setup:upgrade
I use Git Bash on windows and was facing same problem, after looking around I have devised my own solution.
I created a .bashrc, saved it in my home folder and still has little problems but this is my first time in bash scripting, still it might help someone else.
#!/bin/bash
default_php=php8.1.0;
default_mysql=mysql5.7.36;
php_folder=/c/wamp64/bin/php/;
mysql_folder=/c/wamp64/bin/mysql/;
current_folder=$PWD;
main_link_folder=/c/Scripts;
link_php=www;
link_mysql=db;
# In this case I would add C:\Scripts\www to my PATH variable
echo "PHP CLI Version: ${default_php//[!.0-9]/}, to change press P";
echo "MySQL CLI Version: ${default_mysql//[!.0-9]/}, to change press M";
echo '____________________________________';
while : ; do
read -s -n 1 k <&1
if [[ $k = p ]] ; then
for entry in "$php_folder"/*
do
if [[ ! $entry == *.txt ]]; then
arrVar[${#arrVar[@]}]=$(basename $entry)
fi
done
for i in "${!arrVar[@]}"
do
echo "$i : PHP ${arrVar[$i]//[!.0-9]/}"
done
read -s -n 1 opt <&1
if [ "${arrVar[opt]+abc}" ]; then
cd $main_link_folder
rm -rf $link_php
ln -rsfT $php_folder${arrVar[$opt]} $link_php
cd $current_folder
alias mysql="winpty $mysql_folder$default_mysql/bin/mysql.exe"
return
else
cd $main_link_folder
rm -rf $link_php
ln -rsfT $php_folder$default_php $link_php
cd $current_folder
alias mysql="winpty $mysql_folder$default_mysql/bin/mysql.exe"
return
fi
else
cd $main_link_folder
rm -rf $link_php
ln -rsfT $php_folder$default_php $link_php
cd $current_folder
alias mysql="winpty $mysql_folder$default_mysql/bin/mysql.exe"
return
fi
done
break
I just saved this script in my user folder and it loads everytime i open git bash, neat!
My problem is solved.
Any suggestions or further improvements are welcome.
Thank you all
精彩评论