skip to Main Content

How can a host a Laravel 5.6 app to cpanel on a shared hosting.

Can someone give me an idea

require __DIR__.'/../vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__.'/../bootstrap/app.php';

/*
#########my index.php file

7

Answers


  1. You have two methods available, one requiring ssh access. Under no circumstances do you put your entire Laravel directory into the public_html directory.

    SSH Access

    If you have SSH access you’ll want to do the following;

    • Log into your account and go to your home directory cd ~
    • Delete the public_html directory
    • Now you want to upload your Laravel app to ~/laravel
    • Now you need to recreate public_html as a symlink cd ~ && ln -s laravel/public public_html

    No SSH Access

    If you don’t have SSH access you’ll want to do the following;

    • Upload your laravel installation to somewhere like ~/laravel (above the public_html)
    • Copy the contents of the ~/laravel/public directory to public_html
    • Change the path to match your new destination

    Your new ~/public_html/index.php should look like the following;

    <?php
    
    /**
     * Laravel - A PHP Framework For Web Artisans
     *
     * @package  Laravel
     * @author   Taylor Otwell <[email protected]>
     */
    
    define('LARAVEL_START', microtime(true));
    
    /*
    |--------------------------------------------------------------------------
    | Register The Auto Loader
    |--------------------------------------------------------------------------
    |
    | Composer provides a convenient, automatically generated class loader for
    | our application. We just need to utilize it! We'll simply require it
    | into the script here so that we don't have to worry about manual
    | loading any of our classes later on. It feels great to relax.
    |
    */
    
    require __DIR__.'/../laravel/vendor/autoload.php';
    
    /*
    |--------------------------------------------------------------------------
    | Turn On The Lights
    |--------------------------------------------------------------------------
    |
    | We need to illuminate PHP development, so let us turn on the lights.
    | This bootstraps the framework and gets it ready for use, then it
    | will load up this application so that we can run it and send
    | the responses back to the browser and delight our users.
    |
    */
    
    $app = require_once __DIR__.'/../laravel/bootstrap/app.php';
    
    /*
    |--------------------------------------------------------------------------
    | Run The Application
    |--------------------------------------------------------------------------
    |
    | Once we have the application, we can handle the incoming request
    | through the kernel, and send the associated response back to
    | the client's browser allowing them to enjoy the creative
    | and wonderful application we have prepared for them.
    |
    */
    
    $kernel = $app->make(IlluminateContractsHttpKernel::class);
    
    $response = $kernel->handle(
        $request = IlluminateHttpRequest::capture()
    );
    
    $response->send();
    
    $kernel->terminate($request, $response);
    
    Login or Signup to reply.
  2. after googling around i found that you have to take content of public folder which has index.php file and put it in public_html. now we have to change the content of index.php file i.e just provide the right link of app.php and autoload.php which would be require __DIR__.'/<project_folder_name>/vendor/autoload.php' and $app = require_once __DIR__.'/<project_folder_name>/bootstrap/app.php'; also update your .env file and check it should work if it doesnt you have to clear cache and routes using php artisan cache:clear and php artisan route:clear you can do this using ssh or define the function in web.php and then hitting the link

    Login or Signup to reply.
  3. An easy way if your shared hosting team is very supportive for you,
    Upload your files to public_html folder, and then incase if you donot have ssh access to server, contact your hosting team and ask them to point your domain name to public_html/public folder as root folder.
    And then ask them to execute following command via ssh

    composer install
    

    If you want to boost the peformance, please provide them the four commands listed in the following article.

    https://www.techalyst.com/links/read/112/boosting-laravel-performance-in-production-server

    Login or Signup to reply.
  4. Umm. Shared hosting does NOT support php 7, which larave 5.6 depends on. Have you guys found a workaround. I have been stuck for months with laravel 4.x on bluehost.

    Login or Signup to reply.
  5. Laravel 5.6 requires PHP 7.

    First check your shared hosting support PHP 7 in Cpanel (PHP Selector), if yes but you have other projects which PHP 5 and you don’t want to change default php version, then use this in .htaccess file

    For example: public_html/abc/.htaccess

    RewriteEngine on
    AddHandler application/x-httpd-php71 .php
    

    Then PHP 7 Work and you can work with Laravel 5.6 on shared hosting

    Login or Signup to reply.
  6. laravel -> all laravel file
    
    public_html -> move all folder & file on *public* file laravel to *public_html*
    
    change your index.php on public html
    require __DIR__.'/../laravel/vendor/autoload.php';
    $app = require_once __DIR__.'/../laravel/bootstrap/app.php';
    

    don’t forget to change your php version to 7.2

    Login or Signup to reply.
  7. The simplest way to host on shared hosting

    1. Create a subdomain on hosting and map it to a folder e.g: "abc"
    2. In folder "abc" upload laravel project zip (with vendor folder) then extract it
    3. Map subdomain to the public folder of laravel i.e. "abc/public".
    4. Create a database & user and assign that user to the database with all privileges
    5. Import the DB dump in the database created above.
    6. Add DB user/password in laravel .env file.

    Note: If you face any due to cache remove file config.php in directory bootstrap/cache.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search