My website is ready to be deployed and I am trying to set it up online.
Some informations:
/www/test
for now (my current website is still in /www
).The problem:
When I open the URL my-website.com/test
, a Symfony exception tells me No route found for "GET /test/"
, which clearly means that Symfony doesn't know it is in a sub-directory.
How can I tell it?
EDIT:
I just realized it worked when I access my-website.com/test/web
.
Here I wrote exactly about that: https://www.refactory-project.com/install-symfony-app-in-a-subfolder-of-an-existing-site/
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"
}
}
You're sort of setting yourself up for hardship if you are deploying a Symfony app to a host that does not allow SSH - for instance if you want to rebuild your cache you will have to manually nuke your app/cache/*
dirs?
To answer your question directly, if your Symfony project is in /www/test/
then Symfony's web directory is /www/test/web
so you need to use a url like:
http://foo.com/test/web
For completeness, try accessing the explicit url - /test/app.php
and /test/app_dev.php
respectively. If you receive a Symfony error page in either case you know you are on the right path at least.
Edit #1
Something to point out: your project and configuration files and may be readable with this deployment scenario - which is not ideal - so you might want to check this and take some actions to secure this directory if possible. I appreciate that this is probably a test deployment so it might not be a big deal, but it's always good to keep mindful of security :)
Edit #2
Okay YMMV with this, I am no .htaccess
expert but you could deploy your symfony app to /www/symfony/
and rewrite the /test
URI to show /symfony/web/
instead; e.g:
RewriteEngine On
# rewrite all `/test/*` uris to `symfony/web`
RewriteRule ^test(.*)$ symfony/web/$1 [L,QSA]
# direct access to /symfony dir is a 404
RewriteRule !^symfony/web/$1 - [R=404]
This should serve all applicable uri requests (to /test
and /symfony/web
itself) to Symfony, while restricting direct access to the symfony core files.
Haven't tested this, so how this will play with Symfony's own .htaccess
is not something I can answer off the top of my head.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With