Our Work

Yii Install with and Without composer

Updated 2 years, 5 months and 7 days ago

 

YII PHP Framework 1.0 and 2.0 installation on Ubuntu or Linux

If you are coding PHP applications chances are you might have used this Yii PHP Framework or thought about using it. One of the best PHP framework currently in the market.

 What Makes Yii Special?

  •     Speed, Performance and Scalability
  •     Simplicity of the code
  •     Framework influenced heavily from Ruby on Rails, especially DRY(Don't Repeat Yourselves Principle.
  •     Tons of Free MIT Licensed extensions
  •     Lot of Enterprise companies have adopted YII because of its simplicity and popularity among developers. 
  •     Lot of companies have use YII framework to build SaaS/Cloud applications 
  •     Lots of YII Open Source Projects are written/Re-Written using YII Framework. 

YII 1.0 install without composer : -

Step 1 : 
wget http://yii.googlecode.com/files/yii-1.1.13.e9e4a0.zip
unzip yii-1.1.13.e9e4a0.zip
sudo apt-get install unzip
yii_framework:

Step 2 : 
mv yii-1.1.13.e9e4a0 yii_framework
Make sure you replace the folder name with the name of the extracted folder for your case.

Step 3 : 
Creating your First Application

cd /var/www

php yii_framework/framework/yiic webapp mysite

Make sure the path corresponds to your environment. Select Yes when you are prompted and now you have your new application under /var/www/mysite.
To test it out, point your browser to that folder:
http://example.com/mysite/index.php
 
You should now see the homepage of your skeleton application. You have a couple of pages already created as well as a contact form and login/logout functionality. You can login with the following credentials:

    username: admin

    password: admin

This is functionality you don’t need to create yourself.

YII 1.0 install with composer : -

Prerequisites

    Install Yii

    Install Composer


Step 1 : 
wget http://yii.googlecode.com/files/yii-1.1.13.e9e4a0.zip
unzip yii-1.1.13.e9e4a0.zip
sudo apt-get install unzip

yii_framework:

Step 2 : 
mv yii-1.1.13.e9e4a0 yii_framework
Make sure you replace the folder name with the name of the extracted folder for your case.

Step 3 : 
Creating your First Application

cd /var/www

Run command to generate a new application:

php yii_framework/framework/yiic webapp mysite
Create a file protected/composer.json and insert the following content:

{
    "name": "myvendor/myapp",
    "require": {
        "php": ">=5.1.0",
        "yiisoft/yii": "1.1.*"
    }}

    Open folder protected and run command to install dependencies:

composer install

    Open index.php and replace the following:

//$yii=dirname(__FILE__).'/../framework/yii.php';$yii=dirname(__FILE__).'/protected/vendor/yiisoft/yii/framework/yii.php';

    Done!

Make sure the path corresponds to your environment. Select Yes when you are prompted and now you have your new application under /var/www/mysite.
To test it out, point your browser to that folder:

http://example.com/mysite/index.php
You should now see the homepage of your skeleton application. You have a couple of pages already created as well as a contact form and login/logout functionality. You can login with the following credentials:

    username: admin

    password: admin

Yii2 Basic with composer : -

Now we are ready to install Composer, and we will install it globally. First, let's download the composer. Copy-paste this command and execute it:
 
curl -sS https://getcomposer.org/installer | php

 
Now let's install it globally:
 
sudo mv composer.phar /usr/local/bin/composer

 
Now every time you need to use composer you just write "composer 'some command' " in your terminal.

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 terminal, 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.

Finally, we are ready to install yii2 basic and advanced templates. Move to your localhost web root folder. If you are using lampp you can move with this command :
 
cd /var/www

 

To install basic template execute this command:
 
composer create-project --prefer-dist yiisoft/yii2-app-basic

 
As you can see we are using composer to download yii2 basic application. After the download is complete you can rename the downloaded folder to something you like, I will be generic and rename it to "basic".
Now if you start your lampp, you can start your basic Yii2 application by simply visiting this URL in your browser:
 
localhost/basic/web/  - access the links

    Yii2  without composer : -

Installation without composer means Installing Yii from an archive file whics involves three steps:
    

    Download the archive file from yiiframework.com.

    Unpack the downloaded file to a Web-accessible folder.

    Modify the config/web.php file by entering a secret key for the cookieValidationKey configuration item (this is done automatically if you are installing Yii using Composer)

Related Posts