Image Tutorial: How to setup Yii Framework on WAMP using MySQL database

I decides to move to Yii finally after comparing between different framework. At this point, although Yii documentation wasn’t as good as CI, it is not something that will restrict me from entering Yii framework. Like most people i started with the tutorial given on Yii website. Here is something i tried out today through the instruction given on the cookbook section. In this article, i will extend what is present in the article in a more visual form.

Requirement

Here are some of the basic requirement for this tutorial.

  1. Window XP (Vista and Win 7 will also work)
  2. Yii Framework 1.1.3
  3. WAMP 2.0i (Apache 2.2.11, PHP 5.3.0, MySQL 5.1.36, Phpmyadmin)
  4. Basic installation of WAMP (C:\wamp…)

Setting up yiic on WAMP

Firstly install your WAMP with the default installation.

wamp installation Image Tutorial: How to setup Yii Framework on WAMP using MySQL database

Once you have installed this, you should be ready to setup your computer local environment to use Yiic from Yii framework. Firstly, go to your environment variables located at Control Panel->System->Advance->Environment Variables->Path as shown below,

environment variables yii setup 541x400 Image Tutorial: How to setup Yii Framework on WAMP using MySQL database

Once you reached the path textbox, entered the following location to tell your windows that they are the environment variables.

  1. C:wampwwwyiiframework
  2. C:wampbinphpphp5.3.0

In this case, we are telling our window where is our yii framework yiic.bat and where is our php.exe as shown below,

wamp php location 533x400 Image Tutorial: How to setup Yii Framework on WAMP using MySQL database

since my WAMP is using php5.3.0, the folder shows the current version my WAMP is using. This might differ. Hence, change the directory path according to the php version you use. On the other hand, my yiic.bat is located at C:wampwwwyiiframework as shown below, hence, i pass this to the environment variable instead.

yiic bat location 533x400 Image Tutorial: How to setup Yii Framework on WAMP using MySQL database

Click ‘OK’ for all the settings you have made and restart you PC. Once your windows has rebooted, click start->run.. and type ‘cmd’. On the screen type “yiic webapp C:\wampwwwmywebsite” andtype ‘yes”. The folder should show up on your localhost.

install yii wamp 600x296 Image Tutorial: How to setup Yii Framework on WAMP using MySQL databasemywebsite 533x400 Image Tutorial: How to setup Yii Framework on WAMP using MySQL database

Now you need to change your setting from sqllite3 to MySQL. This is located at C:wampwwwmywebsiteprotectedconfigmain.php, open this file and replace the codes with the following.

<?php

// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');

// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
        'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
        'name'=>'My Web Application',

        // preloading 'log' component
        'preload'=>array('log'),

        // autoloading model and component classes
        'import'=>array(
                'application.models.*',
                'application.components.*',
        ),

        // application components
        'components'=>array(
                'user'=>array(
                        // enable cookie-based authentication
                        'allowAutoLogin'=>true,
                ),
                // uncomment the following to enable URLs in path-format
                /*
                'urlManager'=>array(
                        'urlFormat'=>'path',
                        'rules'=>array(
                                '<controller:w+>/<id:d+>'=>'<controller>/view',
                                '<controller:w+>/<action:w+>/<id:d+>'=>'<controller>/<action>',
                                '<controller:w+>/<action:w+>'=>'<controller>/<action>',
                        ),
                ),
                */
                'db'=>array(
                        'connectionString' => 'mysql',
                ),
                // uncomment the following to use a MySQL database

                'db'=>array(
                        'connectionString' => 'mysql:host=localhost;dbname=yourdatabasename',
                        'emulatePrepare' => true,
                        'username' => 'root',
                        'password' => '',
                        'charset' => 'utf8',
                ),

                'errorHandler'=>array(
                        // use 'site/error' action to display errors
            'errorAction'=>'site/error',
        ),
                'log'=>array(
                        'class'=>'CLogRouter',
                        'routes'=>array(
                                array(
                                        'class'=>'CFileLogRoute',
                                        'levels'=>'error, warning',
                                ),
                                // uncomment the following to show log messages on web pages
                                /*
                                array(
                                        'class'=>'CWebLogRoute',
                                ),
                                */
                        ),
                ),
        ),

        // application-level parameters that can be accessed
        // using Yii::app()->params['paramName']
        'params'=>array(
                // this is used in contact page
                'adminEmail'=>'webmaster@example.com',
        ),
);

Change ‘yourdatabasename’ in the text above to your database name and you’r done!

 

Like this post? Share it!

digg 48 Image Tutorial: How to setup Yii Framework on WAMP using MySQL database reddit 48 Image Tutorial: How to setup Yii Framework on WAMP using MySQL database stumbleupon 48 Image Tutorial: How to setup Yii Framework on WAMP using MySQL database delicious 48 Image Tutorial: How to setup Yii Framework on WAMP using MySQL database furl 48 Image Tutorial: How to setup Yii Framework on WAMP using MySQL database technorati 48 Image Tutorial: How to setup Yii Framework on WAMP using MySQL database google 48 Image Tutorial: How to setup Yii Framework on WAMP using MySQL database myspace 48 Image Tutorial: How to setup Yii Framework on WAMP using MySQL database facebook 48 Image Tutorial: How to setup Yii Framework on WAMP using MySQL database twitter 48 Image Tutorial: How to setup Yii Framework on WAMP using MySQL database
share save 171 16 Image Tutorial: How to setup Yii Framework on WAMP using MySQL database

No related posts.

About Clay

I am Clay who is the main writer for this website. I own a small web hosting company in Malaysia and i'm available to be hired as individual contractor on elance. You can find me on twitter.
This entry was posted in How-to, Yii and tagged . Bookmark the permalink.

One Response to Image Tutorial: How to setup Yii Framework on WAMP using MySQL database

  1. Pingback: Customize Authentication On Yii Framework Using MySQL Database - Hungred Dot Com