Running Laravel on Shared Hosting PHP Apache and cPanel

Laravel

Method 1 - Install Laravel using Composer on shared hosting 

The procedure for installing Laravel 5 on shared hosting with Apache and cPanel

  1. Connect to hosting via SSH

  2. Install Composer

  3. In cPanel open Select PHP version and choose 5.4. (I also set phar extension)

  4. Install Laravel

    php composer.phar create-project laravel/laravel myproject --prefer-dist
  5. Copy everything from myproject/public to public_html

  6. open public_html/index.php and set:

    require DIR.'/../myproject/bootstrap/autoload.php';

    $app = require_once DIR.'/../myproject/bootstrap/start.php';

Also, add this to the top of index.php:

ini_set('eaccelerator.enable', 0);

Method 2 - copy Laravel install to shared hosting

I've tried it on my shared hosting. Here's what I did.

  1. Install and setup Laravel on your local (meaning your local machine)

  2. Once done, copy all files to your hosting.

  3. Create a .htaccess file on your Laravel's root directory. This is to access it without the "public" on the URL.


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

Method 3 - Bluehost Laravel shared hosting

  1. Setup a project Laravel 5 in localhost correctly configured
  2. Double check the server configuration of PHP 5.4
    1. This is because every little change on .htaccess file may change that config
  3. Create a directory in the same level of public_html and put the project inside of that folder.
  4. Put the content of public (Laravel 5) directly on public_html (be aware of not overwriting the .htaccess file accidentally)

Now... This is the "tricky part"... actually not xD In Bluehost I see this structure

  • mail
  • perl5
  • php
  • public_html
  • [framework-folder]
  • ssl

Inside of public_html I can see all the files of public directory of Laravel 5

Go to index.php and edit the line 22

#From this
require __DIR__.'/../bootstrap/autoload.php';
#To this
require __DIR__.'/../[framework-folder]/bootstrap/autoload.php';

And the line 36

#From this 
$app = require_once __DIR__.'/../bootstrap/app.php';
#To this
$app = require_once __DIR__.'/../[framework-folder]/pulcro/bootstrap/app.php';

The final step is to edit the .htaccess file and add some lines

RewriteEngine On
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_URI} !^
RewriteRule ^(.*)$ /$1 [L]

Refresh the cache of my browser and.. Victory!!

I know that this is not the absolute right way to install the framework (God, I never spoke about Composer)

 

Source: Laravel.io

 

 

Visit sunny St. George, Utah, USA