Install Yii2 in macOS using MAMP

 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
  1. Open MAMP and click Start Servers.
  2. Note your MAMP PHP version (e.g., 8.x.x).
  3. Open your Mac Terminal and add MAMP's PHP binary to your shell path so Composer can use MAMP's PHP engine:
    bash
    export PATH=/Applications/MAMP/bin/php/php8.x.x/bin:$PATH
    
    Use code with caution.
    (Replace php8.x.x with your exact MAMP PHP folder name found in /Applications/MAMP/bin/php/).
  4. Verify the PHP version matches MAMP: [1]
    bash
    php -v
    
    Use 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
  1. Navigate to your MAMP server root directory (htdocs): [1]
    bash
    cd /Applications/MAMP/htdocs
    
    Use code with caution.
  2. Run the Composer command to create a Yii2 basic project (name your project folder, e.g., my-yii-app): [1]
    bash
    composer create-project --prefer-dist yiisoft/yii2-app-basic my-yii-app
    
    Use code with caution.
  3. Wait for Composer to download all dependencies and generate the project files.
Step 4: Access Your Yii2 Application
  1. Ensure your MAMP Apache and MySQL servers are running.
  2. Open your web browser and go to the project URL using MAMP's default port (8888): [1, 2]
    text
    http://localhost:8888/my-yii-app/web/
    
    Use code with caution.
(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.

Post a Comment

0 Comments