0

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?

agentphoenix
  • 67
  • 2
  • 7
  • I think you should google first for this. you can get lots of answer. check this its same except the OS: http://stackoverflow.com/questions/9766622/solvedphp-extension-loaded-in-command-line-cli-but-not-loaded-by-apache – Ashish Awasthi Feb 27 '15 at 14:15

2 Answers2

1

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.

phpPhil
  • 906
  • 1
  • 9
  • 28
  • 1
    For anyone else looking at this, the `php -c` is for one-time execution. If you want to get this to work every single time, [this answer](http://stackoverflow.com/questions/10844641/how-to-change-the-path-to-php-ini-in-php-cli-version) should point you in the right direction of getting it setup so you don't have to alias `php` in your profile. – agentphoenix Feb 27 '15 at 14:54
1

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

Nebojsa Tomcic
  • 608
  • 5
  • 7