Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload Laravel 5 to server subfolder

I am trying to upload Laravel 5 project to subfolder as:

public_html/project/

I have changed in index.php

require __DIR__.'/../project/bootstrap/autoload.php';
$app = require_once __DIR__.'/../project/bootstrap/app.php';

in config/app.php

'url' => 'http://example.com/project',

when I try url as: http://example.com/project/public it is directed to http://example.com/public

What is the way to upload it to server. Can anyone help me as I have tried lot options.

like image 603
K M Chaudhary Avatar asked Feb 17 '16 15:02

K M Chaudhary


2 Answers

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.

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.

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:

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

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.

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.

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.

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.

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

like image 68
Donkarnash Avatar answered Sep 20 '22 20:09

Donkarnash


After I completed the above steps. Do check with read/write permissions(i.e it should be 777) for few folcers:

storage, vendor and bootstrap>cache

Check for .htaccess file if it is there in the public_html folder or copy it from public folder.

Finally check the version of php it should be higher than 5.5

It worked for me. Cheers!!

like image 38
K M Chaudhary Avatar answered Sep 20 '22 20:09

K M Chaudhary