Homestead + Symfony 2.7 Installation

I am having trouble installing Symfony2 in a Vagrant Laravel Homestead box.

I get a 403 response repeatedly when I enter a URL.

I have this in mine Homestead.yaml

and added test.dev

to my hosts file.

    folders:
        - map: ~/code
          to: /home/vagrant/code

    sites:
        - map: test.dev
        to: /home/vagrant/code/symfony-test
        # Also tried /home/vagrant/code/symfony-test/web

      

Any ideas?

+3


source to share


3 answers


Your option:
# Also tried /home/vagrant/code/symfony-test/web

correct. Just point your browser to http://test.dev/app.php because homestead looks for index.php by default, or rename app_dev.php to index.php! If you need a comment in mod mode on app_dev.php lines 12-18



+5


source


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

In my case, I accepted these errors as warnings of a deeper problem, so I kept looking for an answer. I use Homestead for every project and Symfony had routing issues. In this case, a 403 error indicates a permission denied - which is likely to be familiar with a server trying to serve an invalid file. In Symfony installations running on Apache, this is usually resolved with a file .htaccess

, but Homestead in Nginx and as such obviously works differently.

First, Homestead comes with a Symfony builder to run to set up Symfony's routing requirements. Enable it by simply adding this line underneath sites

so that it looks like this (note the key type

):

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

      

Then run and put Vagrant: vagrant up --provision

. Be sure to clear the cache, but otherwise you should be up and running.

Using App_Dev.php

Note. I recommend that you avoid renaming app_dev.php

as it is optional.

To get the Dev environment to work in Symfony, I added my Homestead IP to the security check in app_dev.php

like this (roughly line 12 - notice the last line in parentheses starting at &&

):

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 want to set /app_dev.php

as the default file, you can do it in one of two ways. Unfortunately, none of them are permanent (please leave a comment if you know a good way). You need to change app.php

to app_dev.php

in the config file /etc/nginx/sites-available/[site name]

.

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

      

You might want to add app_dev.php

to this list (line 7):

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

      

You can SSH into your server (you will most 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 relevant lines. Again, modifying files in the / vendor directory is NOT recommended as it will likely be overwritten. You decide if you should do it.

Don't forget to look at the Symfony docs in the server config .

+12


source


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

ln -s app.php index.php

      

+2


source







All Articles