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?
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
Related
My PHP script is working very well when executed via browser but showing error message when tried to execute using Command prompt.
First I tested php file from command prompt using "system('ls >/tmp/test.txt')" in php file. It worked fine.
But when executed Mysql query within PHP script via command prompt it's showing error.(note: same mysql query within php file was successfully executed from browser).
command: php fullpath____/automatic.php
error: PHP Fatal error: Call to undefined function mysqli_connect() in fullpath_____/automatic.php on line number 7.
What is the problem ?
Note that PHP may use completely different configurations for the CLI (command-line) version and the one that the webserver forwards to (for example, PHP-FPM)
That error means that the mysql extension is not enabled for PHP's CLI configuration. Login as a privileged user and try this:
sudo php5enmod mysql, after that is should work.
php command line uses diferent php.ini than php browser.
You must have installed pdo_mysql extension.
In linux system the command line php.ini is in
/etc/php5/cli/php.ini
And the browser php.ini is in
/etc/php5/apache2/php.ini
Check that you have in that files
extension=pdo_mysql.so
I'm trying to get PHP talking to MS SQL server by following this guide, which is for SQL server 2005 (I'm using 2014 express but it was the most recent I could find).
I'm running 32bit Wamp and PHP 5.5.12. I have installed php_sqlsrv_55_ts.dll and php_sqlsrv_55_ts.dll in the ext folder and have added the following lines to php.ini:
extension=php_sqlsrv_55_ts.dll
extension=php_pdo_sqlsrv_55_ts.dll
All seems to go smoothly but no SQLSRV information is listed under phpinfo() and on the php extensions tab for Wamp they are listed but with a red triangle containing an exclamation mark next to them.
Anyone know what I've missed?
If you just type php at the command line it waits for more input, it does not hang.
If when you run php from the command line ( PHP CLI ) you see sqlsrv is supported but not when you run phpinfo through Apache, then you have edited the wrong php.ini file. There are normally 2, one to control PHP CLI and one to control PHP when being run under Apache.
The php.ini that controls php under apache is normally in the \apache\bin folder. The exact path is of course dependant upon whether you use WAMPServer/XAMPP... or install everything yourself.
I had php 5.3 installed with apache 2.2
I just added php 5.57 x64 with apache 2.4 x64
both setups seem to be working fine in parallel when pulling php pages through browsers
can't run php pages/scripts from command line using the new php 5.57 executable
(I cd to the directory c:\php55 then run the command: php -f c:\... path to template in htdocs)
same php pages/scripts run just fine with 5.3 php executable using same exact command
same php pages/scripts run just fine through browsers using the new php 5.57 executable (configured on port 8080)
I'm on windows 2008 r2
any idea folks?
You should use absolute path. For example
c:\php55\php.exe c:\htdosc\script.php
Also check waht php executable file is in folder c:\php55 May be it in c:\php55\bin
I am trying to execute a php file with a specific MAMP php version(/Applications/MAMP/bin/php/php5.3.14/bin/php) . But even though I have enabled APC caching while starting MAMP, apc code are getting error like "Fatal error: Call to undefined function apc_fetch()" . in general running of that script from browser via 'localhost' works fine.
I have also tried by adding 'apc.so' to php.ini file for that php version. But this is generating another error 'Segmentation fault: 11' .
What can I do to get the APC running under that php cli version please? Thanks.
MAMP uses a different php.ini for CLI. Here's how to find it:
$ php -i | grep php.ini
Configuration File (php.ini) Path => /Applications/MAMP/bin/php/php5.5.10/conf
Loaded Configuration File => /Applications/MAMP/bin/php/php5.5.10/conf/php.ini
In this case you should edit /Applications/MAMP/bin/php/php5.5.10/conf/php.ini and uncomment:
;extension=apcu.so
EDIT: make sure php is the MAMP php and not system php! In doubt use:
$ /Applications/MAMP/bin/php/php5.5.10/bin/php -i | grep php.ini
I am attempting to configure PHP and Mongo DB to connect with one another and I'm having some troubles. Before I say the problem let me recap what I have so far.
I am using MAC OS X 10.6.8
I have mongo DB installed and working stand-alone.
I have enabled PHP on the default Mac OS Apache web server. It is working and the server recognizes PHP ( it is not allowing inline PHP scripts in HTML files...not sure if this an issue)
"Web sharing" works just fine.
I have installed pear via this url: curl -O http://pear.php.net/go-pear.phar
I have the pear folder and files accessible and have launched o-pear.php from a web browser.
I have gone through the step-by-step install process ( and removed any red displayed errors ).
Presumably Pear is now installed.
It says at the bottom of the install front end:
Note: To use PEAR without any problems you need to add your PEAR
Installation path (/Users/myname/Sites/PEAR) to your
include_path.
Using a .htaccess file or directly edit httpd.conf would be working
solutions for Apache running servers, too.
I am not sure what the code is I need to add for the httaccess rewrite.
As of this moment
Terminal does not recognize the pear command.
When I launch the pear "front end" from a web browser I get:
Fatal error: No PEAR.php in supplied PEAR directory: /Users/myname/Sites/PEAR in /Users/myname/Sites/index.php on line 24
Thank you.
That is all.
Create a new PHP file called phpinfo.php. Add the content <?php phpinfo(); ?> there. Run the script from within your webbrowser.
You should see a big page with PHP configuration information. Watch out for include_path. This is where your webserver/PHP module/process searches for include files.
You will also find Loaded Configuration File. This is the PHP configuration file being used. Open that file in any editor, and search for include_path again. Add /Users/myname/Sites/PEAR to the end of the include_path.
Restart your webserver. PEAR now should work.
If you need to install the MongoDB PHP extension, go for pecl install mongo from command line.