How to Install Yii2 Advanced via Composer

The main reason for migrating to Yii2 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 Yii2 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 yii2 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 composer, make sure you’ve installed composer. If not, you can download it here.

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 (CMD) change to htdocs directory. For example “cd C:\xampp\htdocs”, then you can install the yii2 application 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 composer asset plugin that allows the management of bower and npm package dependencies through Composer. You only need to execute this command once for all. The second command installs the advanced yii2 application 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 application, you must perform the following steps to initialize the installed application. You only have to do this once.

  1. Open the yii2 installation folder. For example “C:xampphtdocsyii2-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 CMD, change it to yii2 installation directory. For example “cd C:\xampp\htdocs\yii2-test”, then type the command
yii migrate
  1. Open the apache configuration file “C:\xampp\apache\conf\extra\httpd-vhosts.conf” with notepad. Add it to the last line
    <VirtualHost *:80="">
        ServerName frontend.bardimin
		#sesuaikan with yii directories created
        DocumentRoot "C:/xampp/htdocs/yii2-test/frontend/web/"
           
        <Directory "c:/xampp/htdocs/yii2-test/frontend/web/"="">
            RewriteEngine on
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule . index.php
            DirectoryIndex index.php
        </Directory>
    </VirtualHost>
       
    <VirtualHost *:80="">
        ServerName backend.bardimin
		#sesuaikan with yii directories created
        DocumentRoot "C:/xampp/htdocs/yii2-test/backend/web/"
           
        <Directory "c:/xampp/htdocs/yii2-test/backend/web"="">
            RewriteEngine on
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule . index.php
            DirectoryIndex index.php
        </Directory>
    </VirtualHost>
  1. Then edit the hosts file on “C:\Windows\System32\drivers\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 browser 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.

RELATED ARTICLES

Latest Articles