This project provides a virtual environment for Symfony development using Vagrant.
When you start Vagrant, this environment will provide the following tools that can be useful when developing for Symfony2:
- Git
- cURL
- MySQL
- Username:
root
- Password: empty
- Username:
- SQLite
- nginx
- PHP
- PHP-FPM
- APC
- PEAR
- XDebug
- Beanstalkd
- Memcached
- Node.js:
- less,
- casperjs,
- phantomjs,
- bower,
- gulp.
Additionally, it will create a MySQL database called cp
that a Symfony
application can connect to without any configuration.
Ansible is used to provision the virtual machine, so you must have that installed. Follow the installation instructions.
Installation is as easy as cloning a GitHub project:
$ git clone https://github.com/tinker1987/php7-symfony-vm VM
$ cd VM/sources
$ git clone {your project}
After the project is added, you can start the environment like this:
$ cd VM
$ vagrant up
Starting the VM might take some time, since it will download the entire box and additional applications/library. When the VM is done setting up, point your browser towards http://192.168.33.10 and there you have it: Symfony.
If you're using Windows, you have to modify the Vagrantfile
a little bit to
make it all work (since Windows doesn't support NFS). Replace the following
lines in the Vagrantfile:
config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", :nfs => true
config.vm.synced_folder "./sources/", "/var/www", id: "application", :nfs => true
with:
config.vm.synced_folder ".", "/vagrant", id: "vagrant-root"
config.vm.synced_folder "./sources/", "/var/www", id: "application"
- Make it possible to create virtual hosts by adding new section to site.yml;
- Add script for importing db dump if it is available in
db/
folder.
If you visit your site and you get the following error message:
You are not allowed to access this file. Check app_dev.php for more information.
You have to remove the following lines from web/app_dev.php
:
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
If your site is noticeably slow (and I'm talking hundreds of milliseconds), it's
because the caching and logging is taking it's time (NFS synchronization). One
way to fix this is by changing the cache folder in the app/AppKernel.php
file.
At the end of the AppKernel class, add the following methods:
public function getCacheDir()
{
return '/tmp/symfony/cache/'. $this->environment;
}
public function getLogDir()
{
return '/tmp/symfony/log/'. $this->environment;
}
This will change the location of the cache
and log
directories you normally
find in the app
directory of Symfony to the /tmp/symfony
directory. This
will speed up your site a lot. The downside is that you won't be able to check
the log from your host computer (the computer that's running Vagrant).
Thanks @kleiram for his awesome vagrant-symfony.