Homestead + Symfony 2.7 Installation Homestead + Symfony 2.7 Installation nginx nginx

Homestead + Symfony 2.7 Installation


For others looking into this, I believe there may be a better answer. I had trouble with getting Symfony 2 up and running with Homestead but found a few simple things in the process.

In my case, I took those errors as warnings of a deeper problem so I continued to look for the answer. I am using Homestead on a per-project basis, and Symfony was having some trouble with routing. In this case, the 403 error is indicative of permission denial - which would be mostly likely acquainted with the server trying to serve the wrong file. In Symfony installations running on Apache, this is usually resolved with the .htaccess file, but Homestead in Nginx and as such, obviously works differently.

First, Homestead comes with a Symfony provisioner baked into it which needs to run to set up Symfony's routing requirements. Enable it simply by adding this line under sites to make it looks like this (notice the type key):

sites:    - map: symfony.dev      to: "/home/vagrant/symfony/web"      type: symfony

Then start and provision Vagrant: vagrant up --provision. Make sure to clear the cache, but otherwise, you should be up and running.

Using App_Dev.php

Note: I recommend against renaming app_dev.php as that is not necessary.

To get the dev environment working for Symfony, I added my Homestead IP address to the security check in app_dev.php like this (roughly line 12 - notice the last line in the parenthesis starting with &&):

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')) || php_sapi_name() === 'cli-server')    && $_SERVER['SERVER_ADDR'] != '192.168.10.24') {    header('HTTP/1.0 403 Forbidden');    exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');}

Now, if you'd like to set /app_dev.php as your default file, you can do this in one of two ways. Unfortunately, neither are permanent (please leave a comment if you know of a good way). You need to change the app.php to app_dev.php in your /etc/nginx/sites-available/[site name] config file.

location / {    try_files \$uri \$uri/ /app.php?\$query_string;}

You might want to add app_dev.php to this list as well (about line 7):

index index.html index.htm index.php app.php;

You can SSH into your server by running (you will likely need to use sudo):

  • vagrant ssh
  • cd /etc/nginx/sites-available/[your site] (where [your-site] is set under "map" above
  • service nginx restart
  • service php5-fpm restart

Or go to /vendor/laravel/homestead/scripts/serve-symfony2.sh and change the appropriate lines. Again, modifying files in your /vendor directory is NOT recommended as it likely will be overwritten. You decide if that is worthwhile to you.

Don't forget to review Symfony's docs on server config.


Your variant:
# Also tried /home/vagrant/code/symfony-test/webis right. Just point in browser to http://test.dev/app.php because by default homestead looking for index.php or rename your app_dev.php to index.php!If you need dev mode comment in app_dev.php lines 12-18


I've created a symlink of app.php and it worked for me.

ln -s app.php index.php