Skip to content

Instantly share code, notes, and snippets.

@djandyr
Last active July 19, 2026 17:58
Show Gist options
  • Select an option

  • Save djandyr/c04950a1375e96814316 to your computer and use it in GitHub Desktop.

Select an option

Save djandyr/c04950a1375e96814316 to your computer and use it in GitHub Desktop.
MacOS XAMPP PHP Installation

Change default Mac OS X PHP to XAMPP's PHP Installation and Install Composer


Find out what version of PHP is running

which php

This will output the path to the default PHP install which comes preinstalled by Mac OS X, by default

/usr/bin/php

Now, we just need to swap this over to the PHP that is installed with XAMPP, which is located at /Applications/XAMPP/bin

1.vim ~/.bash_profile

  1. Type i and then paste the following at the top of the file:

     export PATH=/Applications/XAMPP/bin:$PATH
    
  2. Hit ESC, Type :wq, and hit Enter

  3. In Terminal, run source ~/.bash_profile

  4. In Terminal, type in which php again and look for the updated string. If everything was successful, It should output the new path to XAMPP PHP install.

Install Composer


Now you can fire the command to install the composer:

curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin

After the download & installation is done, You can add this alias to your .bash_profile or .profile file to get composer to work globally instead of php /usr/bin/composer.phar command.

alias composer="php /usr/bin/composer.phar"

You can verify your installation worked by typing the following command within the Terminal:

composer
@f0X231

f0X231 commented May 16, 2019

Copy link
Copy Markdown

@hadiAugmedix

Copy link
Copy Markdown

use /usr/local/bin

So the command will be

curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin

So alias will be

alias composer="php /usr/local/bin/composer.phar"

@awesome-urch

awesome-urch commented Apr 22, 2021

Copy link
Copy Markdown

After running
echo $PATH
I get this:
/Applications/XAMPP/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Is it okay?

Because I still get
/usr/bin/php
after running
which php

Please help me

@deborahtrez

Copy link
Copy Markdown

What is the use of installing Composer?

@cesar4rroyo

Copy link
Copy Markdown

Works for me, thank you!

@thant-htoo-aung

Copy link
Copy Markdown

I did all the above steps but I am still getting /usr/bin/php. I just want to change xampp PHP as default php.

@Apisathan

Apisathan commented Nov 10, 2021

Copy link
Copy Markdown

^ If anyone runs into the same error where /usr/local/bin is not writable run:

sudo chown -R `whoami`:admin /usr/local/bin

@Adrian-Wiszowaty

Copy link
Copy Markdown

First of all, thanks for the great tutorial.
Second, has anyone had the same problem and managed to solve it?
After restarting the computer, the PHP default settings seem to be cleared.
After booting, I have to enter source ~ / .bash_profile to get PHP setup from XAMP.

@djandyr

djandyr commented Feb 3, 2022

Copy link
Copy Markdown
Author

@Adrian-Wiszowaty It's likely your default shell is Z Shell (zsh) since macOS Catalina. You will need to edit, and source ~/.zshrc instead to persist on reboot

Can check your current shell, using;

echo $0

@Adrian-Wiszowaty

Copy link
Copy Markdown

THX!

@MatheusFarias03

MatheusFarias03 commented Apr 23, 2022

Copy link
Copy Markdown

Ok, so for the ones whose shell is Z Shell (zsh) and are having issues with composer working globally:

  • After installing composer I could not move it or make an alias through the /usr/local/bin directory.
  • To do so, type php composer.phar -n config --global home in the terminal to find where it is located.
  • Create the alias alias composer="php (directory you found)composer.phar".
  • To save multiple lines in the ~/.zshrc type esc and then :w(write) and finally :x (exit). For the alias to work, restart the terminal.

This is what worked for me, hope it works for the ones who are having the same problem.

@bantustic

bantustic commented May 18, 2022

Copy link
Copy Markdown

ok all above was useful but could not get rid of;All settings good but /usr/local/bin not writable

ok mine on high sierra went like this;
for: curl -s https://getcomposer.org/installer | php (result:All settings good but /usr/local/bin not writable)
so decided to make the folder if none existent: [ -e /usr/local/bin ] || sudo mkdir -p /usr/local/bin
then own the created folder: sudo chown -R whoami:admin /usr/local/bin
And again ran: curl -s https://getcomposer.org/installer | php (There were no:/usr/local/bin not writable issues - this time)
then moved on to: mv composer.phar /usr/local/bin/composer.phar
and: alias composer='/usr/local/bin/composer.phar'
and wala: composer --version
Composer version 2.2.12 2022-04-13 16:42:25

@prondubuisi

Copy link
Copy Markdown

If your change doesn’t persist when you restart or open a new terminal window then you are most likely using zsh as @djandyr mentioned , do

  1. vim ~/.zshrc

  2. Type i and then paste the following at the top of the file:

  3. export PATH=/Applications/XAMPP/bin:$PATH

  4. Hit ESC, Type :wq, and hit Enter

  5. In terminal, run source ~/.zshrc

  6. In same terminal, new terminal or system restart type in which php again and look for the updated string. If everything was successful, It should output the new path to XAMPP PHP install.

Just rephrasing @djandyr with the ~/.zshrc alternative

@AnnaigJegourel

Copy link
Copy Markdown

Very useful, thanks a lot ! I installed Composer with Homebrew ("brew install composer"), it's even easier and seems to work perfectly.

@monjuindonesia

Copy link
Copy Markdown

it Works for me! Thank you!

@akash-magar-dev

Copy link
Copy Markdown

Thanks worked for me aswell

can you also explain why below solution is not working
https://codewithsusan.com/notes/path-variable-mac

@dgr8abr

dgr8abr commented Jun 3, 2024

Copy link
Copy Markdown

thanks for this, when i type :

$ which php

/Applications/XAMPP/bin/php

it will show that but when i open a duplicated terminal , it
will show mbam1@192 config % which php
php not found

thanks for this @akash-magar-dev , helped me a lot.

@fivelow

fivelow commented Jul 19, 2026

Copy link
Copy Markdown

Nothing changed. Even after a reboot. It's still /usr/local/bin/php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment