Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SubhanRaj/62631fdea39d73cc4e034debccabf296 to your computer and use it in GitHub Desktop.
Save SubhanRaj/62631fdea39d73cc4e034debccabf296 to your computer and use it in GitHub Desktop.
This gist provides a step by step guide on how to host a Laravel project on Hostinger shared hosting.

How to host a Laravel project on Hostinger shared hosting

Introduction

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.

What is working

Following is working:

  1. Host Laravel 10 & 11 Project on Hostinger's Shared Hosting
  2. Does not have to move any files from Laravel's Public folder
  3. Working Storage link functionality.

Steps to host a Laravel project on Hostinger shared hosting

  1. Create a new website on Hostinger's hPanel: Add your domain to create a new website.

  2. 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.

  3. 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.

  4. Delete all files and folders in the root directory: This includes public_html and DO_NOT_UPLOAD_HERE.

  5. Optimize your Laravel Project for Production: Optimize the project and make it ready for deployment to production as per the official Laravel documentation.

  6. 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.

  7. 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.

  8. 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 usually localhost.
    • DB_PORT: Set this to the port of your database server. This is usually 3306.
    • 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 to production, this will optimize your Laravel project for production.
    • APP_DEBUG: Set this to false, this will disable debug mode.
  9. 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.

  10. Rename the Public folder: The uploaded Public folder should be renamed to public_html.

  11. Open the filesystems.php file: This file is located in the config folder of your Laravel project.

  12. Modify the Symbolic Links section: Change the following line in the filesystems.php file:

    'links' => [
            public_path('storage') => storage_path('app/public'),
        ],

    to

    'links' => [
            base_path('public_html/storage') => storage_path('app/public'),
        ],
  13. Open SSH terminal and go to the root directory of your website

  14. 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
  15. Cache the routes, views, config and routes by running the following command:

    php artisan optimize
  16. Have a running Laravel project on Hostinger shared hosting: Now you have a running Laravel project on Hostinger shared hosting.

@Symon-kalola
Copy link

thank you.. this was helpful

@Benezerds
Copy link

Thank you very much for the comprehensive guide. I will try it out!

@Jiysea
Copy link

Jiysea commented Oct 20, 2024

Thanks for this guide. However, I'm using the Single Web Hosting option from Hostinger so basically I don't have any SSH access. Do you have any alternative ways to host it without SSH access?

@MoneerKamal
Copy link

thanks you saved my life

@feljohn07
Copy link

need help on this error

`[u574655838@us-bos-web1570 mediumaquamarine-emu-171723.hostingersite.com]$ php artisan storage:link

Error

Call to undefined function Illuminate\Filesystem\symlink()

at vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:355
351▕ */
352▕ public function link($target, $link)
353▕ {
354▕ if (! windows_os()) {
➜ 355▕ return symlink($target, $link);
356▕ }
357▕
358▕ $mode = $this->isDirectory($target) ? 'J' : 'H';
359▕

  +14 vendor frames

15 artisan:13
Illuminate\Foundation\Application::handleCommand()`

@nahom17
Copy link

nahom17 commented Feb 10, 2025

cd public_html
unlink storage

ln -s ../storage/app/public storage

@keinermendoza
Copy link

Thanks for this guide. However, I'm using the Single Web Hosting option from Hostinger so basically I don't have any SSH access. Do you have any alternative ways to host it without SSH access?

If you don't have access to SSH (like in my case), you can use Cron Jobs to run the commands.

In the sidebar, at the bottom, there is an Advanced option—select it. Then, select Cron Jobs.
You will see in the main area that the default option is PHP—that's fine. You can paste the following commands to run the migrations:

domains/<replace.com>/artisan migrate

NOTE: You can run any Artisan command you need using this format.

Replace <replace.com> with your domain.

Set the schedule to every minute, hour, day, month, and week, then save.
Wait until the current minute ends and check the output.


If you need to run a command outside of PHP, select Custom instead of PHP. For example, to create a symbolic link without modifying the configuration:
ln -s /home/<u123456789>/domains/<replace.com>/storage/app/public /home/<u123456789>/domains/<replace.com>/public_html/storage

In this case, replace with your user ID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment