We are close to finish our blog application. Before deployment, we would like to do some tune-ups.
We change to use the post list page as the home page. We modify the application configuration as follows,
return array( ...... 'defaultController'=>'post', ...... );
indexto be its default action, when we access the home page of the application, we will see the result generated by the
indexaction of the post controller.
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.
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.
The final deployment process manly involves copying the directory
/wwwroot/blog to the target directory. The following checklist shows every needed step:
/wwwroot/blogto the target place;
index.phpby pointing the
$yiivariable to the new Yii bootstrap file;
protected/yiic.phpby setting the
$yiicvariable to be the new Yii
protected/runtimeso that they are writable by the Web server process.