Set Up Yii2 Advanced Template in macOS using MAMP

 To set up the Yii2 Advanced Template in macOS using MAMP, install the project via Composer inside your MAMP htdocs directory and run the initialization script.

1. Start MAMP Services
  • Open MAMP from your Applications folder and click Start Servers.
  • Ensure Apache and MySQL are running (default local server uses port 8888 or 80 depending on your setup). [1]
2. Navigate to MAMP htdocs & Install Yii2 Advanced
Open your Terminal and navigate to the MAMP document root directory: [1]
bash
cd /Applications/MAMP/htdocs
Use code with caution.
Run the Composer command to create the Yii2 advanced project (replace yii-application with your preferred folder name): [1]
bash
composer create-project --prefer-dist yiisoft/yii2-app-advanced yii-application
Use code with caution.
3. Initialize the Application
Move into your newly created project folder: [1]
bash
cd yii-application
Use code with caution.
Run the initialization command to generate environment-specific configuration files: [1]
bash
php init
Use code with caution.
  • Type 0 for the Development environment.
  • Type yes to confirm overwriting or creating files. [1]
4. Configure the Database
  • Open common/config/main-local.php in your code editor.
  • Update the database credentials to match your MAMP MySQL settings (default username is root, password is root, and database name can be created via phpMyAdmin at http://localhost:8888/phpMyAdmin/): [1, 2]
php
'db' => [
    'class' => 'yii\db\Connection',
    'dsn' => 'mysql:host=localhost;dbname=your_database_name',
    'username' => 'root',
    'password' => 'root',
    'charset' => 'utf8',
],
Use code with caution.
5. Run Database Migrations
In your Terminal, run the migration command to populate essential tables (like the user table): [1, 2]
bash
php yii migrate
Use code with caution.
6. Access Your Application
The Yii2 advanced template separates the frontend and backend into distinct subdirectories under /frontend/web and /backend/web.
  • Frontend URL: http://localhost:8888/yii-application/frontend/web/
  • Backend URL: http://localhost:8888/yii-application/backend/web/
    (Adjust 8888 if your MAMP port is set to 80).
    [1]
If you'd like, let me know:
  • MAMP port configurations (Apache/Nginx ports)
  • Virtual Host setup preferences for cleaner URLs
I can guide you through setting up dedicated domains for frontend and backend.
  • YouTube·Uthpala Heenatigala
    Yii2 Lesson - 7 Installing the Advance Template in Yii

Post a Comment

0 Comments