Saturday, January 8, 2011

How to setup Yii Framework on WAMP using MySQL database

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.



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,

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:\wamp\www\yii\framework
2. C:\wamp\bin\php\php5.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,

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:\wamp\www\yii\framework as shown below, hence, i pass this to the environment variable instead.

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:\\wamp\www\mywebsite” andtype ‘yes”. The folder should show up on your localhost.

How to setup Yii Framework on WAMP using MySQL databasemywebsite
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:\wamp\www\mywebsite\protected\config\main.php, open this file and replace the codes with the following.
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(
'/'=>'/view',
'
//'=>'/',
'
/'=>'/',
),
),
*/
'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!

No comments:

Post a Comment