How to Install Yii2 Advanced via Composer

10 April 2021

Home » Blogs » Technology » How to Install Yii2 Advanced via Composer

The main reason for migrating to Advanced Template is for the implementation of user management features such as listing, login, exit, and password reset.

Yii2 Advanced Template also has front-end and back-end web applications for end-users and administrators. However, this can also be expanded—for example for dedicated moderators or APIs, although there are other ways to integrate these features in a single app.

Here is a chart showing the main differences between basic and advanced:

FeaturedBasicAdvanced
Project structure
Site controller
User login/logout
Forms
DB connection
Console command
Asset bundle
Codeception tests
Twitter Bootstrap
Front- and back-end apps
Ready to use User model
User signup and password restore

To start the installation advanced template requires a web server that supports PHP version +5.4.0. For this article, we will use XAMPP as a webserver. Since we’re going to use , make sure you’ve installed . If not, you can download it here.

TOP TUTORIALS:  How to Run High Priority Apps on Windows

In this example:

  • XAMPP installed on C:\xampp
  • Yii2 Advanced installed on D:\xampp\htdocs\yii2-test

Install Yii2 Advanced Templated via Composer

Open command prompt () change to htdocs directory. For example “cd C:\xampp\htdocs”, then you can install the yii2 using the following command:

composer global require "fxp/composer-asset-plugin:~1.1.1"
composer create-project --prefer-dist yiisoft/yii2-app-advanced yii-application

The first command installs the asset plugin that allows the management of bower and npm package dependencies through . You only need to execute this command once for all. The second command installs the advanced yii2 in a directory called yii-application. You can choose a different directory name if you want. Since we’re going to install it in the yii2-test directory then we change the command to

composer create-project --prefer-dist yiisoft/yii2-app-advanced yii2-test

Initialization of Yii2

After you install the , you must perform the following steps to initialize the installed . You only have to do this once.

  1. Open the yii2 installation folder. For example “C:\xampp\htdocs\yii2-test”, then look for a file with the name “init.bat”. Open the “init.bat” file and select [0] “Development”.
  2. Create a new database and customize the Components configuration [‘db’] in “common/config/main-local.php”. The database name, user and password must be appropriate.
  3. Open , change it to yii2 installation directory. For example “cd C:\xampp\htdocs\yii2-test”, then type the command
yii migrate
  1. Open the configuration file “C:\xampp\\conf\extra\httpd-vhosts.conf” with notepad. Add it to the last line
    
        ServerName frontend.bardimin
		#sesuaikan with yii directories created
        DocumentRoot "C:/xampp/htdocs/yii2-test/frontend/web/"
           
        
            RewriteEngine on
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule . index.php
            DirectoryIndex index.php
        
    
       
    
        ServerName backend.bardimin
		#sesuaikan with yii directories created
        DocumentRoot "C:/xampp/htdocs/yii2-test/backend/web/"
           
        
            RewriteEngine on
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule . index.php
            DirectoryIndex index.php
        
    
  1. Then edit the hosts file on “C:\Windows\System32\\etc\hosts” with notepad and add it to the last line
#match with ServerName in step 4
127.0.0.1 frontend.bardimin
127.0.0.1 backend.bardimin
  1. Restart apache. To access the results from the type the url address as follows:
    – frontend: http://frontend.bardimin/
    – backend: http://backend.bardimin/
  2. To sign in to the app, you’ll need to register first, with your email address, username, and password. Then, you can log into the app with the same email address and password at any time.
TOP TUTORIALS:  File Sharing between Hyper-V Host and Guest

0 Comments