我想知道你们是否知道一种方法,可以在web主机的子目录/子文件夹中安装Laravel 4,同时不将/app/文件夹和其他合理的文件expose 给主机的可公开访问部分.

The idea is, I'd be able to access http://mydomain.com/mylaravel/ to be able to use Laravel, but at the same time I want to avoid anyone doing something like going to http://mydomain.com/app/ or http://mydomain.com/mylaravel/app/ and basically being able to see my config files and other code.

推荐答案

So I figured out how to do this. I'll explain with an example.

假设你有一个域名,http://domain.com.以下是您可能使用的 struct 示例:

domain.com/    (the root of your web hosting)
|-- yourlaravel4_base/
|-- [some other folders...]
|-- public_html/    (where your html files and such go)
|   |-- [some other folders...]
|   |-- yourlaravel4/

/public_html/ is the root of the publicly accessible part of your web hosting files. You want to create a subfolder in /public_html/ (in this case /public_html/yourlaravel4/). In this subfolder you will store all the contents of the Laravel 4 public/ folder.

Now, for the rest of the files. You have to go to the root of your web hosting files, that is, you wanna be at domain.com/ level, therefore being able to see public_html/ and some other folders. Then, we need to create a folder here, where Laravel 4's base files will be stored. In this case, it's domain.com/yourlaravel4_base/. Inside yourlaravel4_base/ we need to store every file and folder that exists in the base Laravel 4 directory. That would be app/, bootstrap/, vendor/, server.php, etc. Everything EXCEPT the /public/ folder, whose contents you already stored in public_html/yourlaravel4/.

Finally, we need to edit 2 files: Laravel's /bootstrap/paths.php and /public/index.php.


In the 100 file, replace:

'app' => __DIR__.'/../app',

与:

'app' => __DIR__.'/../../yourlaravel4_base/app',

In the 100 file, replace:

'public' => __DIR__.'/../public',

与:

'public' => __DIR__,

In the 100 file, replace:

'base' => __DIR__.'/..',

与:

'base' => __DIR__.'/../../yourlaravel4_base',

In paths.php, replace:

'storage' => __DIR__.'/../app/storage',

与:

'storage' => __DIR__.'/../../yourlaravel4_base/app/storage',

In 100, replace:

require __DIR__.'/../bootstrap/autoload.php';

与:

require __DIR__.'/../../yourlaravel4_base/bootstrap/autoload.php';

In 100, replace:

$app = require_once __DIR__.'/../bootstrap/start.php';

与:

$app = require_once __DIR__.'/../../yourlaravel4_base/bootstrap/start.php';

Upload changes. Now you should be able to have Laravel 4 installed in a subfolder in your website without actually exposing the app/ folder and other sensitive files. :)

Laravel相关问答推荐

Nuxt 3获取多部分表单数据上传不起作用

警告:构建Reaction App(VITE)后无法解码下载的字体警告

为什么只删除了最后一个Like,而没有删除选中的?

在postgres/mysqlс中,我可以定义基于json字段的唯一索引吗?

V-icon 在 Vuetify 3 中不显示图标

自定义 Laravel 关系?

Laravel 错误ReflectionException-类 App\Http\Kernel 不存在

Blade引擎:打印三重花括号

Laravel 附加额外字段

Laravel transformer vs resource

Laravel 5.5 在迁移文件中设置整数字段的大小

PHP 中的 Http 响应代码枚举

升级到 laravel 5.4 后调用未定义的方法

Laravel 中未加密的 cookie

WhereHas Laravel 中的关系计数条件是什么

Laravel/PHPUnit:断言 json 元素存在而不定义值

Laravel 检测手机/平板电脑并加载正确的视图

Laravel 不活动时间设置

如何判断是否连接到 Laravel 4 中的数据库?

Laravel 验证用户名不允许有空格