DEV Community

Ariel Mejia
Ariel Mejia

Posted on

Install PHP and Composer in MontereyOS

Install PHP with brew

It would install the most recent PHP version, just open your terminal and type this command:

brew install php
Enter fullscreen mode Exit fullscreen mode

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');"
Enter fullscreen mode Exit fullscreen mode

Then you can verify that the composer.phar file is working by typing in your terminal:

php composer.phar
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Now you are able to move the composer.phar file to that directory with this command:

sudo mv composer.phar /usr/local/bin/composer
Enter fullscreen mode Exit fullscreen mode

Set the composer path

Write this command:

PATH=$PATH:~/.composer/vendor/bin
Enter fullscreen mode Exit fullscreen mode

Test your composer installation

Now you can test that everything works fine and just type in your terminal:

composer
Enter fullscreen mode Exit fullscreen mode

and you should be able to see that there is an output with the list of composer commands and flags.

Top comments (1)

Collapse
 
chantal_ouellet_6e26c1077 profile image
Chantal Ouellet

Thanks, very usefull!