Setup Laravel 4 in Shared Hosting with securing Laravel base file

You may wonder how to setup PHP Laravel 4 in shared hosting server

Posted by Xambitt on April 19, 2014
  1. Assume that you have file structure something like this:-

    1
    
     /home/username/public_html
    
  2. Create new folder outside public_html:-

    1
    
     /home/username/main-laravel
    
  3. Move all the main file of Laravel (app, boostrap, vendor, composer.json, composer.lock, phpunit.xml etc) into that folder (step 1) except Public folder
  4. Open /home/username/main-laravel/bootstrap/paths.php and edit to look like this:-

    • replace 'app' => __DIR__.'/../app', to 'app' => __DIR__.'/../../main-laravel/app',
    • replace 'public' => __DIR__.'/../public', to 'public' => __DIR__.'/../../public_html/laravel',
    • replace 'base' => __DIR__.'/..', to 'base' => __DIR__.'/../../main-laravel',
    • replace 'storage' => __DIR__.'/../app/storage', to 'storage' => __DIR__.'/../../main-laravel/app/storage',

      Then SAVE

  5. Now create a new folder inside public_html

    1
    
     /home/username/public_html/laravel
    
  6. Now, move all the content in public folder of Laravel into that folder (step 4)
  7. Open /home/username/public_html/laravel/index.php and edit to look like this:-

    • replace require __DIR__.'/../bootstrap/autoload.php'; to require __DIR__.'/../../main-laravel/bootstrap/autoload.php';
    • replace $app = require_once __DIR__.'/../bootstrap/start.php'; to $app = require_once __DIR__.'/../../main-laravel/bootstrap/start.php';

      Then SAVE

  8. Now create .htaccess in /home/username/public_html and insert this code:-

    1
    2
    3
    
     RewriteEngine on
     RewriteCond %{REQUEST_URI} !^laravel
     RewriteRule ^(.*)$ laravel/$1 [L]
    

    Then SAVE

Now, your laravel website can be access at http://[username].com