macoscomposer-phpzsh

Composer alias not working on MacOS - command not found: php


I'm migrating from Windows to Mac but can't setup my working environment for php development. I've installed Xampp on MacOS and now trying to install composer but the alias is not working at all. First, I added php to the path

sudo nano ~/.zshrc

Added this to file and save

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

PHP is now working

source ~/.zshrc
php -v
PHP 8.2.4 (cli) (built: Apr  6 2023 04:12:41) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.4, Copyright (c) Zend Technologies

Next I downloaded and installed composer as their website instructs. Moved composer to /usr/local/bin/composer. I can now execute this command

php /usr/local/bin/composer/composer.phar -V
Composer version 2.8.2 2024-10-29 16:12:11
PHP version 8.2.4 (/Applications/XAMPP/xamppfiles/bin/php-8.2.4)
Run the "diagnose" command to get more detailed diagnostics output.

Next I tried to create an alias for composer by editing the zshrc file again. It now looks like this

export PATH=$PATH:/Applications/XAMPP/xamppfiles/bin
alias composer=”php /usr/local/bin/composer/composer.phar”

Now I try this command and it fails

source ~/.zshrc
composer -V                                 
zsh: command not found: ”php

Solution

  • Your understanding of alias is correct. It looks like it's comes from the ” character instead of "

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

    this is why you got

    zsh: command not found: ”php

    and not

    zsh: command not found: php

    Maybe try like this:

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