How can I deploy my Laravel project to root folder in Hostinger with git?

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

How to Deploy Your Laravel Project to Hostinger Root Folder Using Git: A Developer's Guide

Deploying a modern framework like Laravel to shared hosting environments often introduces confusion regarding file structure. You are right to ask whether you need to manually move folders between the application root and the public web directory. As a senior developer, I can assure you that there is a standardized, robust way to handle this deployment, ensuring your Laravel application functions perfectly on platforms like Hostinger.

This guide will break down the best practices for deploying Laravel applications via Git to shared hosting, resolving your confusion about folder placement and automation.


Understanding Shared Hosting File Structure

The primary source of confusion stems from how shared hosting environments organize their file system. In most cPanel setups, the main accessible directory is /public_html. This directory is designated as the Document Root, meaning anything placed here is publicly accessible via a web browser.

When deploying a Laravel application:

  1. Security First: Sensitive files, configuration settings (like .env), and vendor directories should generally not be directly exposed in the public root for security reasons.
  2. Laravel Requirement: For a Laravel application to serve requests correctly, the index.php file (the entry point) must reside within the publicly accessible directory.

Therefore, the best practice is not to force your entire project structure into /public_html, but rather to deploy the necessary public assets there while keeping the core application logic secure.

The Recommended Deployment Strategy for Laravel

The most effective strategy involves deploying your Git repository contents to a specific location on the server and using a deployment script (often via SSH) to handle the final setup.

Step 1: Repository Structure Preparation

On your local machine, ensure your project is structured logically. You will primarily be pushing the files that need to be web-accessible into the public root.

If you have assets or publicly accessible views stored in subdirectories (e.g., assets/, views/), these directories should be placed inside the final deployment location.

Step 2: Git Deployment via SSH and File Synchronization

Since direct drag-and-drop is often insufficient for complex setups, we leverage Git and SSH to ensure atomic and reproducible deployments.

  1. SSH Access: Ensure you have SSH access to your Hostinger account.
  2. Cloning (Optional): You can clone the repository directly onto the server if you have sufficient permissions, or more commonly, use SFTP/Git commands to push files into the target directory.
  3. The Deployment Command: The key is synchronizing your project structure into /public_html.

For example, assuming your entire Laravel deployable folder is named my-laravel-app and you want it in the root:

# Connect via SSH to your server
ssh user@yourdomain.com

# Navigate to the public root
cd /home/uXXXXXXXX/public_html

# Copy (or use rsync for efficiency) the contents of your local deployable folder
# Ensure you are copying only the necessary files into this web-accessible folder.
# Example using SCP:
scp -r /path/to/local/my-laravel-app/* .

This method avoids confusion because you are explicitly defining what goes where, rather than relying on a single monolithic deployment. This approach aligns with modern development workflows emphasized by resources like https://laravelcompany.com regarding application architecture.

Handling Complex Folder Structures

You asked if you will have to move folders manually. The answer is no, not if you structure your deployment correctly.

If you have several distinct folders—some required for the public view and others for private configuration (like app/ or .env)—you should treat them as separate entities during deployment:

  • Public Assets: Folders like public/, assets/, and views that need to be served by the browser must go into /public_html.
  • Application Core: The rest of your Laravel application structure (models, controllers, configuration files) should reside in a secure subdirectory outside of /public_html but still accessible via SSH.

You can use Git to manage these separate directories and then use a single deployment script (perhaps a simple shell script executed via Git hooks or manually) to copy only the public-facing parts into the web root, keeping the sensitive backend code securely stored elsewhere on the server. This separation ensures that you never have to manually move files based on an ambiguous instruction; the system handles the targeted synchronization automatically.

Conclusion

Deploying Laravel to shared hosting via Git is entirely achievable and highly efficient when you adopt a structured approach. Focus on understanding the role of /public_html as the web entry point. By using SSH/Git commands for precise file synchronization, you eliminate manual errors and maintain the separation between public assets and sensitive application code. This disciplined approach ensures your Laravel project is not only deployed successfully but remains secure and maintainable.