
Vagrant, Symfony and Windows are not incompatibles
At work, I’m using Vagrant on my Windows 10 because Docker really sucks on windows :(
So after promoting PuPHPet, I’m now using
Scotch Box.
In a few words, this is some features already in this box:
- Ubuntu 14.04 LTS (Trusty Tahr)
- PHP 5.6
- Ruby 2.2.x
- MySQL, PostreSQL, SQLite, MongoDB
- Redis, Memcache, Memcached
- Vim, Git, cURL, Composer, Node, NPM, Mailcatcher, Bower, Grunt…
- …
It is a good base.
For my needs, I pimp this box (take a look on
my fork (on GitHub)). I found it pretty cool on my linux…
but on my Windows, it’s really SLOW!
Before: running a Symfony app into a Vagrant box
Here is some tip’s to speed up your application.
First step: Install plugins
-
Install VirtualBox Guest plugin
Terminal window vagrant plugin install vagrant-vbguest -
Install Vagrant WinNFSd plugin
Terminal window vagrant plugin install vagrant-winnfsd
I don’t reinvent the wheel here. If you type speed up vagrant on windows
you will see the same
results.
With this config I switch from ~16s to ~4s for a page to load.
Second step: Install PHP7
In my case PHP7 really decrease page loading time. Be careful, installing PHP7 will remove php5.
1. Update package list
sudo apt-get install python-software-propertiessudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
2. Install PHP7 and remove PHP5
sudo apt-get updatesudo apt-get purge php5-common -ysudo apt-get install -y \ && php7.0 \ && php7.0-fpm \ && php7.0-mysql \ && php-curl \ && libapache2-mod-php7.0 \ && php7.0-mbstringsudo apt-get --purge autoremove -y
3. Set timezone (i.e. date.timezone = Europe/Paris)
sudo vi /etc/php/7.0/cli/php.inisudo vi /etc/php/7.0/apache2/php.ini
4. Restart apache service
sudo a2enmod php7.0sudo service apache2 restart
Now my app run in ~2s.
Third step: Don’t sync cache/log folders with your windows host!
On Benjamin Eberlei’s blog, I found this last tip: put yours logs and cache on non-shared folders.
<?phppublic function getCacheDir(){ if (in_array($this->environment, array('dev', 'test'))) { return '/dev/shm/application-name/cache/' . $this->environment; }
return parent::getCacheDir();}
public function getLogDir(){ if (in_array($this->environment, array('dev', 'test'))) { return '/dev/shm/application-name/logs'; }
return parent::getLogDir();}
If you need, here is some aliases to help you.
# Remove cachealias cache-clear='rm -rf /dev/shm/application-name/cache/'# Copy logs into your Sf projectalias cplogs='cp -R /dev/shm/application-name/logs /var/www/application-name/public/app'
And… tadaaaa! It took Some hundred milliseconds ♥ (I also added some SQL requests to MySQL… just for fun).
After: running a Symfony app into a Vagrant box
About the author

Hey, I'm Maxence Poutord, a passionate software engineer. In my day-to-day job, I'm working as a senior front-end engineer at Orderfox. When I'm not working, you can find me travelling the world or cooking.
Follow me on Bluesky