I have both ~/.bash_profile & ~/.profile files.
~/.bash_profile contains one line:
export PATH=/Applications/mamp/bin/php5.5.3/bin:$PATH
~/.profile contains three lines:
# MacPorts Installer addition on 2014-02-02_at_20:54:53: adding an appropriate PATH variable for use with MacPorts.
export PATH=/Applications/MAMP/bin/php5.5.3/bin/:/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
As you can see I am trying to get my default PHP PATH to use MAMPs PHP because I have mcrypt installed on it. For some reason when I type whereis PHP I get the native route: /usr/bin/php, and when I echo $PATH I get:
/Applications/mamp/bin/php5.5.3/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
Somewhere I have another file thats really controlling my PATH and I have no clue where it is. What else could be controlling my PATH route?
NOTE: I have Homebrew, MacPorts, Xcode, and Xcode Command-Line Tools installed.
What you're seeing is coming from the system-wide /etc/paths file. It is the source of the base $PATH environment variable before ~/.profile, ~/.bash_profile and others get involved. If you're in a Terminal window, you can edit it with the following command:
sudo open -t /etc/paths
By default it contains the following paths:
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
I wouldn't recommend editing this file, however, because it is system-wide and will affect every user on the system.
If you want complete control over $PATH, so as to affect only your own account you're probably better off just not including $PATH in your .profile's export PATH lines. For example (but not this):
export PATH=/Applications/mamp/bin/php5.5.3/bin:/opt/local/bin:/opt/local/sbin
Are you sure .profile is being loaded? Try a test and add an echo line to it:
echo "test: .profile has loaded"
Now open a new terminal window, do you see your echo? I suspect not as I don't think OSX loads .profile by default, at least today.
If you really want to use .profile you can ask .bash_profile to load it:
if [ -f ~/.profile ]; then
source ~/.profile
fi
Hope this helps.
Edit:
Looks like .profile is loaded, if no .bash_profile or .bash_login exist as suggested in this answer
Related
Good morning all,
I have a little problem with variable $PATH in my .bash_profile file.
I have an OSX system with XAMPP installed.
I have edit my .bash_profile in this way:
export XAMPP_HOME="/Applications/XAMPP/xamppfiles"
export PATH="${XAMPP_HOME}/bin/php-5.4.22:${PATH}"
export PATH="$PATH:/Users/alessandrominoccheri/Sites/site.com/lib/Cake/Console"
export PATH
After I have restart apache and write into console:
source ~/.bash_profile
and type:
which php
But always return me:
/usr/bin/php
How can I change path?
I have changed permission on bin folder but same problem.
I have followed this link but I have the same problem:
Mac OSX PHP and XAMPP path issue
If ${XAMPP_HOME}/bin/php-5.4.22 is the executable, then adding it to your path doesn't help you in being able to call it using php. The $PATH needs to contain directories in which executables are, which will be searched in the order they're defined whenever you mention any executable by name.
You either want to alias your php-5.4.22 to php in your profile, or maybe better, create a symlink for it that overrides your default php. E.g.:
$ ln -s ${XAMPP_HOME}/bin/php-5.4.22 /usr/local/bin/php
I've read the global installation documentation for Composer, but it's for *nix systems only:
curl -s https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
I would be such happy doing the same on Windows, that's the OS of my development machine. I would be able to run
composer update
From an arbitrary folder where composer.json exists. Interpreter php.exe is already in PATH variable.
Any clue?
Sure. Just put composer.phar somewhere like C:\php\composer.phar, then make a batch file somewhere within the PATH called composer.bat which does the following:
#ECHO OFF
php "%~dp0composer.phar" %*
The "%*" repeats all of the arguments passed to the shell script.
Then you can run around doing composer update all ya want!
Install Composer
On Windows, you can use the Composer Windows Installer.
Go to php.exe located folder.
C:\wamp\bin\php\php5.5.12\
open cmd there, and execute below command.
php -r "readfile('https://getcomposer.org/installer');" | php
composer.phar will be downloaded in same folder.
Create folder named composer in C:// drive (or anywhere you wish, for upcoming steps, remember the path).
move composer.phar file to C://composer folder.
Create composer.bat file in same folder with contents below
#ECHO OFF
php "%~dp0composer.phar" %*
create file named composer without any extensions.
running command type NUL > composer in CMD will help to get it done quickly,
Open that file and place below contents inside it.
#!/bin/sh
dir=$(d=$(dirname "$0"); cd "$d" && pwd)
# see if we are running in cygwin by checking for cygpath program
if command -v 'cygpath' >/dev/null 2>&1; then
# cygwin paths start with /cygdrive/ which will break windows PHP,
# so we need to translate the dir path to windows format. However
# we could be using cygwin PHP which does not require this, so we
# test if the path to PHP starts with /cygdrive/ rather than /usr/bin.
if [[ $(which php) == /cygdrive/* ]]; then
dir=$(cygpath -m $dir);
fi
fi
dir=$(echo $dir | sed 's/ /\ /g')
php "${dir}/composer.phar" $*
Save.
Now set path, So we can access composer from cmd.
Show Desktop.
Right Click My Computer shortcut in the desktop.
Click Properties.
You should see a section of control Panel - Control Panel\System and
Security\System.
Click Advanced System Settings on the Left menu.
Click Environment Variables towards the bottom of the window.
Select PATH in the user variables list.
Append your PHP Path (C:\composer) to your PATH variable, separated
from the already existing string by a semi colon.
Click OK
Restart your machine.
Or, restart explorer only using below command in CMD.
taskkill /f /IM explorer.exe
start explorer.exe
exit
Original Article with screenshots here : http://aslamise.blogspot.com/2015/07/installing-composer-manually-in-windows-7-using-cmd.html
This may be useful to someone:
On Windows 7, if you've installed Composer using curl, it can be found in similar path:
C:\Users\<username>\AppData\Roaming\Composer
Well, now this question is a bit obsolete as there is now an official installer which "will install the latest Composer version and set up your PATH so that you can just call composer from any directory in your command line."
You can get it at : http://getcomposer.org/doc/00-intro.md#installation-windows
A bit more generic if you put the batch in the same folder as composer.phar:
#ECHO OFF
SET SUBDIR=%~dp0
php %SUBDIR%/composer.phar %*
I'd write it as a comment, but code isn't avail there
Start > Computer : Properties > Change Settings > Advanced > Environment Variables > PATH : Edit [add this string (without "") at the end of line ";C:\<path to php folder>\php5.5.3"].. open cmd and type composer
thats it :-)
I use Composer-Setup.exe and it works fine.
Just in case you need to know where is the composer.phar (to use with PhpStorm) :
C:\ProgramData\ComposerSetup\bin\composer.phar
Unfortunately, all the good answers here didn't work for me. So after installing composer on windows 10, I just had to set system variable in environment variables and it worked.
sorry to dig this up, I just want to share my idea, the easy way for me is to rename composer.phar to composer.bat and put it into my PATH.
An alternative variant (see Lusitanian answer) is to register .phar files as executable on your system, exemplary phar.reg file:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.phar]
#="phar_auto_file"
[HKEY_CLASSES_ROOT\phar_auto_file\shell\open\command]
#="\"c:\\PROGRA~1\\php\\php.exe\" \"%1\" %*"
Just replace the path to php.exe to your PHP executable. You can then also extend the %PATHEXT% commandline variable with .PHAR which will allow you to type composer instead of composer.phar as long as composer.phar is inside the %Path%.
I was having the same issue and when I checked the environment in Windows 7 it was pointing to c:\users\myname\appdata\composer\version\bin which didn't exists.
the file was actually located in
C:\ProgramData\ComposerSetup\bin
Fixed the location in environment setting and it worked
you can install it using this command line
echo #php "%~dp0composer.phar" %* > composer.bat
I found that on Control Panel > Environment Variables > Variables for my localuser just inside PATH varible like this:
C:\Users\MY_USER_NAME\AppData\Roaming\Composer\vendor\bin
I'm running PHP with MAMP on OSX 10.5.8
So if I want to run a script from console I always need to write
/applications/mamp/bin/php5.3/bin/php path/to/script
which is annoying. Is there a way to change the default path to php so that I can write
php path/to/script
and still uses MAMPs PHP version?
Create a file called .bash_profile on your home directory (if you don't have this file already), and add this to the file:
export PATH=/Applications/mamp/bin/php5.3/bin:$PATH
Then quit and relaunch Terminal.app
Use latest MAMP version of PHP
you need to edit .bash_profile
open -a TextEdit ~/.bash_profile
if you cannot find bash_profile under your home directory then create .bash_profile:
touch ~/.bash_profile
Use latest MAMP version of PHP
PHP_VERSION=`ls /Applications/MAMP/bin/php/ | sort -n | tail -1`
export PATH=/Applications/MAMP/bin/php/${PHP_VERSION}/bin:$PATH
(Run source ~/.bash_profile after making your changes to make sure they take effect.)
source: How to override the path of PHP to use the MAMP path?
The easiest way would be to rewrite the alias. Just copy/paste the cmd bellow into terminal for temporary use or write it into .bash_profile to make it permanent.
For MAMP
$ alias php=/applications/mamp/bin/php5.3/bin/php
For XAMPP
$ alias php=/Applications/XAMPP/bin/php
For AMPPS
$ alias php=/Applications/AMPPS/php-5.6/bin/php
Run php via our new alias
$ php -v
vi ~/.bash_profile
//add
export PATH=/path/to/php/bin:$PATH
source ~/.bash_profile
In addition to bfvarettos great answer: since .bash_profile executes at login, you will need to restart your system for the changes to take effect.
I'm not sure if this is specific to MAMP 3.0 or not but you need to do the following path for MAMP 3.0. Make sure you change the PHP version to the version you are using for your server.
Again this goes in ~/.bash_profile
export PATH=/Applications/MAMP/bin/php/php5.5.10/bin:$PATH
I would like to use MAMP's version of PHP instead of the default installed on my mac. I tried using
ln -s /Applications/MAMP/bin/php5.3/bin/php php
but I get a "File exists" error. What's the best way to work around this so I can just type php instead of the full path?
I have created a symlink at the original php location.
1. Locate your osx php version with:
which php
The result should be:
/opt/local/bin/php
2. Backup (move) your original php binary:
sudo mv /opt/local/bin/php /opt/local/bin/php.bak
3. Create the symlink:
sudo ln -s /Applications/MAMP/bin/php/php5.4.4/bin/php /opt/local/bin/php
4. Run your new php version:
php -v
PS:
In order for this to work on El-Capitan
Reboot your Mac to RecoveryMode (hold Cmd+R on boot)
Open Terminal and enter: csrutil disable
Reboot
either : sudo ln -s /Applications/MAMP/bin/php/php5.4.4/bin/php /opt/local/bin/php
or sudo ln -s /Applications/MAMP/bin/php/php5.4.4/bin/php /usr/bin/php
Reboot again to RecoveryMode and re-enable security: csrutil enable
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
I prefer not to tamper with the current files, so I just prepend the MAMP PHP bin folder to the $PATH env variable.
You can edit ~/.bash_profile and add the the following line to the top
export PATH="/Applications/MAMP/bin/php/php5.6.1/bin:$PATH"
Just change the PHP version to the current version you are using.
Don't forget to do source ~/.bash_profile after you edit the file.
I wasn't pleased with the results / solutions I've found on the net so far, because the php.ini configs weren't loaded properly in all cases and on all systems, espacially when you need modules like ioncube and others (it's even more confusing on MAMP Pro). That's why I've created my own php version aliases (with configs), so I've come up with the following solution, as example (based on MAMP Pro, remember to adjust the php.ini paths to your needs):
Edit your .bash_profile
vim ~/.bash_profile
And add the following entries:
alias php55="/Applications/MAMP/bin/php/php5.5.26/bin/php -c '/Library/Application Support/appsolute/MAMP PRO/conf/php5.5.26.ini'"
alias php56="/Applications/MAMP/bin/php/php5.6.10/bin/php -c '/Library/Application Support/appsolute/MAMP PRO/conf/php5.6.10.ini'"
alias php56cgi="/Applications/MAMP/bin/php/php5.6.10/bin/php-cgi -c '/Library/Application Support/appsolute/MAMP PRO/conf/php5.6.10.ini'"
Re-Initialize the .bash_profile in the current terminal session (otherwise you won't see any changes, unless you restart the terminal):
source ~/.bash_profile
If you have some additional modules installed, then you can test it with php56 -v and you should get a output of the ioncube, etc. modules. Otherwise test it with php56 -i | grep "yourModuleNameOrSomethingElse"
Now you are able to easily use one of the php versions like "php56" in your terminal with all configs loaded. So it's perfect for testing and building your applications through all iterations of versions including the right php.ini configs through the terminal.
For normal MAMP Users, the configs should be located in /Applications/MAMP/conf/ I think. Happy programming.
2021 - For those using ohmyzsh, the file to edit is:
/Users/your_user/.zshrc
so, you can edit this file and add the path:
export PATH=/Applications/MAMP/bin/php/php8.0.0/bin:$PATH
Works Perfectly with Big Sur
The latest version of MAMP (Version 5+) offers an easy way to make the MAMP PHP version available to the command line. Just select "PHP" in the the side bar menu and check "Make this version available on the command line". Easy peasy! :)
screenshot
If your terminal is using zsh (oh-my-zosh) as shown in the attachment.
check image
Do the following.
Mac Big Sur uses "zsh" Oh-my-zosh for the terminal. so, I did the following.
open terminal.
check if you have .zshrc file in your profile path (/Users/yourProfileName)
if you don't have .zshrc file, create one using (~ touch .zshrc) command.
add these lines:
export MAMP_PHP=/Applications/MAMP/bin/php/php7.4.12/bin
export PATH="$MAMP_PHP:$PATH"
save the file. close the terminal and reopen it. Now run "which php".
let me know if you need help.
For Mac OS Catalina. Find directory /Users/<user_name>/.zprofile
and add (for example)
# MAMP PRO PHP
export PATH="/Applications/MAMP/bin/php/php7.4.2/bin:$PATH"
after reboot, in terminal
which php
new php version /Applications/MAMP/bin/php/php7.4.2/bin/php
Well, the 'file exists' error is probably because you attempted to create a sym-link with the name of a file that was already there. I assume you were in the directory containing the php version you were trying to replace or that this was a second attempt and you did not first remove the existing sym-link. I agree with the others with regard to not "replacing/modifying" the default version of php.
Based on the second part of the question, the best way to get around having to type the full path, the answers suggesting an alias are right on point with that. When multiple versions are involved though, that means having to call something other than php to run the version you want to run.
I have a script that lets me "select" the version of php that I would like to work with which then creates a sym-link to that version and lets me simply enter 'php' as my command when I want to use it. I wrote a blog about it here where you can get the script. Based on the answer given by #ioCron I may need to revisit my script to account for the different config folders associated with each version.
Well none of this was working for me with OSX10.12.5
i have mac ports php70 installed at /opt/local/bin
which php showed:
/usr/bin/php
I set up the aliases and local paths etc, which mostly worked for me, but other programs were failing (like composer) so the solution for me was to prepend:
/opt/local/bin
/opt/local/sbin
to the file /etc/paths
then it all worked a charm!
After screwing up entirely my PHP configuration on MAC trying to get the SOAP module working (-bash: /usr/bin/php: No such file or directory
....) I now have to use MAMP but each time I have to type the path
Applications/MAMP/bin/php5.3/bin/php to do command line.
How to just type php instead the entire path on MAC ? I double checked and i do not have a file named .profile nor bash_profile
Thanks
PS: Here's what output echo $PATH :
echo $PATH
/Applications/MAMP/Library/bin/:/Applications/MAMP/bin/php5/bin/:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin
In your home folder /Users/David for exmaple, you can create a .bash_profile. In here you can export variables and then add them to your path.
Open up the file to edit it in your favourite editor, I use vim.
Then you can add in your path
export MAMP_PHP=/Applications/MAMP/bin/php/php5.3.6/bin
export PATH="$MAMP_PHP:$PATH"
You want your bit ahead of the $PATH as that already includes /usr/bin which is where the system PHP lives. So the system will always find your MAMP version first.
Save this file and then reboot your Terminal and you'll see that you should get your MAMP version.
To test I use php -v as OSX Lion uses 5.3.10 and my MAMP is using 5.3.6
You can also test using which php which will output the path to your current php executable.
The fact that the previously accepted answer refers to php 5.3.6, while the current version of MAMP ships with 7.2.1 as the default (as of early 2018), points out that this is not a very sustainable solution. You can make your path update automatically by adding an extra line to your .bash_profile or .zshrc to get the latest version of PHP from /Applications/MAMP/bin/php/ and export that to your path. Here’s how I do it:
# Use MAMP version of PHP
PHP_VERSION=`command ls /Applications/MAMP/bin/php/ | sort -n | tail -1`
export PATH=/Applications/MAMP/bin/php/${PHP_VERSION}/bin:$PATH
(Use source ~/.bash_profile after making your changes to make sure they take effect.)
As others have mentioned, you will likely also want to modify your shell to use MAMP’s mysql executable, which is located in /Applications/MAMP/Library/bin. However, I do not recommend exporting that folder, because there are a bunch of other executables there, like libtool, that you probably don’t want to be giving priority to over your system installed versions. This issue prevented me from installing a node package recently (libxmljs), as documented here.
My solution was to define and export mysql and mysqladmin as functions:
# Export MAMP MySQL executables as functions
# Makes them usable from within shell scripts (unlike an alias)
mysql() {
/Applications/MAMP/Library/bin/mysql "$#"
}
mysqladmin() {
/Applications/MAMP/Library/bin/mysqladmin "$#"
}
export -f mysql
export -f mysqladmin
I used functions instead of aliases, because aliases don’t get passed to child processes, or at least not in the context of a shell script. The only downside I’ve found is that running which mysql and which mysqladmin will no longer return anything, which is a bummer. If you want to check which mysql is being used and make sure everything is copacetic, use mysql --version instead.
Note: #julianromera points out that zsh doesn’t support exporting functions, so in that case, you’re best off using an alias, like alias mysql='/Applications/MAMP/Library/bin/mysql'. Just be aware that your aliases might not be available from subshells (like when executing a shell script).
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.
I found that on Mavericks 10.8 there wasn't a .bash_profile and my paths were located in /etc/paths
In order to have the new path (whether this is a mamp or brew install of php) take effect it needs to be above the default /usr/bin/php in this paths file. eg.
/Applications/MAMP/bin/php/php5.3.6/bin
/usr/bin
AFter the change, open a new terminal window and run 'which php' that should now point to your updated path
you might still run into mysql binary not being found in that manner
open terminal, type
touch ~/.bash_profile; open ~/.bash_profile
edit as follows below, save, quite and restart terminal or alternately
source ~/.bash_profile
to execute new PATH without restarting terminal
and in the fashion of the DavidYell's post above, also add the following. You can stack various variables by exporting them followed by a single PATH export which I demonstrated below
export MAMP_PHP=/Applications/MAMP/bin/php/php5.6.2/bin
export MAMP_BINS=/Applications/MAMP/Library/bin
export USERBINS=~/bins
export PATH="$USERBINS:$MAMP_PHP:$MAMP_BINS:$PATH"
cheers
If you have to type
/Applications/MAMP/bin/php5.3/bin/php
in your command line then add
/Applications/MAMP/bin/php5.3/bin
to your PATH to be able to call php from anywhere.
For XAMPP users you can use this:
# Use XAMPP version of PHP
export PATH=/Applications/XAMPP/xamppfiles/bin:$PATH
source ~/.bash_profile
And you can check it with:
php -v
This one worked for me:
sudo mv /usr/bin/php /usr/bin/~php
sudo ln -s /Application/XAMPP/xamppfiles/bin/php /usr/bin/php
Sometimes, it's easier to do this:
sudo ln -s /Applications/MAMP/bin/php/php5.6.10/bin/php /usr/bin/php;
Mamps version of PHP at the time of posting was php5.6.10, so make sure you change that to the version you're using.
You'll be up in a jiffy.
Probably too late to comment but here's what I did when I ran into issues with setting php PATH for my XAMPP installation on Mac OSX
Open up the file .bash_profile (found under current user folder) using the available text editor.
Add the path as below:
export PATH=/path/to/your/php/installation/bin:leave/rest/of/the/stuff/untouched/:$PATH
Save your .bash_profile and re-start your Mac.
Explanation: Terminal / Mac tries to run a search on the PATHS it knows about, in a hope of finding the program, when user initiates a program from the "Terminal", hence the trick here is to make the terminal find the php, the user intends to, by pointing it to the user's version of PHP at some bin folder, installed by the user.
Worked for me :)
P.S I'm still a lost sheep around my new Computer ;)
The latest version of MAMP (Version 5+) offers an easy way to make the MAMP PHP version available to the command line. Just select "PHP" in the the side bar menu and check "Make this version available on the command line". Easy peasy! See attached screenshot:)
This is not an ideal solution as you have to manage two ini files however, I managed to work around this on windows by copying the php ini file in mamp from the conf folder to your active php version in the bin folder.
[MAMP INSTALL]\conf\[ACTIVE PHP VERSION]\php.ini
copy to
[MAMP INSTALL]\bin\php\[ACTIVE PHP VERSION]
To compliment the current accepted answer, if you assume that MAMP uses the most recent version of php5 as the default, you can add grep 'php5' in the middle:
PHP_VERSION= `ls /Applications/MAMP/bin/php/ | sort -n | grep 'php5' | tail -1`
and you are guaranteed to get the most recent php5 regardless of MAMP version.