Skip to main content
All CollectionshPanelInstalling Applications
How to Deploy Laravel 8 at Hostinger
How to Deploy Laravel 8 at Hostinger

Deploying Laravel 8 on Web and Cloud hosting at Hostinger

Updated over 3 months ago

While it's possible to install Laravel automatically, you might want a version that is not on 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:

Step 1 - Preparations

Before starting, you will need to activate your hosting plan and add a domain on which you want to have Laravel.

Step 2 - Upload and Move the 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 file structure will look like this:

The File Manager showing the structure of a laravel project

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

The Move files window indicating to move to public_html

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

The File Manager showing the Laravel files on public_html folder

Step 3 - Edit the index.php and .htaccess Files

Open the index.php file on the File Manager and replace its content with the following. This will make Laravel understand the new file structure:

<?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);

Next, open the .htaccess file and add the following rule so that Laravel loads content correctly:

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

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

Step 4 - Update Database Information

If Models are running on your application, you will have to migrate tables to the database. You have two alternatives:

MySQL

To use MySQL, start by creating a new database. Next, open the .env file and update your database information. It should look like this:

The File Manager showing a .env file with data to connect a MySQL database

SQLITE

If you want to use SQLITE, go to the File Manager, navigate to laravel/database/, and create the database.sqlite file. Next, open the 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:

Migrate the Tables

Once you have created the database with either method, connect to your account via SSH, navigate to your laravel directory, and enter the following command to migrate all the files to a database:

php artisan migrate

That's it. Your Laravel 8 website should work now 😊

NOTE

  • To set up an artisan cronjob for scheduling actions of your application, create a custom cronjob using this code template:

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


    Replacing u12345678 and domain.tld with your data.

Additional Resources

Did this answer your question?