Also available in these languages:
English日本語polskiРусский简体中文

Final Tune-up and Deployment

We are close to finish our blog application. Before deployment, we would like to do some tune-ups.

Changing Home Page

We change to use the post list page as the home page. We modify the application configuration as follows,

return array(
    ......
    'defaultController'=>'post',
    ......
);

Tip: Because PostController already declares index to be its default action, when we access the home page of the application, we will see the result generated by the index action of the post controller.

Enabling Schema Caching

Because ActiveRecord relies on the metadata about tables to determine the column information, it takes time to read the metadata and analyze it. This may not be a problem during development stage, but for an application running in production mode, it is a total waste of time if the database schema does not change. Therefore, we should enable the schema caching by modifying the application configuration as follows,

return array(
    ......
    'components'=>array(
        ......
        'cache'=>array(
            'class'=>'CDbCache',
        ),
        'db'=>array(
            'class'=>'system.db.CDbConnection',
            'connectionString'=>'sqlite:/wwwroot/blog/protected/data/blog.db',
            'schemaCachingDuration'=>3600,
        ),
    ),
);

In the above, we first add a cache component which uses a default SQLite database as the caching storage. If our server is equipped with other caching extensions, such as APC, we could change to use them as well. We also modify the db component by setting its schemaCachingDuration property to be 3600, which means the parsed database schema data can remain valid in cache for 3600 seconds.

Disabling Debugging Mode

We modify the entry script file /wwwroot/blog/index.php by removing the line defining the constant YII_DEBUG. This constant is useful during development stage because it allows Yii to display more debugging information when an error occurs. However, when the application is running in production mode, displaying debugging information is not a good idea because it may contain sensitive information such as where the script file is located, and the content in the file, etc.

Deploying the Application

The final deployment process manly involves copying the directory /wwwroot/blog to the target directory. The following checklist shows every needed step:

  1. Install Yii in the target place if it is not available;
  2. Copy the entire directory /wwwroot/blog to the target place;
  3. Edit the entry script file index.php by pointing the $yii variable to the new Yii bootstrap file;
  4. Edit the file protected/yiic.php by setting the $yiic variable to be the new Yii yiic.php file;
  5. Change the permission of the directories assets and protected/runtime so that they are writable by the Web server process.
$Id: final.deployment.txt 2017 2010-04-05 17:12:13Z alexander.makarow $
If you find any typos or errors in the tutorial, please create a Yii ticket to report it. If it is a translation error, please create a Yiidoc ticket, instead. Thank you.

Total 3 comments:

#522
why ?
by callmeblessed at 7:27pm on July 31, 2009.

should i upload all the files inside yii\framework\ ? it is about 6 mb

why yii separate the file of yii framework with the web apps itself ? should it be good if we just upload all the files insidie /wwwroot/blog/ without editing the other files...

developers that use subversion for example, need to change to their own yii framework.

#813
Caching
by agungrhm at 11:25am on November 19, 2009.

Thanks for the tutorial is very useful, I have a question about Enabling Schema Caching, i had took it on configuration as your tutorial, but something that appear is

CDbException Description

CDbConnection failed to open the DB connection: could not find driver Source File

mywebroot\db\CDbConnection.php(248)

can anyone explain it to me?

#1780
Deploying the Application - Additional Tasks
by thinkingspace at 8:45am on August 11, 2010.
  1. Make any additional changes needed to the configuration data in main.php, for example to the Database information (name, user, password etc.) It may be helpful to have test and deployment versions of this file, and then rename the appropriate one depending on the location.

Your Comment:

You may enter comment using Markdown syntax.

Please login with your forum account.
Note: you must have at least ONE forum post with your account.