When I was looking to deploy a Laravel project on Hostinger shared hosting, I found that there was no proper guide available on the internet. So I decided to write a step-by-step guide on how to host a Laravel project on Hostinger shared hosting. I hope this will help someone who is looking to host a Laravel project on Hostinger shared hosting.
As Hostinger's shared hosting does not provide the same functionalities as a VPS or Dedicated Server, so there are some limitations. However, I have tried to overcome those limitations and make the Laravel project work on Hostinger shared hosting.
Following is working:
- Host Laravel 10 & 11 Project on Hostinger's Shared Hosting
- Does not have to move any files from Laravel's Public folder
- Working Storage link functionality.
-
Create a new website on Hostinger's hPanel: Add your domain to create a new website.
-
Create a new MySQL database on Hostinger's hPanel: Also create a new user, assign the user to the database, and note down the database name, username, and password.
-
Navigate to the root directory of your website: Use the File Manager on Hostinger's hPanel to go to the root directory of your website.
-
Delete all files and folders in the root directory: This includes
public_html
andDO_NOT_UPLOAD_HERE
. -
Optimize your Laravel Project for Production: Optimize the project and make it ready for deployment to production as per the official Laravel documentation.
-
Upload your Laravel project: After doing all the required steps upload all files and folders of your Laravel project to the root directory of your website.
-
Get SSH access to your website: SSH access is available on Hostinger's hPanel. Get SSH access and use Windows PowerShell, PuTTY, or any other SSH client to connect to your website via the SSH terminal.
-
Setup .env file: In a Laravel Project the
.env
file holds all the configuration variables. You can either create a new.env
file or rename the.env.example
file to.env
. You can also upload your local.env
file if you have already. After that open the.env
file and modify the following variables:APP_URL
: Set this to the URL of your website.DB_HOST
: Set this to the hostname of your database server. This is usuallylocalhost
.DB_PORT
: Set this to the port of your database server. This is usually3306
.DB_DATABASE
: Set this to the name of your database.DB_USERNAME
: Set this to the username of your database user.DB_PASSWORD
: Set this to the password of your database user.APP_ENV
: Set this toproduction
, this will optimize your Laravel project for production.APP_DEBUG
: Set this tofalse
, this will disable debug mode.
-
Migrating the Database: After getting SSH access to your website, navigate to the root directory of your website and run the following command:
php artisan migrate
This will migrate the database and create all the required tables if database migrations are available in your Laravel project and you have configured the
.env
file correctly with required database credentials. -
Rename the Public folder: The uploaded Public folder should be renamed to
public_html
. -
Open the filesystems.php file: This file is located in the config folder of your Laravel project.
-
Modify the
Symbolic Links
section: Change the following line in thefilesystems.php
file:'links' => [ public_path('storage') => storage_path('app/public'), ],
to
'links' => [ base_path('public_html/storage') => storage_path('app/public'), ],
-
Open SSH terminal and go to the root directory of your website
-
Run the following command:
php artisan storage:link
After that clear all the cache and config by running the following command:
php artisan optimize:clear
-
Cache the routes, views, config and routes by running the following command:
php artisan optimize
-
Have a running Laravel project on Hostinger shared hosting: Now you have a running Laravel project on Hostinger shared hosting.
thank you.. this was helpful