Overriding PHP Path for MAMP on macOS
As a result of encountering an issue with your PHP configuration, you seek to use the path to MAMP to execute PHP commands. However, manually typing the entire path is inconvenient.
To rectify this, follow these steps:
1. Create a .bash_profile File
Navigate to your home folder (e.g., /Users/David) and create a file named .bash_profile if it does not already exist. This file will contain environment variable exports.
2. Set the MAMP PHP Path Variable
Open .bash_profile in your preferred text editor (e.g., vim) and add the following lines:
export MAMP_PHP=/Applications/MAMP/bin/php/php5.3.6/bin
This will create an environment variable named MAMP_PHP that points to the path of your MAMP PHP installation.
3. Add the Variable to Your Path
Append the following line to .bash_profile:
export PATH="$MAMP_PHP:$PATH"
This line modifies the PATH environment variable to include the path of your MAMP PHP installation. Placing it before the system path ensures that your MAMP PHP version is prioritized.
4. Save and Reboot Terminal
Save the .bash_profile file and reboot your Terminal application.
5. Test the Override
Execute the following commands to verify that the override is successful:
php -v which php
The first command should display the version of your MAMP PHP installation, while the second should return the path to your MAMP PHP executable.
The above is the detailed content of How to Override PHP Path for MAMP on macOS?. For more information, please follow other related articles on the PHP Chinese website!