├── .gitignore ├── LICENSE ├── README.md ├── Vagrantfile └── provisioning ├── defaults └── variables.yml ├── main.yml └── roles ├── adminer ├── handlers │ └── main.yml └── tasks │ └── main.yml ├── common ├── handlers │ └── main.yml ├── tasks │ ├── main.yml │ └── ntp.yml ├── templates │ └── ntp.conf.j2 └── vars │ └── main.yml ├── composer └── tasks │ └── main.yml ├── initial └── tasks │ └── main.yml ├── memcached ├── handlers │ └── main.yml └── tasks │ └── main.yml ├── mongodb ├── handlers │ └── main.yml └── tasks │ └── main.yml ├── mysql ├── handlers │ └── main.yml ├── tasks │ └── main.yml └── templates │ ├── my.cnf.j2 │ └── mysqld-ansible.cnf.j2 ├── nginx ├── handlers │ └── main.yml ├── tasks │ └── main.yml └── templates │ └── site.conf ├── php ├── handlers │ └── main.yml ├── tasks │ └── main.yml └── templates │ ├── php.ini │ └── www-pool.conf ├── phpmongo ├── handlers │ └── main.yml ├── tasks │ └── main.yml └── vars │ └── main.yml ├── phpmyadmin ├── handlers │ └── main.yml └── tasks │ └── main.yml ├── phpredis ├── handlers │ └── main.yml └── tasks │ └── main.yml ├── postgresql ├── handlers │ └── main.yml └── tasks │ └── main.yml ├── redis ├── handlers │ └── main.yml ├── tasks │ └── main.yml ├── templates │ ├── redis.conf.j2 │ └── upstart_redis.conf.j2 └── vars │ └── main.yml ├── sakila-db ├── handlers │ └── main.yml └── tasks │ └── main.yml ├── sqlite ├── handlers │ └── main.yml └── tasks │ └── main.yml └── yii-advanced-project ├── handlers └── main.yml ├── tasks └── main.yml └── templates ├── backend-main-local.php ├── common-main-local.php └── frontend-main-local.php /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .vagrant 3 | /yii2-app-advanced 4 | /html 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Evgeniy Kuzminov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Try Yii2 with Vagrant VM + Ansible provisioning 2 | 3 | ## Out of the box... 4 | 5 | * Ubuntu 14.04 64 bit ( + bulk of system soft like `mc`, `curl`, etc.) 6 | * PHP-FPM 5.5 ( + modules `intl`, `gd`, `xdebug` etc.) 7 | * Nginx 1.6 8 | * MySQL 5.5 9 | * Composer 10 | * phpMyAdmin 4.0 11 | * Adminer 4.1.0 12 | * Redis 2.8 ( + PhpRedis) 13 | * MongoDB 2.6.1 ( + php_mongo) 14 | * PostgreSQL 9.3 15 | * Sqlite 2.8.17 16 | * Memcached 1.4.14 ( + php5_memcached) 17 | * Imported [Sakila DB](http://dev.mysql.com/doc/sakila/en/) for playing around 18 | * And of course Yii2 Advanced Project template imported 19 | * Local IP loop on Host machine `/etc/hosts` and Virtual hosts in Nginx already set up too ! 20 | 21 | ## Quick start 22 | 23 | ### Install 24 | 25 | * [Virtualbox 4.3+](https://www.virtualbox.org/) + VirtualBox Extension Pack 26 | * [Vagrant 1.7+](http://www.vagrantup.com/) 27 | additional Vagrant modules will be installed automatically (vagrant-hostmanager, vagrant-vbguest, vagrant-cachier)` 28 | * Install Vagrant plugins 29 | `vagrant plugin install vagrant-hostmanager vagrant-vbguest vagrant-cachier` 30 | (these plugins will be checked and installed automatically, but `vagrant up` will fail on the first run, just re-run it if you'll get ` Unknown configuration section` error) 31 | > 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. 32 | 33 | ### RUN 34 | 35 | * Clone this sources from Git 36 | * Run `vagrant up`. 37 | * 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 ! 38 | * If you got an error regarding Composer and GitHub API requests limitation during provisioning - go to `/provisioning/main.yml`, uncomment var and add your GitHub oAuth token into `github_oauth_token` variable 39 | 40 | ### Supported Host OS : 41 | 42 | * **Ubuntu-based Linux 14.04+** - main tests and development, works the best 43 | * **Windows 7 Home** - rarely tested to bring some compatibility, but additional Your experience with Vagrant on Windows could be required 44 | * **MacOS** - not tested by maintainer, but assumed to work fine as there is no know big issues with Vagrant on MacOS 45 | 46 | #### Note for Windows OS users 47 | 48 | * Windows Firewall or any Antivirus software can cause some blocks on Vagrant start process. First of all to 'hosts' file modification. Be sure you turned them off (temporary) or set them up properly. 49 | * In case you get `default: warning: connection refused. Retying...` messages and Vagrant never boot successfully - it seems to be a VirtualBox issue. Try to install some older VBox version. It is tested to work on Virtual Box 4.3.6. 50 | * On Windows 8 some issues are reported due to `Hyper-V` enabled. You should disable it if you experience issues with VirtualBox machines. 51 | * use Git Bash if possible to make `vagrant ssh` working out of the box. 52 | 53 | ### PLAY 54 | 55 | Ok, now if everything went fine you can access these Urls in your browser 56 | 57 | * [http://yii2.local/](http://yii2.local/) - frontend app 58 | * [http://admin.yii2.local/](http://admin.yii2.local/) - backend app 59 | * [http://phpmyadmin.yii2.local/](http://phpmyadmin.yii2.local/) - phpMyAdmin 60 | * [http://adminer.yii2.local/](http://adminer.yii2.local/) - Adminer (Lightweight and simple GUI manager for MySQL, PostgreSQL, SQLite, MS SQL, Oracle, SimpleDB, Elasticsearch and MongoDB) 61 | 62 | * Gii code generator should be called like this [http://yii2.local/index.php?r=gii](http://yii2.local/index.php?r=gii) 63 | 64 | **Note :** These local domains `.local` will be available on your host machine only if `hosts` file was modified correctly. It should 65 | be done automatically by `vagrant-hostsmanager` plugin. But if url `http://yii2.local/` or other is not found by your browser - make sure 66 | your `hosts` file contain correct assignment of VM IP and local domains: 67 | It should have such lines : 68 | ``` 69 | 192.168.33.33 yii2.local 70 | 192.168.33.33 admin.yii2.local 71 | 192.168.33.33 phpmyadmin.yii2.local 72 | 192.168.33.33 adminer.yii2.local 73 | ``` 74 | 75 | > File location. On Linux `/etc/hosts`. On Windows `%SystemRoot%\system32\drivers\etc\hosts` 76 | 77 | ### Let's make something 78 | 79 | * [Go to Gii](http://yii2.local/index.php?r=gii) 80 | * [Go to Model Generator](http://yii2.local/index.php?r=gii/default/view&id=model) 81 | 82 | ~~~ 83 | Input there ... 84 | Table Name : actor 85 | Model Class : Actor 86 | Namespace : frontend\models 87 | 88 | Press - Preview and then Generate 89 | ~~~ 90 | 91 | * [Go to CRUD Generator](http://yii2.local/index.php?r=gii/default/view&id=crud) 92 | 93 | ~~~ 94 | Input there ... 95 | Model Class : frontend\models\Actor 96 | Search Model Class : frontend\models\ActorSearch 97 | Controller Class : frontend\controllers\ActorController 98 | 99 | Press - Preview and then Generate 100 | ~~~ 101 | 102 | * And now your Actor CRUD page is generated. You can access it here [http://yii2.local/index.php?r=actor](http://yii2.local/index.php?r=actor) 103 | * 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! 104 | 105 | 106 | ## Getting deeper ... 107 | 108 | * In `try-yii2` folder run `vagrant ssh` to access virtual dev server via SSH. You can modify and setup additionally anything you want. 109 | * 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!) 110 | 111 | ## TODO : 112 | 113 | * Sphinx 114 | * Elastic Search 115 | * CUBRID 116 | * yii-basic-template checkout (http://basic.yii2.local) 117 | * automatic Model / CRUD generation via Cli command 118 | 119 | ### Made by [Evgeniy Kuzminov](http://stdout.in). Thanks for support to [Anton Logvinenko](http://anton.logvinenko.name/). 120 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! 5 | VAGRANTFILE_API_VERSION = "2" 6 | 7 | # check and install required Vagrant plugins 8 | required_plugins = ["vagrant-hostmanager", "vagrant-vbguest", "vagrant-cachier"] 9 | required_plugins.each do |plugin| 10 | if Vagrant.has_plugin?(plugin) then 11 | system "echo OK: #{plugin} already installed" 12 | else 13 | system "echo Not installed required plugin: #{plugin} ..." 14 | system "vagrant plugin install #{plugin}" 15 | end 16 | end 17 | 18 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 19 | # Every Vagrant virtual environment requires a box to build off of. 20 | config.vm.box = "Ubuntu14.04" 21 | 22 | # The url from where the 'config.vm.box' box will be fetched if it 23 | # doesn't already exist on the user's system. 24 | config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box" 25 | 26 | # Uncomment this line and remove config.vm.box_url above 27 | # if you need to use 32 bit of Ubuntu 28 | # config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-i386-vagrant-disk1.box" 29 | 30 | # Create a private network, which allows host-only access to the machine 31 | # using a specific IP. 32 | config.vm.network "private_network", ip: "192.168.33.33" 33 | 34 | # Create a public network, which generally matched to bridged network. 35 | # Bridged networks make the machine appear as another physical device on 36 | # your network. 37 | # config.vm.network "public_network" 38 | 39 | # If true, then any SSH connections made will enable agent forwarding. 40 | # Default value: false 41 | # config.ssh.forward_agent = true 42 | 43 | # Share an additional folder to the guest VM. The first argument is 44 | # the path on the host to the actual folder. The second argument is 45 | # the path on the guest to mount the folder. And the optional third 46 | # argument is a set of non-required options. 47 | config.vm.synced_folder "./", "/var/www" 48 | # Provider-specific configuration so you can fine-tune various 49 | # backing providers for Vagrant. These expose provider-specific options. 50 | # Example for VirtualBox: 51 | # 52 | config.vm.provider "virtualbox" do |vb| 53 | # Don't boot with headless mode 54 | # vb.gui = true 55 | # Use VBoxManage to customize the VM. For example to change memory: 56 | vb.customize ["modifyvm", :id, "--memory", "512"] 57 | vb.customize ["modifyvm", :id, "--name", "TryYii2"] 58 | vb.customize ["modifyvm", :id, "--ostype", "Ubuntu_64"] 59 | vb.customize ["modifyvm", :id, "--cpuexecutioncap", "90"] 60 | # By default set to 1, change it to amount of your CPUs 61 | vb.customize ["modifyvm", :id, "--cpus", "2" ] 62 | # Or uncomment line above for Automatic set VirtualBox guest CPU count to the number of host cores 63 | # WARNING ! Works on Linux Host ONLY 64 | # vb.customize ["modifyvm", :id, "--cpus", `grep "^processor" /proc/cpuinfo | wc -l`.chomp ] 65 | end 66 | 67 | # Set entries in hosts file 68 | config.hostmanager.enabled = true 69 | config.hostmanager.manage_host = true 70 | config.hostmanager.ignore_private_ip = false 71 | config.hostmanager.include_offline = true 72 | config.hostmanager.aliases = ["yii2.local","admin.yii2.local","phpmyadmin.yii2.local","adminer.yii2.local"] 73 | 74 | if Vagrant.has_plugin?("vagrant-cachier") 75 | config.cache.scope = :box 76 | end 77 | 78 | # 79 | # Pre-provisioning 80 | # Install Ansible on the VM to run main provisioning from the VM itself 81 | # 82 | $script = <