Symfony4部署到共享主机 [英] Symfony4 deploy to shared hosting

查看:68
本文介绍了Symfony4部署到共享主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用symfony4.一切都在开发中工作.但是针对产品的教程较少. 如何部署教程仅提供了较少的信息(没有有关共享主机的信息)

I'm using symfony4. Everything works in dev. But there is less tutorial for prod. How to deploy tutorial provides only less info (No info about shared hosting)

Index.php防止.env读取环境变量.没关系.但是在Symfony2.x中,我们可以通过app.php和app_dev.php前端控制器在env之间切换.但是在Symfony4中,没有这样的文件,只有一个index.php和一个.env文件

Index.php prevents .env from reading the environment variables. Thats fine. But in Symfony2.x we can switch between env by app.php and app_dev.php front controllers. But in Symfony4 There is no such files only one index.php and an .env file

根据部署链接 .

如何设置环境变量,取决于您的设置:可以在命令行,Nginx配置中或通过托管服务提供的其他方法来设置它们.

How you set environment variables, depends on your setup: they can be set at the command line, in your Nginx configuration, or via other methods provided by your hosting service.

我正在使用共享主机,因此提供程序不允许更改环境变量.如果它在我的文件中,我可以很好地使用它.

I'm using shared hosting, so the provider does not allow to change environment variables. If it is in my file, I can use it good.

当前要解决此问题,我正在做的是

Currently to overcome this problem, what i'm doing is,

$_SERVER['APP_ENV'] = "prod";
$_SERVER['APP_SECRET'] = "79cfa09223f91b1a195134019e0b17ac";

我在index.php和bin/console文件的开头添加了这两行.我认为这不是正确的方法.

I added these two line at the beginning of index.php and bin/console file. I think this is not the correct way to do.

建议我热衷于部署symfony4(甚至测试产品环境)

推荐答案

您需要服务器上的.env文件具有APP_ENV=prod..env文件用于特定的计算机,git会将其忽略. ,同时跟踪.env.dist.因此,编辑.env.dist并提交.

You need the .env file that is on the server to have APP_ENV=prod The .env file is for the specific machine, it is ignored by git, while .env.dist is tracked. So edit the .env.dist and commit it.

将项目放置在与public_html相同的目录中作为同级.然后删除public_html目录,并将其重新创建为指向项目公共目录的符号链接.

Put your project in the same dir as public_html as a sibling. Then remove the public_html dir and recreate it as a symlink pointing to your project public dir.

.env.dist重命名为.env.

运行composer require symfony/apache-pack,它将创建.htaccess文件,您应该一切都很好.

Run composer require symfony/apache-pack it will create the .htaccess file and you should be good.

在A2托管的服务器上为我工作.

Worked for me on A2hosted server.

更新2019-06-28

只是部署到Bluehost,他们最终升级到了PHP7.除了一个更改之外,我使用与上述相同的过程部署到了子域中.我必须将以下行添加到由apache-pack生成的public/.htaccess文件中,以启用PHP 7.1

Just deployed to Bluehost, they finally upgraded to PHP 7. I deployed into a sub-domain using the same process as above except one change. I had to add the following line to the public/.htaccess file generated by apache-pack in order to enable PHP 7.1

AddHandler application/x-httpd-ea-php71 .php

这篇关于Symfony4部署到共享主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆