将 Laravel 项目上传到 Web 服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22075238/
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
Uploading Laravel Project onto Web Server
提问by Sainath Krishnan
I am trying to upload my Laravel project onto my web server, but my past two attempts have been unsuccessful. I believe I am not uploading the files to the right location.
我正在尝试将我的 Laravel 项目上传到我的网络服务器,但我过去的两次尝试都没有成功。我相信我没有将文件上传到正确的位置。
This is my web server's structure ->
这是我的 Web 服务器的结构 ->
Am I correct to say that I need to upload ALL of my laravel files into public_html?
我说我需要将所有 Laravel 文件上传到 public_html 是否正确?
This is my Laravel project's directory :
这是我的 Laravel 项目的目录:
EDIT : I have now added all the files onto the root folder, and public into public_html, however none of my routes seem to work. (They work perfectly on localhost). Everything throws a 404
编辑:我现在已将所有文件添加到根文件夹中,并将 public 添加到 public_html 中,但是我的路由似乎都不起作用。(它们在本地主机上完美运行)。一切都会抛出 404
采纳答案by alexrussell
No, but you have a couple of options:
不,但您有几个选择:
The easiest is to upload all the files you have into that directory you're in (i.e. the cPanel user home directory), and put the contents of public into public_html. That way your directory structure will be something like this (slightly messy but it works):
最简单的方法是将您拥有的所有文件上传到您所在的目录(即cPanel 用户主目录),并将public 的内容放入public_html。这样你的目录结构就会是这样的(有点乱,但它有效):
/
.composer/
.cpanel/
...
app/ <- your laravel app directory
etc/
bootstrap/ <- your laravel bootstrap directory
mail/
public_html/ <- your laravel public directory
vendor/
artisan <- your project's root files
You may also need to edit bootstrap/paths.php
to point at the correct public directory.
您可能还需要编辑bootstrap/paths.php
以指向正确的公共目录。
The other solution, if you don't like having all these files in that 'root' directory would be to put them in their own directory (maybe 'laravel') that's still in the root directory and then edit the paths to work correctly. You'll still need to put the contents of public
in public_html
, though, and this time edit your public_html/index.php
to correctly bootstrap the application. Your folder structure will be a lot tidier this way (though there could be some headaches with paths due to messing with the framework's designed structure more):
另一个解决方案,如果您不喜欢将所有这些文件都放在那个“根”目录中,那么将它们放在它们自己的目录(可能是“laravel”)中,该目录仍然在根目录中,然后编辑路径以使其正常工作。不过,您仍然需要将public
in的内容放入public_html
,这次编辑您的内容public_html/index.php
以正确引导应用程序。通过这种方式,您的文件夹结构将更加整洁(尽管由于与框架的设计结构更加混乱,路径可能会有些麻烦):
/
.composer/
.cpanel/
...
etc/
laravel/ <- a directory containing all your project files except public
app/
bootstrap/
vendor/
artisan
mail/
public_html/ <- your laravel public directory
回答by Raj Sf
I believe - your Laravel files/folders should not be placed in root directory.
我相信 - 你的 Laravel 文件/文件夹不应该放在根目录中。
e.g. If your domain is pointed to public_html
directory then all content should placed in that directory. How ? let me tell you
例如,如果您的域指向public_html
目录,则所有内容都应放在该目录中。如何 ?让我告诉你
- Copy all files and folders ( including public folder ) in public html
- Copy all content of public folder and paste it in document root ( i.e. public_html )
- Remove the public folder
Open your bootstrap/paths.php and then changed
'public' => __DIR__.'/../public',
into'public' => __DIR__.'/..',
and finally in index.php,
Change
- 复制公共 html 中的所有文件和文件夹(包括公共文件夹)
- 复制 public 文件夹的所有内容并将其粘贴到文档根目录(即 public_html )
- 删除公用文件夹
打开你的引导/ paths.php再变
'public' => __DIR__.'/../public',
到'public' => __DIR__.'/..',
最后在 index.php 中,
改变
require __DIR__.'/../bootstrap/autoload.php'; $app = require_once __DIR__.'/../bootstrap/start.php';
require __DIR__.'/../bootstrap/autoload.php'; $app = require_once __DIR__.'/../bootstrap/start.php';
into
进入
require __DIR__.'/bootstrap/autoload.php'; $app = require_once __DIR__.'/bootstrap/start.php';
require __DIR__.'/bootstrap/autoload.php'; $app = require_once __DIR__.'/bootstrap/start.php';
Your Laravel application should work now.
你的 Laravel 应用程序现在应该可以工作了。
回答by Abhinandan N.M.
If you are trying to host your Laravel app on a shared hosting, this may help you.
如果您尝试在共享主机上托管 Laravel 应用程序,这可能对您有所帮助。
Hosting Laravel on shared hosting #1
Hosting Laravel on shared hosting #2
If you want PHP 5.4 add this line to your .htaccess
file or call your hosting provider.
如果您想要 PHP 5.4,请将此行添加到您的.htaccess
文件中或致电您的托管服务提供商。
AddType application/x-httpd-php54 .php
AddType application/x-httpd-php54 .php
回答by Overcomer
Had this problem too and found out that the easiest way is to point your domain to the public folder and leave everything else the way they are.
也有这个问题,并发现最简单的方法是将您的域指向公共文件夹,并保持其他所有内容不变。
PLEASE ENSURE TO USE THE RIGHT VERSION OF PHP. Save yourself some stress :)
请确保使用正确版本的 PHP。为自己节省一些压力:)
回答by M.A. Heshmat Khah
In Laravel 5.x there is no paths.php
在 Laravel 5.x 中没有 paths.php
so you should edit public/index.php
and change this lines in order to to pint to your bootstrap
directory:
所以你应该编辑public/index.php
和更改这一行,以便品脱到你的bootstrap
目录:
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
for more information you can read thisarticle.
有关更多信息,您可以阅读这篇文章。
回答by Miroslav Trninic
All of your Laravel files should be in one location. Laravel is exposing its publicfolder to server. That folder represents some kind of front-controller to whole application. Depending on you server configuration, you have to point your server path to that folder. As I can see there is wwwsite on your picture. wwwis default root directory on Unix/Linux machines. It is best to take a look inside you server configuration and search for root directory location. As you can see, Laravel has already file called .htaccess, with some ready Apache configuration.
你所有的 Laravel 文件都应该在一个位置。Laravel 将其公共文件夹暴露给服务器。该文件夹代表了整个应用程序的某种前端控制器。根据您的服务器配置,您必须将服务器路径指向该文件夹。正如我所看到的,您的图片上有www站点。www是 Unix/Linux 机器上的默认根目录。最好查看您的服务器配置并搜索根目录位置。如您所见,Laravel 已经有一个名为.htaccess 的文件,其中包含一些现成的 Apache 配置。