命令行在本地使用wamp

时间:2011-09-09 11:46:30

标签: shell command-line wamp

在这里提到这篇文章时:

http://net.tutsplus.com/tutorials/javascript-ajax/start-using-html5-websockets-today/

它告诉你使用XAMPP从shell运行php -q path \ to \ server.php,是否有替代WAMP?

5 个答案:

答案 0 :(得分:25)

将php.exe注册为环境变量可能很有用,因此命令行可以识别'php'命令而不需要输入完整路径'\ wamp \ bin \ php \ php5.3.8 \ php'as命令。

为此,您可以按照此页面上列出的步骤操作:http://windows.fyicenter.com/view.php?ID=60。除步骤5外,请输入WAMP的php.exe路径。例如,只需将$;C:\wamp\bin\php\php5.3.8添加到“变量值”字段即可。每次打开命令行时,只需使用

运行php
php pageYouAreRunning.php 

..仍然记住pageYouAreRunning.php是相对于命令行中的当前路径。

答案 1 :(得分:3)

它与描述的基本相同。您将需要打开windows cmd shell,然后您只需要在特定安装中找到php文件的位置。

在wamp安装中,我将它放在\wamp\bin\php\php5.3.8\php。所以要运行我想要的php脚本,我会打电话给...

\wamp\bin\php\php5.3.8\php pageYouAreRunning.php 

请记住pageYouAreRunning.php与您在shell控制台中的当前路径相关。

答案 2 :(得分:2)

未经测试,但我会说它是相同的......

你的wamp / php文件夹中有一个“php.exe”......

通过命令行运行:

cd mywamp/php

php -q file.php

答案 3 :(得分:1)

如果php根本没有运行,请使用以下代码创建一个批处理文件,并将其另存为“ php”。

"c:\wamp64\bin\php\php7.0.29\php.exe" $1 ${2} ${3} ${4}

当然,用您机器上的任何php版本替换php7.0.29
然后只需像正常运行任何php命令,例如

php -v

如果您需要更多参数,只需继续将其添加为可选参数即可,例如$ {5} $ {6}

答案 4 :(得分:1)

不再建议编辑环境路径以直接指向PHP exe的路径。这可能会使您头痛不已。

WampServer forum上一位名叫RiggsFoley的主持人共享了以下文件 称为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=

按照说明,您需要编辑baseWampdefaultPHPver变量。检查Wamp的bin\php目录中可用的PHP版本号。

将文件放在C:\Windows目录中,然后打开一个新的命令窗口,然后键入phppath。现在,在该窗口的会话期间,您将可以使用php