29

I have installed XAMPP on Mac OSX running Yosemite I have created the .bash_profile file like this:

export XAMPP_HOME=/Applications/XAMPP/xamppfiles
export PATH=${XAMPP_HOME}/bin/php:${PATH}
export PATH

When I type echo $PATH in terminal, I get correct XAMPP path But when I type "which php" it shows /usr/bin/php

How can I make my XAMPP use the correct php instead of default php that came with mac?

ssdesign
  • 2,743
  • 6
  • 37
  • 53

5 Answers5

101

To use the XAMPP PHP and other binaries found in /Applications/XAMPP/bin/ add the following to the appropriate ~/.zshrc or ~/.bash_profile file depending on your default shell (see note below).

export XAMPP_HOME=/Applications/XAMPP
export PATH=${XAMPP_HOME}/bin:${PATH}
export PATH

Reload the current login shell to apply the changes (won't be needed next time you open a shell session):

$ exec $SHELL -l;

Confirm:

$ which php
/Applications/XAMPP/bin/php

Note: zsh vs bash

Since MacOS Catalina (v10.15, released 2019), the default shell is zsh rather than bash. To find your current shell, open Terminal and type:

$ echo $SHELL

The output will most likely be either /bin/zsh or /bin/bash unless you changed to another shell at some time.

Follow the instructions above and if using zsh then add the required lines to ~/.zshrc and if using bash then add them to ~/.bash_profile

BlueC
  • 1,472
  • 1
  • 10
  • 13
  • Thanks, solved my problem...!! earlier i was not loading bash_profile using 'source ~/.bash_profile' – VipinKundal Nov 17 '16 at 11:55
  • 1
    What's the correct path to XAMPP's php in the latest version (7)? It is quite different – molerat Aug 10 '17 at 19:36
  • launching next terminal, which php return old path – Irfan Ul Haq Jul 05 '18 at 22:08
  • Do you found any solution for this issue that lunching next terminal return old path?? @rfan-ul-haq – Farid Vatani Jun 16 '20 at 15:46
  • I have installed xampp 8.0 in macbook. It was installed at "/Users/kamlesh/.bitnami/stackman/machines/xampp/volumes/root/htdocs/". It is working in the browser. xampp 8.0 has php 8 and I want to set its path in bash_profile file so that when i use php -v command in terminal then it should show php 8.0 version. I have set strings in bash_profile as, but not working yet, any suggestion: export XAMPP_HOME=/Users/kamlesh/.bitnami/stackman/machines/xampp/volumes/root export PATH=${XAMPP_HOME}/bin:${PATH} export PATH – Kamlesh Apr 23 '21 at 19:28
16

In My case I did the following

I created my bash profile.

sudo nano ~/.bash_profile

And then added the following to it

export PATH=/Applications/XAMPP/xamppfiles/bin:$PATH
export PATH

And then refreshed my path source ~/.bash_profile Or if that doesn't work you can close the terminal completely and start a new session.

Enter which php And you would see your new php path, in my case /Applications/XAMPP/xamppfiles/bin If you know what php version you installed, you can also check by entering php -v in my case it output the following.

PHP 5.6.14 (cli) (built: Nov 19 2015 20:37:15) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies.

Amir
  • 8,821
  • 7
  • 44
  • 48
Daniel Barde
  • 2,603
  • 5
  • 31
  • 40
10

Finally I Solve the Problem. I set the Following Config in my "~/.bash_profile"

If u have a bash_profile U need to Edit otherWise create bash_profile. Then Add these lines 1st

export PATH=/Applications/XAMPP/xamppfiles/bin:$PATH
export PATH

Above is the Xampp path. Next Add The Composer Path(IF U ADD THE COMPOSER PATH 1st IT WON'T WORK)

export PATH="~/.composer/vendor/bin:$PATH"

Finally Working Fine for Me.

which php
/Applications/XAMPP/xamppfiles/bin/php
Bala Murugan
  • 479
  • 5
  • 10
  • I have installed xampp 8.0 version in mac but there no Xampp directory in Applications directory. Kindly suggest how can we set php path for Xampp 8.0 version in Mac. Thanks a lot. – Kamlesh Apr 24 '21 at 05:27
  • it works but after restart again shows older version – Hemant Maurya Jul 28 '21 at 21:05
-1

I managed to solve the problem. On the Mac, the XAMPP bin folder and the php file had the wrong permission, hence it was not working. Secondly, I also had to profile the full path

/bin/php-5.5.15:${PATH}

Thanks

ssdesign
  • 2,743
  • 6
  • 37
  • 53
  • If this solved your problem and you are happy with the answer, please accept this answer (so it does not appear in the unanswered questions list) – David Newcomb Oct 22 '15 at 14:03
-1

1.Open terminal

2.Run:

echo "$SHELL"

3.if result is "/bin/zsh", Run:

sudo nano ~/.zshrc

else Run:

sudo nano ~/.bash_profile

and enter your devices password

4.add theese lines to the end of the file:

export XAMPP_HOME=/Applications/XAMPP/xamppfiles
export PATH=${XAMPP_HOME}/bin/php:${PATH}
export PATH

5.then control+X and enter twice

6.restart

nasim jahednia
  • 165
  • 1
  • 8
  • Please explain the value that your advice adds to this page. As a reader who is not an expert in this subject matter, it would help me to decide if I should use your advice if you explain how it differs from earlier answers. – mickmackusa Apr 03 '23 at 08:37