Updated on February 14, 2016
Let's start by installing Composer for Windows. Download the installer and run it. Installer will ask you to locate php.exe. If you are using xampp, browse to :
and select the purple php file, that is php.exe. If you are using wamp, browse to :
and select purple php file. Note that in my wamp, I have php version "5.5.12", yours may be different, so just select the folder of your version instead.
Now we need to start using Command Prompt. Open your start menu and in search box type "cmd". Click on Command Prompt to run it.
Let's use Composer to install Composer asset plugin. "The Composer Asset Plugin allows you to manage project assets (css, js, etc.) in your composer.json without installing NPM or Bower." Copy -> paste the following command to your CMD, and execute it.
composer global require "fxp/composer-asset-plugin:~1.1.1"
During installation of this package, you may be asked to enter your GitHub username and password. If you do not have it, just create account there, it is free.
Now we can install Yii2 application templates. First we need to move to htdocs folder ( or www if you are using wamp ). Type this command in your command prompt and press enter:
Replace "htdocs" with "www" if you are using wamp. Now we can tell Composer to download and install yii2 basic template inside this folder. Execute this command:
composer create-project --prefer-dist yiisoft/yii2-app-basic
After download is complete you will see yii2-app-basic folder in your htdocs / www. You can open it in your text editor or IDE to work with it. If you want to start application in localhost to see what you got, start your xampp / wamp and visit this URL in your browser:
Now let's install advanced Yii2 template. Process of installing advanced template is a bit more complicated, but do not worry, I will show you everything.
In your command prompt move to htdocs / www folder again, and execute this command to install Yii2 advanced template there:
composer create-project --prefer-dist yiisoft/yii2-app-advanced
After download is complete we will have to initialize our application, create database and run yii migration to populate that database with boilerplate tables.
To initialize your application, first move inside the yii2-app-advanced folder. In your command prompt execute this command:
Now run the php init file with this command:
You will be asked to chose environment. Chose Development ( type "0" and press enter ) and then you will have to confirm your choice by typing "yes" and press enter again.
Now create database that you will use for this application. You can use any tool you like, for example "phpMyAdmin". Give it any name you want. Now we have to tell Yii to use this database. In your IDE or text editor open up the "main-local.php" configuration file. Path to this file is:
Inside this file you can set up your database credentials. Write your database name, username and password and save the file.
Inside your command prompt move to yii2-app-advanced folder again and execute this command:
Confirm migration by typing "yes" and press enter.
Now you are ready to start your application and see what you got. Advanced template is consisting from front-end and back-end sides. To start each of them, you can use these URLs:
Congratulations, now you can start developing some cool apps using yii2.
NOTE: if you want to use .htaccess to remove index.php entry script from your URLs, you may need to enable mod_rewrite and AllowOverride All in your Apache configuration. You can read Windows guide here.
Thanks for reading this tutorial, i hope it was useful to you. Cya next time.