How to safely go to maintenance?


I am wondering what would be the best way to take a yii website off the air for maintenance.

Anyone has experience with that?

I would like to have a simple page showing “we’re off the air, please, come back later”,

closing db connections, but ideally waiting for users that were browsing the site before the

maintenance page kicked in to finish their navigation as they might be in the middle of something.

Is there a right way of doing it?

Thanks in advance for any help!


I would probably just replace /index.php to display what you want. You could create another virtual host to point to a different bootstrap file while you work on the application.


You could do this:

Or use an extension:

That’s cool! I didn’t even know about ‘catchAllRequest’.


I will probably use a solution that mixes both suggestions.

I’ll do the check for ‘.maintenance’ file in ‘index.php’:




	? include(dirname(__FILE__).'/protected/config/maintenance.php')

	: include(dirname(__FILE__).'/protected/config/main.php');


And then ‘maintenance.php’ boils to:


return array(



That way I can avoid any interaction with other components,

specially the database (I am using CDbHttpSession in ‘main.php’).

Thanks for the helpful comments!

What if I want to provide my client with the facility to put the site in online/offline mode from a backend setting?

Use PHP to create a .maintenance file - and likewise remove it.

For the best of both worlds: combine the extension with the tip. :)

The extension allows admins to login.

Any new ideas for this?