将 Laravel 5 上传到服务器子文件夹 [英] Upload Laravel 5 to server subfolder
问题描述
我正在尝试将 Laravel 5 项目上传到子文件夹:
<块引用><块引用>public_html/project/
我在index.php里改了
需要 __DIR__.'/../project/bootstrap/autoload.php';$app = require_once __DIR__.'/../project/bootstrap/app.php';
在 config/app.php 中
'url' =>'http://example.com/project',
当我尝试 url 为:http://example.com/project/public 它被定向到http://example.com/public
上传到服务器的方法是什么.任何人都可以帮助我,因为我尝试了很多选项.
把你的整个 laravel 项目上传到 public_html (public) 文件夹不是一个好主意.公用文件夹中的文件具有不受限制的访问权限.
如果您因为想上传到共享主机而被限制考虑将 laravel 项目上传到 public_html 文件夹,那么没有必要这样做.
试试这个:
1. 在 public_html 文件夹的同一级别上创建一个名为 laravel 的文件夹(或任何你喜欢的文件夹).
例如:/|--变量|---www|----laravel|----public_html
2.从您的 laravel 项目中的 laravel
文件夹(在服务器主机上)复制除 public
文件夹之外的所有内容.
3. 打开你的 laravel 项目的 public 文件夹,复制所有内容并粘贴到 public_html
文件夹中(在服务器主机上)
4. 现在打开 public_html
文件夹中的 index.php
文件,然后:
更改:需要 __DIR__.'/../bootstrap/autoload.php';到:requrie 需要 __DIR__.'/../laravel/bootstrap/autoload.php';和改变:$app = require_once __DIR__.'/../bootstrap/app.php';到:$app = require_once __DIR__.'/../laravel/bootstrap/app.php';保存并关闭.
5.现在转到 laravel
文件夹并打开 server.php
文件
更改:require_once __DIR__.'/public/index.php';到:require_once __DIR__.'../public_html/index.php';保存并关闭.
现在,当您使用服务器访问配置为域的 url 时,您的 laravel 应用程序应该可以像在 localhost 上一样工作.
注意: config/app
中的 'url'=>'someurl'
是 artisan 即 cli 使用的,它对你的网络服务器网址.
希望能帮助到你.
编辑
完成上述操作后,如果您在尝试访问 url 时出现空白页面,请递归设置 storage 文件夹的写入权限.即 storage 及其子文件夹中的所有文件夹都应具有为 775
设置的权限网络服务器所有者和组拥有写入权限.
如果您不打算在存储文件夹中存储任何敏感信息,您还可以将权限设置为 777
以授予对存储文件夹的所有人的读取、写入和执行权限.
注意 linux 中的文件权限,它们就像一把双刃剑,如果使用不当,可能会使您的应用容易受到攻击.要了解 Linux 文件权限,您可以阅读 this
I am trying to upload Laravel 5 project to subfolder as:
public_html/project/
I have changed in index.php
require __DIR__.'/../project/bootstrap/autoload.php';
$app = require_once __DIR__.'/../project/bootstrap/app.php';
in config/app.php
'url' => 'http://example.com/project',
when I try url as: http://example.com/project/public it is directed to http://example.com/public
What is the way to upload it to server. Can anyone help me as I have tried lot options.
It is not a good idea to upload your entire laravel project in the public_html (public)folder. The files in the public folder are having unrestricted access.
If you are constrained to think about uploading the laravel project to the public_html folder because you want to upload to a shared host, then it is not necessary to do so.
Instead try this:
1. Create a folder called laravel (or anything you like) on the same level as the public_html folder.
Eg:
/
|--var
|---www
|----laravel
|----public_html
2. Copy every thing except the public
folder from your laravel project in the laravel
folder (on server host).
3. Open the public folder of your laravel project, copy everything and paste in the public_html
folder (on server host)
4. Now open the index.php
file in the public_html
folder and:
Change:
require __DIR__.'/../bootstrap/autoload.php';
To:
requrie require __DIR__.'/../laravel/bootstrap/autoload.php';
And
Change:
$app = require_once __DIR__.'/../bootstrap/app.php';
To:
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
Save and close.
5. Now go to the laravel
folder and open server.php
file
Change:
require_once __DIR__.'/public/index.php';
To:
require_once __DIR__.'../public_html/index.php';
Save and close.
Now when you visit the url which you configured as the domain with your server, your laravel app should work just as it worked on your localhost.
Note: The 'url'=>'someurl'
in the config/app
is used by artisan ie the cli, it does not have any effect on your webserver urls.
Hope it helps.
Edit
After completing the above if your get a blank page when you try to visit the url, set write permissions for the storage folder recursively .i.e all folders within the storage and its subfolders should have permissions 775
set for the webserver owner and group to have write permission.
You can also set the permissions as 777
to give read, write and execute access to all for the storage folder if you don't plan to store any sensitive information in the storage folder.
Be careful with the file permissions in linux, they are like double edged sword, if not used correctly, they may make your app vulnerable to attacks. For understanding Linux file permissions you can read this
这篇关于将 Laravel 5 上传到服务器子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!