我是 Symfony 的新手,来自 .NET 世界。使用 Symfony (4) 文档,我设法创建了简单的网站。现在我想把它付诸实践,但我正在努力寻找任何有用的信息,我应该怎么做才能“打包”所有必要的东西并部署它。确实,有描述部署的页面( How to Deploy a Symfony Application ),但我发现它缺少以下信息:
dev
依赖项,部署composer
文件似乎也没有任何意义).env
文件 - 包含 APP_ENV
和 APP_SECRET
- 我在哪里使用这些值?)www
对于公开演示,我是否必须在重命名 public
之前更改/配置某些内容?目录到 www
? .htaccess
不通过 PHP 路由图像/css/js? 我目前的项目结构是:
+ bin
+ config
+ public
+ css
- index.php
+ src
+ Controller
- Kernel.php
+ templates
+ var
+ vendor
- .env
- .gitignore
- composer.json
- composer.lock
- symfony.lock
编辑(2018-07-17):
production
的 git 分支进行部署(每当我推送到这个分支时,它都会调用 composer install --no-dev
)composer.json
中完成composer.json
中的额外配置示例:"extra": {
"symfony": {
"allow-contrib": false
},
"public-dir": "www"
}
关于我最初的问题 - 我现在使用 git 使用托管部署功能。在这种情况下,我也需要 Composer 文件。我最初的想法是构建和打包最少的东西,然后将此包部署到服务器。 (现在我仍然有
bin
、 Composer 文件或 .gitignore
(可能还有更奇怪的东西)也已部署)。
最佳答案
好吧,我会拍的。
what to include/exclude (obviously I don't want to pack dev dependencies, and deploying composer files also doesn't seems to make any sense)
我注意到您没有
.gitignore
.如果你不使用 GIT(你应该)看看默认的 gitignore,它会告诉你哪些文件夹是你不需要的。你是对的,供应商不是必需的。 Composer 的锁定文件包含您正在使用的确切版本。就做
composer install
将文件复制到服务器后。 “部署”的最简单方法是使用 git(hub),并在您的服务器上设置一个 ssh key ,并授予它对您的 git repo 的读取权限。 (部署 key )what to change (there's .env file - containing APP_ENV and APP_SECRET - where do I use those values?)
.env 文件默认仅在开发模式下工作。 (注意 composer.json 中的 require-dev 部分)。
Symfony 推荐在生产环境中使用“真实的”环境变量,但是你可以使用
.env
文件。为此,您必须移动 "symfony/dotenv"
来自 require-dev
至require
在 Composer .json。 (之后进行更新)您还需要在服务器上将 APP_ENV 设置为 prod,同时配置 db access 和 mailer。
my hosting uses folder www for public presentation, do I have to change/configure something before renaming public directory just to www?
我不会完全回答这个问题,那会花费太长时间。使用 VirtualHost 将 apache 配置为指向您的公共(public)目录。更多信息:https://symfony.com/doc/current/setup/web_server_configuration.html
do I have to configure .htaccess to not route images/css/js trough PHP?
如果你安装了 apache 包,你会得到一个
.htaccess
文件,并且忽略文件。# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
这种方式请求的文件不会命中您的 PHP 代码。
但是,如果文件不存在,Symfony 将处理该请求。
我建议忽略常见的文件扩展名,例如:
# Do not allow image requests to hit symfony
RewriteCond %{REQUEST_URI} \.(gif|jpg|jpeg|png|ico|map)$ [NC]
RewriteRule .* - [L]
关于php - 打包和部署 Symfony 网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51195284/