Question

Let's say I have a Symfony webapp and it is in a subfolder of my webroot

path/to/root/<subfolder>/Symfony/

So if I would want to call my page I have to enter

http://host.tld/<subfolder>/Symfony/web

But as you can imagine I would like everyone just to call

http://www.host.tld/

I know that I can use the webserver's settings (e.g. define root directory, set alias etc.). Thus I derive two questions:

  1. Where do I tell Symfony that this is the base of all to be created links? And

  2. Does Symfony provide a native function or configuration, where I can set this up without having to change my webserver's configuration?

Était-ce utile?

La solution

Dedicated server :

If you are on a dedicated debian server (with apache), you probably know what is a vhost.

You need to create a Vhost and point the domain to the web folder of the Symfony project to encapsulate users :

nano /etc/apache2/sites-enabled/host.tld :

<VirtualHost *:80>
    ServerName host.tld
    DocumentRoot /home/sybio/www/mywebsite/Symfony/web

    <Directory "/home/sybio/www/mywebsite/Symfony/web">
        DirectoryIndex app.php
        Options -Indexes FollowSymLinks SymLinksifOwnerMatch
        AllowOverride All
        Allow from All
    </Directory>
</VirtualHost>

Then test apache configuration :

apache2ctl configtest

If no error restart :

apache2ctl restart

That's it !

Shared hosting :

In many hosters, like OVH, you can configurate the destination folder (web dir) thanks to admin panel ! If you can't, this is easy :

1) add Symfony structure at the root dir of your shared hosting

2) Rename the web/ dir by the one used by your hoster (oftently "www" or "public")

3) Override Sf configuration to say "web" dir is now named "www" : http://symfony.com/doc/current/cookbook/configuration/override_dir_structure.html#override-the-web-directory

Autres conseils

  1. Move the Symfony folder and all it's contents to someplace else such as /home/work/Symfony

  2. Copy Symfony/web/.htaccess and app.php to http://www.host.tld/ (i.e. www or public-html or htdocs)

  3. Edit app.php and adjust the require statements to point to /home/work/Symfony/app

  4. run app/console assets:install http://www.host.tld/

At this point, the app should run from www.host.tld assuming your caching permissions are setup correctly. The routes will have the generated desired paths in them.

No real need to change your web configuration.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top