Website is ready for hosting, now what?

Hi All,

I think my basic Yii2 website is ready for hosting. What steps to follow now?

I know all about ftp, hosting etc, but what to set where in Yii2 to make it suitable and secure for hosting? Where or how to disable the debugger and Gii. What htaccess file setting to make, etc. I used the basic Yii2 and built my website based on that, is it good enough for hosting or is it not secure enough?

Lot’s of questions I know, but I am sure most new Yii developers would like a common list of things to do before hosting a Yii website.


The first question is: can you run composer on you deployment server?

If the answer is no then you need to copy all the files of your project.

If the answer is yes then copy composer.json and composer.lock then run (composer.lock is need to preserve the component version you used during the development)

composer install

This will install yii2 and all the extensions that are in composer.json at the version saved in composer.lock

DO NOT RUN COMPOSER UPDATE, unless you want to UPDATE to never versions.

Normally in production environment you must run always composer install

Making update directly in production without testing if never version break your code is a bad idea.

run requirements.php to check if your server meet the yii2 minimum requirement (you should have done it long time ago)

Copy your project files, which on basic template are typically:

  • assets
  • commands
  • config
  • controllers
  • mail
  • migrations
  • models
  • views
  • web
  1. open web/index.php and set

defined(‘YII_DEBUG’) or define(‘YII_DEBUG’, false);

defined(‘YII_ENV’) or define(‘YII_ENV’, ‘prod’);

false: this disable the generation of debug info

prod: this will disable all the module (i.e. gii) declared in dev section of the config file (look at the end of config/web.php if (YII_ENV_DEV) {…)

  1. set your db connection(s) according to production environment

  2. regarding the .htaccess I hope you developed your site with the rewrite already active

  3. basic template is secure at same level as advanced one, in few words it is only a more simple scheme when you do not need frontend and backend

Another question: in production are you using the development db with the data or you want to start with a blank one?

Using the development db: just export/import it

Starting with a blank one:

  1. Apply framework and module migration

  2. apply your models migration (if you have them) or export and import your model schema

  3. populate the table that need to be filled (RBAC, Users, ‘Master Table’…)

At this point your site is up and running.

I think it is all, but probably I forgot something and others have more to add.

Awesome answer.

Thank you very much for such a complete answer. I have hosted an older version of Yii on the server before, but never a Yii2 site.

Thanks again