tiimowad tiimowad - 2 months ago 6
PHP Question

Hide "web" from URL in Symfony2.8 application

I have two different Symfony2.8 applications. During development they are accessible via two separated domains (virtual hosts):

www.app1.local
and
www.app2.local
. And everything works fine. But finally both applications should be deployed to the one server with one domain. Therefore I created two folders for each application.

Document root is
/httpdocs
, so file
/httpdocs/test.php
is accessible via
www.domain.com/test.php
. Two folders are
/httpdocs/app1
and
/httpdocs/app2
. Each contains different installation of Symfony2.8 with own bundles etc.

And what is the problem? The
web
in URL. The URL to application looks like
www.domain.com/app1/web/index.php
instead of
www.domain.com/app2/web/index.php
. I'm trying to hide this
web
from URL but I don't have idea how to do this.

Answer

In general, it should be configurated via web-server itself. But if you don't have any access to configuration of web-server (Apache, nginx), you can do the following.

Put in your /httpdocs/app1 copy of app1/web, and in /httpdocs/app2 copy of app1/web

Applications themselves put in some other place. So it will look, for example, like this:

app1/
  app/
  bin/
  ... # <--no web among these folders
  composer.json
  ...
app2/
  app/
  bin/
  ... # <--no web among these folders
  composer.json
  ...
httpdocs/
  app1/
    bundles/
    ....
    index.php
  app2/
    bundles/
    ....
    index.php

And then in your index.php fix paths to application

  $loader = require __DIR__.'/../../app1/app/autoload.php';
  include_once __DIR__.'/../../app1/var/bootstrap.php.cache';

(and same for app2, but with app2).

Also, fix both composer.json

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