The request was simple: one of my customer wanted to have a Symfony app available as a subfolder of an existing site, i.e.
http://www.example.com/myapp/
Googling for it, I found lots of tutorials but each one of them failed to meet two specific requirements:
So here’s my solution, which only assumes that you have file access (i.e. FTP) at one level above your site root.
Start by uploading the application folders at the same level of your site root:
[ftproot] -- public_html ---- ... ---- ... -- symfonyapp ---- app ---- bin ---- src ---- vendor ---- web ------ app.php ------ app_dev.php ------ ... ---- composer.json ---- composer.lock
Move the content of the “web” folder into the desired subfolder, i.e. “myapp”.
[ftproot] -- public_html ---- ... ---- ... ---- myapp ------ app.php ------ app_dev.php ------ ... -- symfonyapp ---- app ---- bin ---- src ---- vendor ---- composer.json ---- composer.lock
Edit files app.php and app_dev.php and insert the new application location.
require_once __DIR__ . '/../../symfonyapp/app/bootstrap.php.cache'; require_once __DIR__ . '/../../symfonyapp/app/AppKernel.php';
Edit file composer.json with the new web folder name
{ ... "extra": { ... "symfony-web-dir": "../public_html/myapp" } }
As @sadun reported in the comments, if you use Assetic, you have to let it know where the assets are:
read_from: “%kernel.root_dir%/../../public_html/myapp”
Basically, we’re used to have the “web” folder inside the Symfony app structure but as you just read it’s very easy to put it elsewhere.
Disclaimer: I haven’t yet tested the full “Rewrite” thing yet, I’ll come back to this later.
Update: the “symfony-web-dir” parameter was wrong, I fixed it.