Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 215
user972616 Avatar asked Dec 25 '22 12:12

user972616


2 Answers

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!!

like image 165
xiidea Avatar answered Dec 28 '22 10:12

xiidea


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

like image 24
Chris Gunawardena Avatar answered Dec 28 '22 09:12

Chris Gunawardena