Try Yii2 with Vagrant VM + Ansible provisioning = Complete readymade virtual server playground > stdout.in Ievgen Kuzminov IT blog

Try Yii2 with Vagrant VM + Ansible provisioning = Complete readymade virtual server playground

May 28, 2014, 7:14:24 PM

yii vagrant ansible

With nowadays web technologies anybody could try any web product with minimal efforts and completely safe. No more need to install and adjust tons of software, no more fear to ruine your working OS with another one server etc. I was dreaming making sandbox for Yii2 playground with Vagrant and Ansible from the first day I have learned them.
And today is this Day :)

So ... here it is on Github. Go !
And those who is not realy familiar with Vagrant and do not understand what I am talkign about - please read my post about Vagrant, you will love it.

In two words ...

"Try Yii2" provides you with Vagrant file and Ansible provsioning scripts. Vagrant will launch the VirtualBox VM, download OS image, deploy it and then run Ansible. It will set up all needed software inside Linux VM, clone Yii2 project, download test DB and connect it with project. Also Vagrant will modify you hosts file and assign special local domain adresses with VM IP address, so you will be able to access test Yii2 prject by humanreadable local domain name. All these steps will be made completely automatically, just run vagrant up and wait !

Now in details, out of the box you will get...

  • Ubuntu 14.04 64 bit ( + bulk of system soft like mc, curl, etc.)
  • PHP-FPM 5.5 ( + modules intl, gd, xdebug etc.)
  • Nginx 1.6
  • MySQL 5.5
  • Composer
  • phpMyAdmin 4.0
  • Adminer 4.1
  • Redis 2.8 ( + PhpRedis)
  • MongoDB 2.6 ( + php_mongo)
  • PostgreSQL 9.3
  • Sqlite 2.8.17
  • Memcached 1.4 ( + php5_memcached)
  • Imported Sakila DB for playing around
  • And of course Yii2 Advanced Project template imported
  • Local IP loop on Host machine /etc/hosts and Virtual hosts in Nginx already set up too !
  • And... I hope to add even more software in the future

Quick start

It was tested on Ubuntu Linux host machine (But after latest changes, when Ansible was transferred to VM, there is no known issues to run it on Windows)
On other host OSes potentially you will need to change some steps (like the way of Vagrant plugins installation and Terminal usage).
If you have issues on other OSes and have solved it - please send me comments here or on GitHub, to add some solutions to the docs.

Install

  • Virtualbox 4.3+ + VirtualBox Extension Pack
  • Vagrant 1.6+ additional Vagrant modules (optional, but provide full automation) :

  • vagrant plugin install vagrant-hostsupdater

  • vagrant plugin install vagrant-vbguest
  • vagrant plugin install vagrant-cachier

You don't need to have Ansible installed on host machine. It will be installed on VM and self-provisioning will be launched. So it is possible to run everything on Windows machine.

Run

  • Clone this from GitHub
  • Go inside cloned folder (where Vagrantfile is)
  • Run vagrant up.
  • It will start VM creation and Provisioning. Could take some time 15-30 min... Drink coffee and get back for complete virtual server with Yi2 project ready for play !

Hardware virtualisation issue

On this step you can face an issue, that you Vagrant up is failing just after importing Ubuntu Imgae. If you will run VBox image with GUI you could see an error like this

Failed to open a session for the virtual machine TryYii2. VT-x is disabled in the BIOS. (VERR_VMX_MSR_VMXON_DISABLED).

It means that you need to turn On hardware virtualisation in your BIOS. Just Google a little to find out how to do it for your BIOS. As I undestand everything will be fine if you have x64 CPU (Core i3-5-7), but if you still have old 32 bit CPU current Ubuntu Image (x64) could fail in any case, or there will no be VT-x option in your BIOS.
Than you can try to change config.vm.box_url param in Vagrantfile to this value https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-i386-vagrant-disk1.box

Play

Ok, now if everything went fine you can access these Urls in your browser

Let's make something

Input there ...  
Table Name : actor  
Model Class : Actor  
Namespace : frontend\models

Press - Preview and then Generate
Input there ...  
Model Class : frontend\models\Actor  
Search Model Class : frontend\models\ActorSearch  
Controller Class : frontend\controllers\ActorController

Press - Preview and then Generate
  • And now your Actor CRUD page is generated. You can access it here http://yii2.local/index.php?r=actor
  • Continue playing with other Models, modify code (on your host machine in folder .../try-yii2/yii2-app-advanced) make relations between Models etc. Whatever you wish!

Getting deeper ...

  • In try-yii2 folder run vagrant ssh to access virtual dev server via SSH. You can modify and setup additionally anything you want.
  • Or modify Ansible provisioning YML files (if you are familiar with it) and run vagrant provision to update server config (WARNING! I can't guarantee that your changes will not be overwritten!)

TODO :

Complete Ansible provisioning scripts for all software stack Yii2 works out of the box

  • Sphinx
  • Elastic Search
  • CUBRID

Make option for yii-basic-template checkout

Thanks for support to Anton Logvinenko.

comments powered by Disqus
Ievgen
Kuzminov "iJackUA"
Web Team Lead
at MobiDev (Kharkiv, Ukraine)
Code in Ruby and Elixir, but still love PHP. Explore ES6 and Vue.js. Explore databases, use Ubuntu and MacOS, think about IT people and management

Notes


Ok Docker I give up! It seems that Docker 1.0 with Docker Hub made so much progress and such an interesting ecosystem that I definitely need to try you :)