Skip to content

Setup Yii

Setup Yii

This example installs a Yii 2.x application with Composer from inside the Devilbox PHP container.

example yii documentation

Overview

The following configuration will be used:

Project nameVirtualHost directoryDatabaseTLD_SUFFIXProject URL
my-yii/shared/httpd/my-yiin.a.lochttp://my-yii.loc br https://my-yii.loc

[!NOTE] Inside the Devilbox PHP container, projects are always in /shared/httpd/. On your host, projects are stored in ./data/www/ by default. This path can be changed via env-httpd-datadir.

Walk through

It will be ready in six steps:

  1. Start Devilbox
  2. Enter the PHP container
  3. Create a new VirtualHost directory
  4. Install Yii 2.x via Composer
  5. Symlink the webroot directory
  6. Configure DNS and open the site

1. Start Devilbox

Terminal window
host> ./dvl.sh up

2. Enter the PHP container

All work will be done inside the PHP container:

Terminal window
host> ./dvl.sh shell

* enter-the-php-container * work-inside-the-php-container * available-tools

3. Create new vhost directory

The vhost directory defines the name under which your project will be available.

Terminal window
[email protected] in /shared/httpd $ mkdir my-yii
[email protected] in /shared/httpd $ cd my-yii

env-tld-suffix

4. Install Yii 2.x

Install the Yii 2 basic application template:

Terminal window
[email protected] in /shared/httpd/my-yii $ composer create-project --prefer-dist yiisoft/yii2-app-basic yii2

How the directory structure looks after installation:

Terminal window
[email protected] in /shared/httpd/my-yii $ tree -L 1
.
└── yii2
1 directory, 0 files

The web server expects every project document root in <vhost dir>/htdocs/. Yii keeps its entry point in web/, so symlink it to htdocs:

Terminal window
[email protected] in /shared/httpd/my-yii $ ln -s yii2/web/ htdocs
Terminal window
[email protected] in /shared/httpd/my-yii $ tree -L 1
.
├── yii2
└── htdocs -> yii2/web
2 directories, 0 files

6. DNS record and browser

If Auto DNS is configured you can skip the hosts entry. Otherwise add this line to your host operating system’s hosts file:

Terminal window
127.0.0.1 my-yii.loc

Open http://my-yii.loc or https://my-yii.loc to see the Yii welcome page.

  • howto-add-project-hosts-entry-on-mac
  • howto-add-project-hosts-entry-on-win
  • setup-auto-dns

Next steps

Use bundled batteries

* devilbox-intranet-adminer * devilbox-intranet-phpmyadmin * devilbox-intranet-phppgadmin * devilbox-intranet-phpredmin * devilbox-intranet-phpmemcachedadmin

Enhance the Devilbox

* setup-valid-https * setup-auto-dns * configure-php-xdebug

Add services

  • custom-container-enable-blackfire
  • custom-container-enable-rabbitmq
  • custom-container-enable-solr
  • custom-container-enable-varnish