How to use MAMP's version of PHP instead of the default on OSX
I would not recommend trying to modify the default version of PHP that is called on the command line. Doing so may break other parts of your system as well as provide you with problems in the future, should you decide to upgrade your OS.
There is an alternative that may meet your needs. You can create an alias to your copy of MAMP's php 5.3. In my case I named the alias phpmamp. Open your terminal and type:
alias phpmamp='/Applications/MAMP/bin/php5.3/bin/php'
Now, typing phpmamp at the command line will launch the MAMP php interperter. Verify this by typing:
phpmamp --help
You will most likely want to store this, and any other alias, in a ~/.bash_profile
This will allow the aliases to persist across reboots. Otherwise, the alias should only last for the particular terminal session you are in. More information about creating a .bash_profile
file can be found here:
http://www.redfinsolutions.com/redfin-blog/creating-bashprofile-your-mac
How to override the path of PHP to use the MAMP path?
Everytime you save MAMP config (PHP section), it saves the current version of PHP on ~/.profile
file and creates the alias for php, pear and pecl, to point to the current configured version. (Note: you need to check "Make this version available on the command line" option in MAMP)
However, you need to refresh your terminal (open another session) to get this file refreshed. You can also type source ~/.profile
to refesh the aliases manually.
If you want to extract this curerent version in a PHP_VERSION variable - as commented above - for further use, you can do:
export PHP_VERSION=`grep "alias php" ~/.profile | cut -d"/" -f6 | cut -c4-`
And then you'll have $PHP_VERSION available with the current version of MAMP.
Finally, if you want to run your php using the current configured version on mamp, you just need to add to your ~/.bash_profile
the following:
export PHP_VERSION=`grep "alias php" ~/.profile | cut -d"/" -f6 | cut -c4-`
export PHPRC="/Library/Application Support/appsolute/MAMP PRO/conf/" #point to your php.ini folder to use the same php settings
export PATH=/Applications/MAMP/bin/php/php$PHP_VERSION/bin:$PATH
Now, even script that relies on /usr/bin/env php
will read the correct version from Mamp config.
How to run a PHP script from the command line with MAMP?
Please note that with version 2.0.5 of MAMP, the path has changed. It is now one of the following:
/Applications/MAMP/bin/php/php5.2.17/bin/
/Applications/MAMP/bin/php/php5.3.6/bin/
Therefore the command to add MAMP's php command should probably look like this:
export PATH=/Applications/MAMP/bin/php/php5.2.17/bin/:$PATH
or like this (depending on which version of PHP you want to use):
export PATH=/Applications/MAMP/bin/php/php5.3.6/bin/:$PATH
Use MAMP Pro php.ini instead of OSX php
The MAMP Pro
PHP
executable should be located in /Applications/MAMP/bin/php/php5.x.x/bin/
.
The OSX
PHP
is located in /usr/bin/php
and /usr/bin
is in PATH
variable by default.
One way to make OSX
use MAMP
PHP
is to add /Applications/MAMP/bin/php/php5.x.x/bin/
to your PATH
variable (before /usr/bin
):
Simply edit ~/.profile
(ie. open Terminal.app
, type vim ~/.profile
) and add the following line to end of the file:
export PATH=/Applications/MAMP/bin/php/php5.x.x/bin/:$PATH
Note that you should replace x
s in php5.x.x
with the MAMP Pro
PHP
version.
Change default Mac OS X PHP to MAMP's PHP Installation on oh-my-zsh
Ok i figured out it - I had to add #
before export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
Where does MAMP keep its php.ini?
Note: If this doesn't help, check below for Ricardo Martins' answer.
Create a PHP script with <?php phpinfo() ?>
in it, run that from your browser, and look for the value Loaded Configuration File
. This tells you which php.ini
file PHP is using in the context of the web server.
How to align my PHP version on my Mac with the PHP version installed in MAMP during Laravel installation?
I think maybe you're using default php builded on yosemite.
Type
php --ini
in terminal. you'll see information about php.ini file. for exp.
Configuration File (php.ini) Path: /Applications/XAMPP/xamppfiles/etc
Loaded Configuration File: /Applications/XAMPP/xamppfiles/etc/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)- Or type
which php
and you'll see path of php folder for exp.
/Applications/XAMPP/xamppfiles/bin/php
- Or type
If it's different than MAMP folder (if it's default - /usr/bin/php
)
Change it to MAMP folder. To do it you need to change .bash_profile and add the MAMP version of PHP to the PATH variable.
You can edit .bash_profile with vim. Export the path variable with command
export PATH=/Applications/MAMP/bin/php/php[php.version]/bin:$PATH
Finally, check again if php path is correct with commands php --ini
or which php
Related Topics
How to Generate Random Date Between Two Dates Using PHP
PHP Function to Get Mp3 Duration
Sqlstate[Hy000] [1045] Access Denied for User 'Username'@'Localhost' Using Cakephp
Setting Value of a HTML Form Textarea
How to Capture the Result of Var_Dump to a String
Turn Off Warnings and Errors on PHP and MySQL
Select Outgoing Ip for Curl Request
What's the Disadvantage of Mt_Rand
Removing Array Index Reference When Using JSON_Encode()
Warning: File_Get_Contents(): Https:// Wrapper Is Disabled in the Server Configuration by All
Generating Xml Document in PHP (Escape Characters)
Retrieve All Hashtags from a Tweet in a PHP Function
Is There a PHP Sandbox, Something Like Jsfiddle Is to Js
Why Should I Use Templating System in PHP
PHP Function to Delete All Between Certain Character(S) in String