Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy Laravel 5 using only FTP in a shared hosting

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:

  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.

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.

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.

like image 794
Andrew F. Avatar asked Apr 02 '15 01:04

Andrew F.


People also ask

Can I deploy laravel on shared hosting?

Q: How to deploy Laravel on shared hostingDo ZIP your Laravel project. Create a database in your cPanel. Import the local exported database into the shared hosting database. Upload project ZIP file to public_html folder and extract.


3 Answers

  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),

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';

like image 148
Agung Kessawa Avatar answered Oct 21 '22 17:10

Agung Kessawa


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:

  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]
like image 20
ssi-anik Avatar answered Oct 21 '22 17:10

ssi-anik


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

like image 33
Karwan Jacksi Avatar answered Oct 21 '22 16:10

Karwan Jacksi