Install PHP with brew
It would install the most recent PHP version, just open your terminal and type this command:
brew install php
If you does not have installed Brew, you can check the previous article from this series.
Install composer
You can go to the official page and get the installation commands always updated here, but I will add it in this article updated at the current date.
Open your terminal and paste this commands (all at once):
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
Then you can verify that the composer.phar file is working by typing in your terminal:
php composer.phar
and you should be able to see that there is an output with the list of composer commands and flags.
Add composer globally
You must need to move the composer path to /usr/local/bin
directory, in MontereyOS or any other MacOS newer than HighSierraOS you need to create this directory manually:
sudo mkdir -p /usr/local/bin
If it throws an error like /usr/local/bin is not a directory
, just remove the bin file and try again:
sudo rm -rf /usr/local/bin
sudo mkdir -p /usr/local/bin
Now you are able to move the composer.phar
file to that directory with this command:
sudo mv composer.phar /usr/local/bin/composer
Set the composer path
Write this command:
PATH=$PATH:~/.composer/vendor/bin
Test your composer installation
Now you can test that everything works fine and just type in your terminal:
composer
and you should be able to see that there is an output with the list of composer commands and flags.
Top comments (1)
Thanks, very usefull!