使用MAMP for Windows的命令行上的PHP版本

使用MAMP for Windows的命令行上的PHP版本

问题描述:

I run MAMP on my Mac at home, but on my work machine (Win7) I just started using MAMP for Windows so that I'm running the same (relatively speaking) software between the two machines. I was running some commands from the command line yesterday and noticed that the script was throwing errors because the mbstring extension wasn't loaded. I did some digging and am left scratching my head now...

In the browser, everything works fine. When I check the phpinfo, it's loading the configuration file just fine and mbstring is enabled. When I switch to the command line though, mbstring isn't in the list of modules (php -m). Also, when I do a php --ini, it tells me that no configuration file was loaded. I've added the correct PHP version to my PATH and running php -v gives me the version I expect, so I'm not really sure why PHP on the command line is acting differently from PHP in the browser.

Has anyone run into this before? How do I make PHP on the command line load the same configuration file that the browser is using?

我在家里的Mac上运行MAMP,但在我的工作机器(Win7)上我刚开始使用MAMP for Windows 所以我在两台机器之间运行相同(相对来说)的软件。 我昨天从命令行运行了一些命令并注意到脚本因为没有加载 mbstring code>扩展名而抛出错误。 我做了一些挖掘,现在我正在挠头... p>

在浏览器中,一切正常。 当我检查 phpinfo code>时,它正在加载配置文件,并且启用了 mbstring code>。 当我切换到命令行时, mbstring code>不在模块列表中( php -m code>)。 此外,当我执行 php --ini code>时,它告诉我没有加载任何配置文件。 我已经将正确的PHP版本添加到我的PATH并运行 php -v code>给了我期望的版本,所以我不确定为什么命令行上的PHP与PHP的行为不同 浏览器。 p>

之前有没有人碰到这个? 如何在命令行上加载PHP加载浏览器使用的相同配置文件? p> div>

Command line php (CLI) is a different executable to CGI PHP. It also uses typically a different php.ini file. You can however specify the location of the php.ini you would like to load when launching php cli:

php -c <path to your php.ini>

Have a look here.

This example assumes you use C:\MAMP\ as installation directory.

As you need configuration as used in Windows MAMP you will need to supply it as argument to php.

Open command prompt.

To execute test.php with script located in C:\MAMP\htdocs\ by using PHP5.6.0 from MAMP:

C:\MAMP\bin\php\php5.6.0\php.exe -c "C:\MAMP\conf\php5.6.0\php.ini" "C:\MAMP\htdocs\test.php"

As you can notice last argument is the script to be executed ("C:\MAMP\htdocs\test.php").

To execute phpinfo from command line:

C:\MAMP\bin\php\php5.6.0\php.exe -c "C:\MAMP\conf\php5.6.0\php.ini" -r phpinfo();

There should be line from phpinfo output which acknowledges that you're using configuration from C:\MAMP\conf\php5.6.0\php.ini.

Loaded Configuration File => C:\MAMP\conf\php5.6.0\php.ini