问题
I need to deploy a laravel 5 project to a client host.
The plan of my client is basic hosting: Linux + MySql without cpanel or similar (i.e. no admin panel).
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).
One year ago, I deployed a project made with Laravel 4 this way:
- got rid of public folder moving its content to root folder and updating index.php and bootstrap.php
- finished whole project in localhost (with Xampp)
- uploaded all files to www.myclientweb.com via ftp.
My questions are:
Did I do everything all right with laravel 4 project? May I have fallen into security issues (I mean, is the site safe)?
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.
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:
- I can see wellcoming page of laravel at http://www.myclientweb.com/public.
- I can not see anything at http://www.myclientweb.com/
- And also I CAN SEE .env CONTENT AT http://www.myclientweb.com/.env ???????
Surely this is not the right way...
I've had a long searching through the web and Stackoverflow with no luck.
Really apprecite any help.
Thanks for reading.
回答1:
There is no difference between L4 and L5, so do the same thing you did for L4.
回答2:
- I create a new folder named "protected"
- Move all except "public" folder into "protected" folder
- Move all inside "public" folder to root
- Edit index.php in root folder(from public folder),
edit require __DIR__.'/../bootstrap/autoload.php';
into require __DIR__.'/protected/bootstrap/autoload.php';
also edit $app = require_once __DIR__.'/../bootstrap/app.php';
into $app = require_once __DIR__.'/protected/bootstrap/app.php';
回答3:
UPDATE
This is a risky process. By using this, you give malicious users permissions to find bugs. like, http://project-url/storage/logs/laravel.log is 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:
- move every file in public to parent folder.
- update paths in index.php.
- add the following line to .htaccess:
RewriteRule ^(server\.php|gulpfile\.js|\.env|composer.*|package.*) - [F,L,NC]
回答4:
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:
http://mywebsite.com/mylaravel/
So this answer is for you, first of all make sure you meet
Laravel 5.1 requirements :
- PHP 5.5
- PHP extension Mcrypt
- PHP extension Mbstring
- PHP extension OpenSSL
Here two tutorials for you :
Link 1
Link 2
回答5:
In Apache, you can achieve this something like
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/$1 [L]
来源:https://stackoverflow.com/questions/29403554/deploy-laravel-5-using-only-ftp-in-a-shared-hosting