如何在不公开/app/文件夹的情况下将 Laravel 4 安装到 Web 主机子文件夹? [英] How to install Laravel 4 to a web host subfolder without publicly exposing /app/ folder?
问题描述
我想知道你们中是否有人知道将 Laravel 4 安装在网络主机的 SUBDIRECTORY/子文件夹中,同时不将/app/文件夹和其他敏感文件暴露给主机的可公开访问部分的方法.
I was wondering if any of you know of a way to install Laravel 4 in a web host SUBDIRECTORY / subfolder while not exposing the /app/ folder and other sensible files to the publicly accesible part of the host.
这个想法是,我可以访问 http://mydomain.com/mylaravel/ 以便能够使用Laravel,但同时我想避免任何人做类似去 http://mydomain.com/app/ 或 http://mydomain.com/app/a href="http://mydomain.com/mylaravel/app/">http://mydomain.com/mylaravel/app/ 并且基本上能够看到我的配置文件和其他代码.
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.以下是您可能正在使用的结构示例:
Suppose you a domain, http://domain.com. Here's an example of the structure you might be using:
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/
是您的网络托管文件的可公开访问部分的根.您想在 /public_html/
中创建一个子文件夹(在本例中为 /public_html/yourlaravel4/
).在此子文件夹中,您将存储 Laravel 4 public/
文件夹的所有 内容.
/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.
现在,剩下的文件.你必须去你的网络托管文件的根目录,也就是说,你想在 domain.com/
级别,因此能够看到 public_html/
和其他一些文件夹.然后,我们需要在这里创建一个文件夹,用于存放 Laravel 4 的基础文件.在这种情况下,它是 domain.com/yourlaravel4_base/
.在 yourlaravel4_base/
中,我们需要存储基本 Laravel 4 目录中存在的每个文件和文件夹.那将是 app/
、bootstrap/
、vendor/
、server.php
等.除了 /public/
文件夹,您已经将其内容存储在 public_html/yourlaravel4/
中.
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/
.
最后,我们需要编辑2个文件:Laravel的/bootstrap/paths.php
和/public/index.php
.
Finally, we need to edit 2 files: Laravel's /bootstrap/paths.php
and /public/index.php
.
在paths.php
文件中,替换:
In the paths.php
file, replace:
'app' => __DIR__.'/../app',
与:
'app' => __DIR__.'/../../yourlaravel4_base/app',
<小时>
在paths.php
文件中,替换:
In the paths.php
file, replace:
'public' => __DIR__.'/../public',
与:
'public' => __DIR__,
<小时>
在paths.php
文件中,替换:
In the paths.php
file, replace:
'base' => __DIR__.'/..',
与:
'base' => __DIR__.'/../../yourlaravel4_base',
<小时>
在 paths.php
中,替换:
In paths.php
, replace:
'storage' => __DIR__.'/../app/storage',
与:
'storage' => __DIR__.'/../../yourlaravel4_base/app/storage',
<小时>
在 index.php
中,替换:
In index.php
, replace:
require __DIR__.'/../bootstrap/autoload.php';
与:
require __DIR__.'/../../yourlaravel4_base/bootstrap/autoload.php';
<小时>
在 index.php
中,替换:
In index.php
, replace:
$app = require_once __DIR__.'/../bootstrap/start.php';
与:
$app = require_once __DIR__.'/../../yourlaravel4_base/bootstrap/start.php';
上传更改.现在你应该能够将 Laravel 4 安装在你网站的子文件夹中,而不会实际暴露 app/
文件夹和其他敏感文件.:)
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. :)
这篇关于如何在不公开/app/文件夹的情况下将 Laravel 4 安装到 Web 主机子文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!