Difference between #61 and #62 of
Yii v2 snippet guide III

Revision #62 has been created by rackycz on Mar 13, 2021, 11:41:23 AM with the memo:

Vagrant
« previous (#61) next (#63) »

Changes

Title unchanged

Yii v2 snippet guide III

Category unchanged

Tutorials

Yii version unchanged

2.0

Tags unchanged

tutorial,yii2,beginer

Content changed

[...]
replace: $1php $2 // <?php if ...
// note that sometimes <?xml can be found and it is valid, keep it

```

**
Running Yii project in Vagrant. (Simplified version)**
 
---
 
 
*Info: This chapter works with PHP 7.0 in ScotchBox. If you need PHP 7.4, read next chapter where CognacBox is used (to be added when tested)*
 
 
Important: If command "vagrant ssh" wants a password, enter "vagrant".
 
 
- Do you want your colleague-developers to use identical environment like you have?
 
- Or do you want to easily setup whole server after you reinstalled your computer?
 
 
This is when Vagrant is helpful. 
 
 
Vagrant creates a virtual machine with a web server (using almost any OS/PHP/SQL you specify), while the docroot is on your local disk so you can easily modify the PHP fil
Virtualization - Vagrant and Docker - why and how**
 
---
 
Both Vagrant and Docker create a virtual machine using almost any OS or SW configuration you specify, while the source codes are on your local disk so you can easily modify them in your IDE under your OS.
 
 
Can be used not only for PHP development, but in any other situation.
 
 
What is this good for? ... Your production server runs a particular environment and you want to develop/test on the same system. Plus you dont have to install XAMPP, LAMP or other servers locally. You just start the virtual and its ready. Plus you can share the configuration of the virtual system with other colleagu
es inso your IDE and in your OS. Vagrant all work on indentical environment.
 
 
Vagrant and Docker
works just like composer or NPM. It is a library of available OS images and other SW and you just pick soone. Whole configuration is defined in one text-file, named Vagrantfile or docker-compose.yml, and all you need is just a few commands to run it. And debugging is no problem.
 
**Running Yii project in Vagrant. (Simplified version)**
 
---
 
 
*Info: This chapter works with PHP 7.0 in ScotchBox. If you need PHP 7.4, read next chapter where CognacBox is used (to be added when tested)*
 
 
**Basic overview and Vagrant configuration:**
 
 
List of all available OS images for Vagrant is here: - https://app.vagrantup.com/boxes/search Both Yii demo-applications already contain the Vagrantfile, but its setup is unclear to me - it is too PRO. So I wanted to publish my simplified version which uses OS image named [scotch/box](https://box.scotch.io) and you can use it also for non-yii PHP projects. (It has some advantages, the disadvantage is older PHP in the free version) The Vagrantfile is stored in the root-folder of your demo-project. My Vagrantfile contains only following commands.

```
[...]
```

Before you use Vagrantfile, you mu**Installing and using Vagrant:**
 
 
Fir
st install Vagrant and VirtualBox, please. Note 1: Sadly, these days VirtualBox does not work on the ARM-based Macs with the M1 chip
 
 
Note 2: You can use many other virtual systems besides VirtualBox ( see the list of OS images above), but "my" scotch/box is designed only for VirtualBox I think
. Use Docker in that case.
 
 
Important: If command "vagrant ssh" wants a password, enter "vagrant"
.

- Install [Virtual Box](https://www.virtualbox.org/wiki/Downloads), I recommend to install also the "Extension Pack", but is might be done automatically by "scotch/box".
- Install [Vagrant](https://www.vagrantup.com/downloads) ... on Windows restart is needed :-(
- https://www.sitepoint.com/re-introducing-vagrant-right-way-start-php/
[...]
8 0
4 followers
Viewed: 191 071 times
Version: 2.0
Category: Tutorials
Written by: rackycz
Last updated by: rackycz
Created on: Jan 21, 2021
Last updated: a year ago
Update Article

Revisions

View all history