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 yourapp/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:
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.
How about using.htaccess
file to achieve your goal. As far as I understand your problem your symfony app works IF you access it via web folder for examplefoo.com/test/web
try using the following code in your.htaccess
file which will sit at the root of yourtest
directory
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteCond %{REQUEST_URI} !web/
RewriteRule (.*) /web/$1 [L]
</IfModule>
please replace thedomain.com
with your domain name.
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Symfony compares favorably with other PHP frameworks in terms of reliability and maturity. This framework appeared a long time ago, in 2005, that is, it has existed much longer than most of the other tools we are considering. It is popular for its web standards compliance and PHP design patterns.
https://symfony.com/
Bootstrap is not exclusively a CSS framework, but its most popular features are CSS-centric. These include a powerful grid, icons, buttons, map components, navigation bars, and more.
https://getbootstrap.com/
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.