将 Laravel 5 上传到服务器子文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35461322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Upload Laravel 5 to server subfolder
提问by K M Chaudhary
I am trying to upload Laravel 5 project to subfolder as:
我正在尝试将 Laravel 5 项目上传到子文件夹:
public_html/project/
public_html/项目/
I have changed in index.php
我在 index.php 中改变了
require __DIR__.'/../project/bootstrap/autoload.php';
$app = require_once __DIR__.'/../project/bootstrap/app.php';
in config/app.php
在 config/app.php
'url' => 'http://example.com/project',
when I try url as: http://example.com/project/publicit is directed to http://example.com/public
当我尝试 url 为:http: //example.com/project/public它被定向到 http://example.com/public
What is the way to upload it to server. Can anyone help me as I have tried lot options.
上传到服务器的方法是什么?任何人都可以帮助我,因为我尝试了很多选择。
回答by Donkarnash
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.
将整个 Laravel 项目上传到 public_html (public) 文件夹中并不是一个好主意。公用文件夹中的文件具有不受限制的访问权限。
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.
如果你因为要上传到共享主机而被限制考虑将laravel项目上传到public_html文件夹,那么就没有必要这样做了。
而是试试这个:
1. 在与 public_html 文件夹相同的级别上创建一个名为 laravel(或任何你喜欢的东西)的文件夹。
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:
2. 复制除public
laravel 项目中laravel
文件夹(在服务器主机上)中的文件夹之外的所有内容。
3. 打开 Laravel 项目的公共文件夹,复制所有内容并粘贴到public_html
文件夹中(在服务器主机上)
4. 现在打开index.php
文件public_html
夹中的文件,然后:
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
5.现在转到laravel
文件夹并打开server.php
文件
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.
现在,当您访问配置为服务器域的 url 时,您的 Laravel 应用程序应该可以像在本地主机上一样工作。
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.
注意:'url'=>'someurl'
inconfig/app
由工匠即 cli 使用,它对您的网络服务器 url 没有任何影响。
希望能帮助到你。
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.
编辑
完成上述操作后,如果您尝试访问 url 时出现空白页面,请递归设置存储文件夹的写入权限。即存储中的所有文件夹及其子文件夹都应具有775
为网络服务器所有者和组设置的写入权限允许。
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.
777
如果您不打算在存储文件夹中存储任何敏感信息,您还可以将权限设置为授予对存储文件夹的所有读取、写入和执行访问权限。
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
小心linux中的文件权限,它们就像双刃剑,如果使用不当,可能会使您的应用程序容易受到攻击。要了解 Linux 文件权限,您可以阅读此内容
回答by Hemant Kumar
Issue Fixed:-
问题已修复:-
Go to laravelFolder/bootstrap/cache then rename config.php eg. config.php_old and reload your site.
转到 laravelFolder/bootstrap/cache 然后重命名 config.php 例如。config.php_old 并重新加载您的网站。
回答by K M Chaudhary
After I completed the above steps. Do check with read/write permissions(i.e it should be 777) for few folcers:
在我完成上述步骤之后。请检查读/写权限(即它应该是 777)的几个 folcer:
storage, vendor and bootstrap>cache
存储、供应商和引导>缓存
Check for .htaccess file if it is there in the public_html folder or copy it from public folder.
检查 .htaccess 文件是否在 public_html 文件夹中或从 public 文件夹中复制它。
Finally check the version of php it should be higher than 5.5
最后检查php的版本应该高于5.5
It worked for me. Cheers!!
它对我有用。干杯!!
回答by vimuth
I did like this. (My version was laravel 5.2)
我就是这样的。(我的版本是 laravel 5.2)
- Change the name of server.php file to 'index.php'.
- Copy .htaccess file from public folder to main directory(Created subfolder)
- And inside .htaccess after RewriteEngine Onwe have to add RewriteBase /yoursubfolder/
- 将 server.php 文件的名称更改为“index.php”。
- 将 .htaccess 文件从公共文件夹复制到主目录(创建子文件夹)
- 在RewriteEngine On之后的 .htaccess 中,我们必须添加 RewriteBase /yoursubfolder/