user972616
user972616

Reputation: 1404

Remove web/app.php in Symfony2

My server has the following directory structure

/srv
   /www
      /site.com
         /symfonysite
         /Other Drupal hosted site files

when I go to site.com my drupal site opens up and I want to be able to access my symfony site on site.com/symfonysite instead of site.com/symfonysite/web/app.php

I created an .htaccess file inside /symfonysite shown below

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /billing/web
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ app.php [QSA,L] 
</IfModule>

But this only gets rid of the app.php part, i.e. site.com/symfonysite/web opens my symfony site and site.com/symfonysite gives No route found for "GET /symfonysite/" error.

What am I doing wrong?

Upvotes: 4

Views: 2500

Answers (3)

xiidea
xiidea

Reputation: 3394

Its the beauty of symfony that it is highly configurable. You can achieve what you are looking for by following the simple 4 steps:

  1. Create a directory(say project) and put all the content of symfonysite there. You can put this directory any where you like. For simplicity we are going to create the directory in your symfonysite dir.

  2. Move all content of your symfonysite/web to symfonysite

  3. Edit the app.php and or app_dev.php to modify two line as follow:

    $loader = require_once __DIR__.'/../app/bootstrap.php.cache';
    require_once __DIR__.'/../app/AppKernel.php';

    to

    $loader = require_once __DIR__.'/project/app/bootstrap.php.cache';
    require_once __DIR__.'/project/app/AppKernel.php';

  4. Edit composer.json file to update the value of "symfony-web-dir": "web" and change it to

    "symfony-web-dir": "../",

Your modified directory structure may look like:

/srv
   /www
      /site.com
         /symfonysite
              /project
         /Other Drupal hosted site files

NB: For security reason symfony suggest to expose only the web directory to a web accessible path. You can put the project directory any where you like. Just need to update the path as per your locations. To give this set-up a little more security you can put a .htaccess file in the project directory

.htaccess

Deny from all

Enjoy!!

Upvotes: 6

Chris Gunawardena
Chris Gunawardena

Reputation: 6468

You need to make /srv/www/site.com/symfonysite/web the document root of the project. This can't be done with .htaccess so you need to change apache virtual host config. This usually lives in /etc/apache2/sites-enabled/yourserver.com.conf

<VirtualHost *:80>
    ServerName yourserver.com
    DocumentRoot /srv/www/site.com/symfonysite/web
</VirtualHost>

I'm not sure how rackspace sites work, maybe best to open a support ticket with them if you are unable to change these settings. I head they have Fanatical Support :P

Upvotes: 3

Michael Sivolobov
Michael Sivolobov

Reputation: 13240

The best approach IMHO is to use symlinks. In the site.com/web/content directory you need to run ln -s symfonysite/web sitesymfony. It will create symlink sitesymfony in your web-root that points to /site.com/web/content/symfonysite/web folder. Then your site.com/sitesymfony will call app.php from site.com/symfonysite/web

Upvotes: 1

Related Questions