How to Deploy a Laravel Application on Hostinger (Step-by-Step Guide)
Deploying a Laravel application to a live server may seem difficult if you're doing it for the first time. In this guide, we'll walk through the complete deployment process on Hostinger, from preparing your project locally to making your website live.
By the end of this tutorial, your Laravel application will be running successfully on your Hostinger hosting account.
Prerequisites
Before you begin, make sure you have:
- A Laravel project running locally
- A Hostinger hosting account
- Access to Hostinger File Manager
- A MySQL database backup
- Your domain connected to Hostinger
Step 1: Zip Your Laravel Project
Navigate to your Laravel project folder and compress it into a ZIP file.
Example:
We'll upload this ZIP file to Hostinger in the next step.
Step 2: Export Your MySQL Database
Open phpMyAdmin (or any database management tool) on your local machine.
- Select your Laravel database.
- Click Export.
- Choose Quick export.
- Select SQL format.
- Click Go to download the SQL file.
Example:
Step 3: Upload Your Laravel Project to Hostinger
Login to your Hostinger account.
Navigate to:
Open the following directory:
Upload your Laravel ZIP file.
Once the upload completes:
- Right-click the ZIP file.
- Click Extract.
- Extract it inside the public_html directory.
Your folder structure should now look something like this:
Step 4: Create a MySQL Database
From your Hostinger dashboard, go to:
Create a new database by providing:
- Database Name
- Database Username
- Database Password
After creating the database, import your previously exported SQL file.
Keep the following information ready:
Step 5: Update Your .env File
Open your Laravel project's .env file and update the database credentials.
Important: Replace
APP_URLwith your actual domain name.
Example:
Step 6: Configure the Root .htaccess
If the .htaccess file does not exist in the project root, create it.
Replace its contents with:
This redirects all incoming requests to Laravel's public directory.
Step 7: Configure public/.htaccess
Open the following file:
If it doesn't exist, create it.
Replace it with the following code:
This configuration enables Laravel routing, allows access to storage files, and increases PHP upload limits.
Step 8: Verify Your Project Structure
After deployment, your project should look like this:
Step 9: Visit Your Website
Open your browser and visit your domain.
Example:
If everything has been configured correctly, your Laravel application should now be live.
Common Issues
404 Not Found
- Check both
.htaccessfiles. - Make sure
mod_rewriteis enabled. - Verify that the project was extracted correctly.
Database Connection Error
Double-check the following values in your .env file:
DB_DATABASEDB_USERNAMEDB_PASSWORDDB_HOST
Storage Images Not Loading
Ensure the storage directory is correctly linked and accessible.
Internal Server Error (500)
Check:
- File permissions
.envconfiguration- Laravel logs inside:
Conclusion
Congratulations! 🎉 You have successfully deployed your Laravel application on Hostinger.
To recap, you:
- ✔️ Zipped your local Laravel project
- ✔️ Exported your MySQL database
- ✔️ Uploaded and extracted the project in
public_html - ✔️ Created a new MySQL database
- ✔️ Updated the
.envfile with the correct credentials - ✔️ Configured the root
.htaccess - ✔️ Configured the
public/.htaccess - ✔️ Updated the
APP_URLto your domain - ✔️ Launched your Laravel application successfully
Your Laravel project is now live and accessible from anywhere in the world!