将Laravel 5上传到服务器子文件夹 [英] Upload Laravel 5 to server subfolder

查看:105
本文介绍了将Laravel 5上传到服务器子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Laravel 5项目上传为子文件夹,如下所示:

public_html/project/

我已更改index.php

require __DIR__.'/../project/bootstrap/autoload.php';
$app = require_once __DIR__.'/../project/bootstrap/app.php';

在config/app.php

'url' => 'http://example.com/project',

当我尝试使用以下网址时: http://example.com/project/public 指向 http://example.com/public

将其上传到服务器的方式是什么.我尝试过很多选择,谁能帮助我.

解决方案

将整个laravel项目上载到public_html(公共)文件夹不是一个好主意.公用文件夹中的文件具有不受限制的访问.

如果由于要上传到共享主机而不得不考虑将laravel项目上传到public_html文件夹,则不必这样做.
相反,请尝试以下操作:
1.在与public_html文件夹相同的级别上创建一个名为laravel的文件夹(或您喜欢的任何文件).

Eg:  
/
 |--var  
    |---www
        |----laravel
        |----public_html  

2.将laravel项目中除public文件夹之外的所有内容复制到laravel文件夹中(在服务器主机上).
3.打开laravel项目的公用文件夹,复制所有内容并粘贴到public_html文件夹(在服务器主机上)
4.现在打开public_html文件夹中的index.php文件,然后:

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.现在转到laravel文件夹并打开server.php文件

Change:  
require_once __DIR__.'/public/index.php';  
To:  
require_once __DIR__.'../public_html/index.php'; 
Save and close. 

现在,当您访问在服务器上配置为域的URL时,laravel应用程序应该可以正常运行,就像在本地主机上一样.

注意:config/app中的'url'=>'someurl'由工匠使用,即cli,它对您的Web服务器网址没有任何影响.
希望能帮助到你.

修改
完成上述操作后,如果在尝试访问url时出现空白页,请递归设置存储文件夹的写权限.即,存储及其子文件夹中的所有文件夹均应为Web服务器所有者和组的权限设置为775,有写权限.

如果您不打算在存储文件夹中存储任何敏感信息,还可以将权限设置为777,以授予对存储文件夹全部的读取,写入和执行访问权限.

请注意linux中的文件权限,它们就像一把双刃剑,如果使用不正确,它们可能会使您的应用容易受到攻击.要了解Linux文件权限,您可以阅读

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屋!

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