如何在子目录中部署 Symfony? [英] How can I deploy Symfony in a subdirectory?
问题描述
我的网站已准备好部署,我正在尝试将其设置为在线.
My website is ready to be deployed and I am trying to set it up online.
一些信息:
- 主持人是 OVH.
- 它不允许使用 SSH,我必须使用 FTP 发送我的文件.也没有命令行.
- 我现在希望能够在子目录中设置网站:
/www/test
(我当前的网站仍在/www
中).立>
- The host is OVH.
- It doesn't allow SSH, I have to send my files with FTP. No command line either.
- I want to be able to set up the website in a subdirectory:
/www/test
for now (my current website is still in/www
).
问题:
当我打开 URL my-website.com/test
时,Symfony 异常告诉我 No route found for "GET/test/"
,这显然意味着Symfony 不知道它在子目录中.
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.
我怎么知道?
当我访问 my-website.com/test/web
时,我才意识到它起作用了.
I just realized it worked when I access my-website.com/test/web
.
推荐答案
我在这里专门写过: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
移动 Web 部件
移动网络"的内容文件夹放入所需的子文件夹,即myapp".
Move the web part
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
让网络知道应用程序在哪里
编辑文件 app.php 和 app_dev.php 并插入新的应用程序位置.
Let the web know where is the application
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';
让应用程序知道 web 文件夹是如何调用的
使用新的 Web 文件夹名称编辑文件 composer.json
Let the application know how the web folder is called
Edit file composer.json with the new web folder name
{
...
"extra": {
...
"symfony-web-dir": "../public_html/myapp"
}
}
这篇关于如何在子目录中部署 Symfony?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!