An ansible provisioning to set-up a PHP development environment in Vagrant. Tuned for modern php applications (Symfony2, Silex, Laravel, etc.)
We (Ibsciss) use it for our php developments.
Build on top of the default precise64 vagrant box, PHP5.5 & Ngninx ansible provisioning added.
Plus :
- Composer
- Php cli
- Php sqlite
- Mysql (default db, user & password : ibsciss)
- Wkhtmltopdf
- You need to have Ansible & Vagrant installed on your computer before you start.
- A NFS shared folder is used, so you need the
nfs-kernel-server
package on the host to use it :apt-get install nfs-kernel-server
- Create a directory for your project (warning: don't git clone at this step):
$ mkdir my-project
. - Clone this repository inside a "provisioning" sub-directory:
$ git clone https://github.com/Ibsciss/vagrant-ansible-php my-project/provisioning
. - Clone your php project inside a "code" sub-directory:
$ git clone https://github.com/organization/my-project my-project/code
. - Go to the
provisioning
folder and runvagrant up
:$ cd my-project/provisioning
&&$ vagrant up
.
Note : Symfony < 2.3 installation you have to copy the app/config/parameters.yml.dist
to app/config/parameters.yml
.
- After setup, login in the vagrant VM :
vagrant ssh
- Change current user to www-data :
sudo -s -u www-data
- Go to the app directory :
cd /var/www
- Install composer dependencies :
composer install
- If needed, dump assets :
app/console assetic:dump
- Install database stuffs
- install database schema :
app/console doctrine:schema:create
- (optionnal) install fixtures :
app/console doctrine:fixtures:load
- install database schema :
- Remove previous caches :
app/console cache:clear --env=prod && app/console cache:clear
- Open your browser, go to
http://ibsciss.devel
and Tada ! Your app is up and running.
One of the biggest issue with wagrant is dealing with large amount of I/O on the shared disk.
A solution is to put non-src repository which generate a lot of I/O, especially log & cache mecanism, in memory. On debian/ubuntu you have a /dev/shm
which is a disk mounted in memory.
Overriding default cache & log directory can be achieve in AppKernel.php
file :
<?php
class AppKernel extends Kernel
{
public function getCacheDir()
{
if (in_array($this->environment, array('dev', 'test'))) {
return '/dev/shm/symfony/cache/' . $this->environment;
}
return parent::getCacheDir();
}
public function getLogDir()
{
if (in_array($this->environment, array('dev', 'test'))) {
return '/dev/shm/symfony/logs';
}
return parent::getLogDir();
}
}
from WhiteWashing.de a great blog about php & programming.