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
8888or80depending on your setup). [1]
2. Navigate to MAMP
htdocs & Install Yii2 AdvancedOpen 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
0for the Development environment. - Type
yesto confirm overwriting or creating files. [1]
4. Configure the Database
- Open
common/config/main-local.phpin your code editor.
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
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/
(Adjust8888if your MAMP port is set to80). [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.
0 Comments