PHP Installed and using MAMP but encountering "zsh: command not found: php" error
P粉875565683
P粉875565683 2023-11-09 09:34:56
0
1
734

I tried to install the Google client library using Composer, but I can't install Composer or use php on the command line.

I'm using php 8.0.8 with MAMP and it works fine so I know it's installed. If I type php in the terminal I get a command not found message. Thinking it might be an environment variable, I tried navigating to the php folder /Applications/MAMP/bin/php/php8.0.8/lib/php and tried the php command again, but still got the same error

I'm using a Mac running Monterey

P粉875565683
P粉875565683

reply all(1)
P粉007288593

Change the default Mac OS X PHP to MAMP's PHP installation and install Composer package management


Instructions for changing PHP installation


First, let's find out what version of PHP we're running (to know if it's the default version).

To do this, trigger this command within the terminal:

which php

This should output the Mac OS X pre-installed default PHP installation path, which by default must be (assuming you haven't changed it before):

/usr/bin/php

Now we just need to swap it to the PHP installed with MAMP, which is located at /Applications/MAMP/bin/php/php5.4.10/bin (MAMP 2.1.1) 3)

To do this, we need to edit .bash_profile and add the MAMP version of PHP to the PATH variable.

Please follow these simple steps:


  1. In the terminal, run vim ~/.bash_profile

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

    export PATH=/Applications/MAMP/bin/php/php5.4.10/bin:$PATH
  3. Press ESC, enter :wq, then press Enter

  4. In the terminal, run source ~/.bash_profile

  5. In the terminal, type which php again and look for the updated string. If everything was successful, it should output the new path to the MAMP PHP installation.

  6. If it doesn't output the correct path, try closing the terminal window (quit completely) and opening it again and it should apply the changes (restart for short).

Install Composer Package Management


Now you can trigger the command to install composer globally (so you can access it from anywhere):

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

You can verify that the installation works by typing the following command in the terminal:

composer

It will show you the current version and a list of commands you can use after successful installation.

Original source

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!