January 25, 2016

How to Install Yii2 framework on Windows with XAMPP

In this post, I will explain how to install Yii2 framework on Windows, with XAMPP as PHP development environment.
First you have to install XAMPP you can find here: XAMPP Installer
You can install Yii2 framework by two ways:
  • Install Using Composer
  • Install Manually

Install Using Composer

The recommended approach is to install Yii2 framework using composer, because it will automatically install and configures all the required plugins and packages. You can download composer from https://getcomposer.org/download/. Composer setup will ask for PHP installation path, in my XAMPP installation it is:
D:\xampp\php\php.exe

You can verify if composer is correctly installed, by executing the command composer in command prompt. If you get an error message, it means it is not added in the Environment Variables, so you have to add the composer.exe folder path in Environment Variables.

composer

Next step is to install Composer assets plugin by executing the following command from command prompt:

composer global require "fxp/composer-asset-plugin:~1.1.1"

composer-asset-plugin

 
During installation of asset plugin, it will ask you for Github login credentials, because composer need to get API rate-limit to retrieve the dependent pacackges information from Github, you can find more information on this from Composer Documentation

Here we finished installing composer, and now we have to install Yii2. Move to a web-accessible folder, the folder where we usually place all web projects. In my XAMPP installation it is D:\xampp\htdocs
Now go to command prompt, move to the above mentioned web-accessible folder, and execute following command:
composer create-project --prefer-dist yiisoft/yii2-app-basic basic

composer-yii2-basic-project

 
It will install Yii2 framework to a folder named basic inside the htdocs folder, you can use your own project name in place of basic(last part in the above command). Then composer will download and configure all the required packages, and finally your Yii2 basic application is now ready. You can try access it by localhost path:
http://localhost/basic/web

Install Manually

Manuall Installation of Yii involves three steps:
  1. Download the archive file from yiiframework.com.
  2. Unpack the downloaded file to a Web-accessible folder, in our example it is D:\xampp\htdocs\basic
  3. Modify the config/web.php file by setting a secret key for the cookieValidationKey configuration item (this is done automatically if you are installing Yii using Composer):
        'cookieValidationKey' => 'enter your secret key here',
    

Thats it, you can access this new basic application by following url:
http://localhost/basic/web

You should see the following "Congratulations!" page in your browser.

yii-basic

If you did not see this page, please check if your PHP installation satisfies Yii's requirements. Just copy /requirements.php to /web/requirements.php and then access it via http://localhost/requirements.php. If you PHP development environment is properly configured, you should see the output similar to this:

yii-requirements


You should configure your PHP installation so that it meets the minimum requirements of Yii. Most importantly, you should have PHP 5.4 or above.

References

http://www.yiiframework.com/doc-2.0/guide-start-installation.html



11 comments:

  1. Nice post. I was checking continuously this blog and I am impressed! Very helpful information specially the last part
    Hire Yii Framework Developers in India

    ReplyDelete
  2. Nice Blog!
    Thanks you very much for sharing valuable information.
    Keep on posting...

    Biofit ingredients

    ReplyDelete
  3. I am very glad when I read this blog post
    Thanks for sharing valuable information.
    Keep on posting...
    Calf Sleeves Benefits
    High Waist Tummy Control Panties
    High Neck Tank Top
    Compression Sleeve For Arm

    ReplyDelete
  4. Thanks for sharing this informative article about How to Install Yii2 framework on Windows with XAMPP with useful screenshots. PHP has many framework and one of them is YII. If you have any requirement to Hire Yii Developers for your project. Please visit us.

    ReplyDelete