Saturday, 27 August 2016

How to install Yii2 in ubuntu.

There are two templates available for yii2 while installing. Choose according to your need if you need a simple application without backend module than basic will be good enough . But for whole functionality advanced application will be used.

Basic Application Template – a basic frontend application template.
Advanced Application Template – consisting of a frontend, a backend, console resources, common (shared code), and support for environments.

Yii2 Requirements:
PHP >= 5.4
Some of packages installed :- curl, openssl, mcrypt etc.

Before running the composer command . first we need to install lates update and upgrade of your machine server.

sudo apt-get update
sudo apt-get upgrade

Assuming that PHP , apache , mysql are already installed. If not installed than install the LAMP stack.

Installing Composer:
While running the composer token will be needed for processing. Then create GitHub personal API token.

# installing composer
curl -sS | php
# move composer globally
sudo mv composer.phar /usr/local/bin/composer
# check composer working

Download the repo  unzip it.

Run these commands to install dependency globally.

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 which allows managing bower and npm package dependencies through Composer. You only need to run this command once for all. The second command installs the advanced application in a directory named yii-application. You can choose a different directory name if you want.

1. Open a console terminal, execute the init command and select dev as environment.
php init

2. Create a new database and adjust the components['db'] configuration in common/config/main-local.php accordingly.

3. Open Console and run the migration command. ./yii migrate

4. Final step for /path/to/yii-application/frontend/web/ and using the URL http://frontend.local/

5. for apache set sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/yiiapp.conf.

sudo gedit /etc/apache2/sites-available/yiiapp.conf

<VirtualHost *:80>
    ServerName frontend.local
    ServerAlias frontend.local
    DocumentRoot /var/www/html/yiiapp/frontend/web
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined


6. Enabled the virtual host:
sudo a2ensite yiiapp.conf

7. Restart your apache server.
sudo service apache2 restart

8. Final make a host entry
sudo nano /etc/hosts   frontend.local

Now test your application at http://frontend.local. You can see a offical installation steps here link here.

Featured post

How to create dynamic schema in mongodb

Sometime what we need in our application is to create mongodb schema for collection and some of our collection schema are same but names are...

Popular Posts