Deploying a Laravel project to Hostinger shared hosting requires placing your project files outside the public document root and pointing public_html to Laravel’s public directory (or using an .htaccess rewrite rule) to prevent sensitive files like .env from being publicly exposed. Follow this guide to set up your environment, connect your database, and run production commands efficiently.
1. Preparing Your Local Project & Hostinger hPanel
Before moving any files to production, configure your local environment and prepare your Hostinger environment for deployment.
Step 1: Optimize Your Local Build
On your local computer, open your terminal inside your Laravel project root directory and run these optimization commands to package your routes, config, and views:
composer install --optimize-autoloader --no-dev
php artisan config:cache
php artisan route:cache
php artisan view:cache
Step 2: Configure PHP and Create the Database on Hostinger
-
Log into your Hostinger hPanel.
-
Go to Advanced > PHP Configuration and ensure your PHP version matches your local Laravel requirements (e.g., PHP 8.2 or 8.3).
-
Enable essential extensions such as
mbstring,openssl,pdo_mysql,tokenizer,xml, andcurl. -
Go to Databases > Management in hPanel.
-
Create a new MySQL database, database user, and password. Write down these credentials; you will need them for your
.envconfiguration.
2. Uploading Project Files to Hostinger
Hostinger shared hosting uses public_html as the web root. To protect your codebase and sensitive configurations, your core application files must live one level above public_html.
├── /home/u12345678/
│ ├── laravel-app/ <-- Core Laravel files (app, config, routes, bootstrap, etc.)
│ └── public_html/ <-- Only the contents of Laravel's /public folder
Option A: Upload via hPanel File Manager
-
Zip your local Laravel project (exclude
node_modules,.git, and the localvendorfolder if you plan to install packages via SSH). -
Open Files > File Manager in Hostinger hPanel.
-
In your root directory (outside of
public_html), create a folder namedlaravel-app. -
Upload your
.zipfile insidelaravel-appand extract it.
Option B: Deploy via SSH & Git (Recommended for Developers)
-
Go to Advanced > SSH Access in hPanel and activate SSH.
-
Connect to your server using Terminal or PuTTY:
Bashssh u12345678@your-server-ip -p 65002 -
Clone your GitHub/GitLab repository directly outside
public_html:Bashgit clone https://github.com/your-username/your-repo.git laravel-app cd laravel-app composer install --no-dev --optimize-autoloader
3. Web Root Configuration & File Routing
To point web traffic directly to Laravel’s front controller without breaking paths, use one of the following two standard deployment methods:
Method 1: Separate Core Files from public_html (Recommended for Production Security)
-
Copy all contents from
laravel-app/public/into your mainpublic_html/folder. -
Open
public_html/index.phpin the hPanel File Manager. -
Update the path references to point to your
laravel-appdirectory:
// Find line 1: Maintenance mode path
if (file_exists($maintenance = __DIR__.'/../laravel-app/storage/framework/maintenance.php')) {
require $maintenance;
}
// Find line 2: Composer Autoloader path
require __DIR__.'/../laravel-app/vendor/autoload.php';
// Find line 3: Bootstrap Laravel path
$app = require_once __DIR__.'/../laravel-app/bootstrap/app.php';
Method 2: Use Root .htaccess Redirect
If you uploaded the entire application inside public_html/, redirect incoming traffic safely into the public/ directory:
-
Create a
.htaccessfile directly insidepublic_html/. -
Paste the following configuration:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
4. Environment Setup & Database Migrations
Step 1: Configure Your Production .env
-
Inside
laravel-app/, copy.env.exampleto.env. -
Update the credentials with your live production details:
APP_NAME="Your Application"
APP_ENV=production
APP_DEBUG=false
APP_URL=https://yourdomain.com
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_hostinger_db_name
DB_USERNAME=your_hostinger_db_user
DB_PASSWORD=your_hostinger_db_password
Step 2: Run Database Migrations and Generate App Key
Via SSH, navigate to laravel-app/ and execute:
php artisan key:generate
php artisan migrate --force
If SSH is not available on your shared hosting tier:
-
Export your local database via phpMyAdmin into a
.sqlfile. -
Open Hostinger Databases > phpMyAdmin, select your new database, and click Import.
5. Storage Symlink & Performance Optimization
Link Storage Directory
Laravel requires a symbolic link between storage/app/public and public/storage for file uploads.
If SSH is enabled, run:
php artisan storage:link
If you encounter symlink permission limitations on shared hosting, create a temporary route in routes/web.php to trigger the symlink directly via browser:
Route::get('/symlink-setup', function () {
$target = storage_path('app/public');
$shortcut = public_path('storage');
symlink($target, $shortcut);
return 'Storage symbolic link created successfully!';
});
Visit [https://yourdomain.com/symlink-setup](https://yourdomain.com/symlink-setup) once, then immediately delete this route from your code.
Final Production Caching
Run these commands via SSH to ensure maximum response speed:
php artisan config:cache
php artisan route:cache
php artisan view:cache
Real-World Benefits of Hosting Laravel on Hostinger
-
Cost-Effective Scalability for Freelancers: Run multiple client staging environments or production web applications at a fraction of VPS costs.
-
Built-In Git & SSH Integration: Automate deployment pipelines directly from your GitHub repositories into shared hosting environments.
-
Free SSL & LiteSpeed Performance: Out-of-the-box HTTPS enforcement paired with LiteSpeed caching ensures fast response times for web applications.
-
Automated Cron Jobs: Easily schedule Laravel background tasks (
php artisan schedule:run) directly through Hostinger’s hPanel Cron Job manager.
Exclusive Hosting Offer for Developers & Businesses
Ready to deploy your Laravel applications on high-performance infrastructure? Hostinger provides optimized PHP runtime environments, automated daily backups, free domain registration, and unmetered bandwidth tailored for web developers.
Claim Your Exclusive Discount
Get an EXCLUSIVE 20% DISCOUNT on all hosting packages by using the official referral link below:

