php 在共享主机中仅使用 FTP 部署 Laravel 5

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29403554/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:23:19  来源:igfitidea点击:

Deploy Laravel 5 using only FTP in a shared hosting

phplaravelftplaravel-5shared-hosting

提问by Andrew F.

I need to deploy a laravel 5 project to a client host.

我需要将 Laravel 5 项目部署到客户端主机。

The plan of my client is basic hosting: Linux + MySql without cpanel or similar (i.e. no admin panel).

我的客户的计划是基本托管:Linux + MySql 没有 cpanel 或类似的(即没有管理面板)。

I have access only via ftp and only to a folder named www.mycustomerweb.com. It means I can not create a directory at the same level of www.mycustomerweb.com folder. Only inside it (I think it is called shared hosting).

我只能通过 ftp 访问,并且只能访问名为 www.mycustomerweb.com 的文件夹。这意味着我无法在 www.mycustomerweb.com 文件夹的同一级别创建目录。只有在里面(我认为它被称为共享托管)。

One year ago, I deployed a project made with Laravel 4 this way:

一年前,我以这种方式部署了一个用 Laravel 4 制作的项目:

  1. got rid of public folder moving its content to root folder and updating index.php and bootstrap.php
  2. finished whole project in localhost (with Xampp)
  3. uploaded all files to www.myclientweb.com via ftp.
  1. 摆脱了公共文件夹将其内容移动到根文件夹并更新 index.php 和 bootstrap.php
  2. 在本地主机中完成整个项目(使用 Xampp)
  3. 通过 ftp 将所有文件上传到 www.myclientweb.com。

My questions are:

我的问题是:

  1. Did I do everything all right with laravel 4 project? May I have fallen into security issues (I mean, is the site safe)?

  2. How do I deploy a laravel 5 project to the same site? In Laravel 5 I can not get rid of public folder as I did with Laravel 4.

  1. 我对 Laravel 4 项目做的一切都好吗?我是否陷入了安全问题(我的意思是,该站点是否安全)?

  2. 如何将 Laravel 5 项目部署到同一个站点?在 Laravel 5 中,我无法像在 Laravel 4 中那样摆脱公共文件夹。

Right now, I have set up a fresh installation of Laravel 5 on localhost and then I have uploaded all files to www.myclientweb.com folder via ftp:

现在,我已经在本地主机上全新安装了 Laravel 5,然后通过 ftp 将所有文件上传到 www.myclientweb.com 文件夹:

Surely this is not the right way...

这当然不是正确的方法......

I've had a long searching through the web and Stackoverflow with no luck.

我在网上和 Stackoverflow 上搜索了很长时间,但没有运气。

Really apprecite any help.

真的很感激任何帮助。

Thanks for reading.

谢谢阅读。

采纳答案by Karwan Hymansi

There is no difference between L4 and L5, so do the same thing you did for L4.

L4 和 L5 之间没有区别,所以对 L4 做同样的事情。

回答by Agung Kessawa

  1. I create a new folder named "protected"
  2. Move all except "public" folder into "protected" folder
  3. Move all inside "public" folder to root
  4. Edit index.php in root folder(from public folder),
  1. 我创建了一个名为“protected”的新文件夹
  2. 将除“public”文件夹以外的所有文件夹移动到“protected”文件夹中
  3. 将“public”文件夹中的所有内容移至根目录
  4. 编辑根文件夹中的 index.php(来自公共文件夹),

edit require __DIR__.'/../bootstrap/autoload.php';into require __DIR__.'/protected/bootstrap/autoload.php';

编辑require __DIR__.'/../bootstrap/autoload.php';require __DIR__.'/protected/bootstrap/autoload.php';

also edit $app = require_once __DIR__.'/../bootstrap/app.php';into $app = require_once __DIR__.'/protected/bootstrap/app.php';

也编辑$app = require_once __DIR__.'/../bootstrap/app.php';$app = require_once __DIR__.'/protected/bootstrap/app.php';

回答by ssi-anik

UPDATE
This is a risky process. By using this, you give malicious users permissions to find bugs. like, http://project-url/storage/logs/laravel.logis still open.


Previous Answer:
Those who hardly check the comments, @Andrew F. has already given the answer.
but he missed some other files like composer and package.
Formatted answer is:

更新
这是一个冒险的过程。通过使用它,您可以授予恶意用户查找错误的权限。就像,http://project-url/storage/logs/laravel.log仍然打开。


上一个答案:
那些几乎不看评论的人,@Andrew F. 已经给出了答案。
但他错过了其他一些文件,如 composer 和 package.json 。
格式化的答案是:

  1. move every file in public to parent folder.
  2. update paths in index.php.
  3. add the following line to .htaccess:
    RewriteRule ^(server\.php|gulpfile\.js|\.env|composer.*|package.*) - [F,L,NC]
  1. 将公共中的每个文件移动到父文件夹。
  2. 更新 index.php 中的路径。
  3. 将以下行添加到 .htaccess:
    RewriteRule ^(server\.php|gulpfile\.js|\.env|composer.*|package.*) - [F,L,NC]

回答by Mohamed Salem Lamiri

If you are trying to run Laravel 5.1 into a shared hosting space or you are trying to put your laravel 5/5.1 into a sub directory on your shared hosting so you can access it like this:

如果您尝试将 Laravel 5.1 运行到共享主机空间,或者您尝试将 Laravel 5/5.1 放入共享主机的子目录中,以便您可以像这样访问它:

http://mywebsite.com/mylaravel/

So this answer is for you, first of all make sure you meet

所以这个答案是给你的,首先确保你满足

Laravel 5.1 requirements :

Laravel 5.1 要求:

- PHP 5.5
- PHP extension Mcrypt
- PHP extension Mbstring
- PHP extension OpenSSL

Here two tutorials for you :

这里有两个教程给你:

Link 1

链接 1

Link 2

链接 2

回答by HARENDRA SINGH

In Apache, you can achieve this something like

在 Apache 中,您可以实现类似

    RewriteEngine on
    RewriteBase /

  # Rewrites all URLS without blog in them
    RewriteCond %{REQUEST_URI} !^/blog/

  # Rewrites all URLS [Replace "example" with the actual domain, without the TLD (.com, .net, .biz, etc)]
    RewriteCond %{HTTP_HOST} ^(www\.)?example\.

  # Rewrite all those to insert /folder
    RewriteRule ^(.*)$ /blog/ [L]