Skip to content

Instantly share code, notes, and snippets.

@djandyr
Last active November 5, 2024 13:26
Show Gist options
  • Save djandyr/c04950a1375e96814316 to your computer and use it in GitHub Desktop.
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
@prondubuisi
Copy link

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

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

it Works for me! Thank you!

@akash-magar-dev
Copy link

Thanks worked for me aswell

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

@dgr8abr
Copy link

dgr8abr commented Jun 3, 2024

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.

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