While it's possible to install Laravel automatically using hPanel, you might want to have a version that is not in the list. Keep in mind, that it's always recommended to have the current stable version installed to avoid any security threats or bugs.

If you still choose Laravel 8, you should proceed with a manual installation:

  1. Add the website to your hosting plan

  2. Upload Laravel files and move them to the correct directories

  3. Update index.php and .htaccess

  4. Update database information


Step 1 - Add the website

If you haven't done it yet, activate your hosting account and add a domain on which you want to have Laravel.

Step 2 - Upload and move files

Using any suitable option, upload your Laravel website's files to the website's files, 1 level above public_html. If your project is named laravel, your files structure will look like this:

After this, open laravel/public/ folder and move all files from it to public_html:

After the move, the files structure of public_html should look like this:

Step 3 - Edit the index and .htaccess files

Now, we need to edit the index.php file, so that Laravel understands the new files structure. Open the file and replace its content with the following:

<?php
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';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);

So that Laravel loads content correctly, open .htaccess file and add this code to it:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

If your website uses databases/models, then you should see a Laravel Database connection error at this point. We'll fix it in the next step.

Step 4 - Update database information

If Models are running on your application, then you have to migrate tables to the database. We'll use sqlite database for that.

In the file manager, open laravel/database/ and create database.sqlite file. Then, open laravel/.env file and update your database information. Just copy the path to your root directory and change public_html to laravel/database/database.sqlite. It should look like this:

Then, using SSH in your laravel directory, migrate all the files to a database:

php artisan migrate

That's it, your Laravel 8 website should work now 🎉

NOTE:

  • If you want to set up an artisan cronjob for scheduling actions of your application, just create a custom cronjob using this code template in hPanel:

    /usr/bin/php /home/u12345678/domains/domain.tld/public_html/artisan schedule:run


    where u12345678 and domain.tld are replaced with your data

Did this answer your question?