To install Yii2 in macOS using MAMP, configure your PHP path for the terminal, download the project via Composer into your MAMP document root, and run it.
Step 1: Start MAMP and Configure PHP Path
- Open MAMP and click Start Servers.
- Note your MAMP PHP version (e.g.,
8.x.x). - Open your Mac Terminal and add MAMP's PHP binary to your shell path so Composer can use MAMP's PHP engine:(Replacebash
export PATH=/Applications/MAMP/bin/php/php8.x.x/bin:$PATHUse code with caution.php8.x.xwith your exact MAMP PHP folder name found in/Applications/MAMP/bin/php/). - Verify the PHP version matches MAMP: [1]bash
php -vUse code with caution.
Step 2: Install Composer (If Not Installed)
If you do not have Composer installed globally, run these commands in Terminal: [1]
bash
curl -s https://getcomposer.org | php
sudo mv composer.phar /usr/local/bin/composer
Use code with caution.
Step 3: Install Yii2 in MAMP
htdocs- Navigate to your MAMP server root directory (
htdocs): [1]bashcd /Applications/MAMP/htdocsUse code with caution. - Run the Composer command to create a Yii2 basic project (name your project folder, e.g.,
my-yii-app): [1]bashcomposer create-project --prefer-dist yiisoft/yii2-app-basic my-yii-appUse code with caution. - Wait for Composer to download all dependencies and generate the project files.
Step 4: Access Your Yii2 Application
- Ensure your MAMP Apache and MySQL servers are running.
(Note: Yii2 points its entry script to the
web subdirectory for security reasons). [1]If you want, I can share how to:
- Configure a virtual host in MAMP to remove
/web/from the URL - Connect Yii2 to a MAMP MySQL database
Let me know what you'd like to do next.
0 Comments