将 Yii2 部署到共享主机中,直接部署到基本模板文件夹



我已经阅读了 Yii2 官方网站的文档,从这个 : http://www.yiiframework.com/doc-2.0/guide-tutorial-shared-hosting.html 将 yii2 部署到共享主机中,以及关于这个的讨论:stackoverflow。

所以,我决定使用 sftp 上传 yii2 文件夹。 这是我的共享主机中的目录列表。

access-logs
etc
logs
public_ftp
public_html
ssl
www (this is a link folder to public_html)

您知道,因为共享主机可以保留域直到 5 个域, 是否可以将Yii2Basic文件夹上传到public_html文件夹中?

所以结果是这样的:

access-logs
etc
logs
public_ftp
public_html
-basic
- bunch of yii folders here
ssl
www (this is a link folder to public_html)

因为现在,如果我想访问我的网络,我必须这样写:mydomain.com/basic/public_html/index.php

我需要这样:

mydomain.com/index.php

请指导我。

是的,您可以在public_html文件夹中上传它,但我现在使用 yii2 Basic 应用程序面临的唯一问题是漂亮的 URL,您可以在public_html文件夹中克隆或上传整个内容,我所做的如下,唯一的区别是我有一个web文件夹而不是www

目录结构

public_html
assets
commands
config
controller
mail
migrations
models
runtime
tests
vendor
views
web

public_html/.htaccess

<IfModule mod_rewrite.c>
Options +SymLinksIfOwnerMatch
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} ^/.*
RewriteRule ^(.*)$ web/$1 [L]
RewriteCond %{REQUEST_URI} !^/web/
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ web/index.php
</IfModule>

public_html/web/.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

这有效,但在 URL 中它显示/web/index.php?r=site/index,一旦我在配置文件urlManager中打开prettyUrl,它只会显示默认索引页面,并且我尝试打开的每个链接最终都会出现在主页视图上,尽管地址栏中的 URL 是正确的并且 urlManager 正确解析了规则, 这是我所到之处。

如果你不介意根文件夹中的一堆 Yii 2 文件夹,只需将所有基本的模板文件夹(web除外(和文件放在根文件夹中。然后将web文件夹的内容放在public_html文件夹中。

它应该是这样的:

access-logs
assets
commands
config
controllers
etc
logs
mail
models
public_ftp
public_html
// here should be the content of web folder of Yii 2 basic app
runtime
ssl
test
views
widgets

最新更新