How to Host a Laravel Project on Hostinger’s hPanel: A Step-by-Step Guide
If you're looking to host a Laravel project on Hostinger’s hPanel, you’re in the right place! This guide will walk you through each step, from uploading your project to configuring it for a smooth deployment.
1. Prepare Your Laravel Project
Before uploading, ensure that your Laravel project is ready to go:
Run composer install to install all dependencies.
If you're using front-end assets (like Vue.js or React), make sure to run npm run production.
Configure your .env file with the correct environment variables, such as database credentials and the application URL.
2. Upload Your Laravel Files
You have two options when uploading your files:
Option 1: Upload the Entire Project
Upload your entire Laravel project to the root directory (one level above public_html). Then, move the contents of the public folder to the public_html folder.Option 2: Upload Only the Necessary Files
Create a directory called society in the root directory. Upload everything except the public folder into this directory. Then, move the contents of the public folder into the public_html directory.
3. Update the index.php File
After uploading your files, you need to update the paths in your index.php file, which is now located in the public_html directory.
Here’s how your updated index.php file ould look:
php
<?php
use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
// Determine if the application is in maintenance mode...
if (file_exists($maintenance = __DIR__.'/../society/storage/framework/maintenance.php')) {
require $maintenance;
}
// Register the Composer autoloader...
require __DIR__.'/../society/vendor/autoload.php';
// Bootstrap Laravel and handle the request...
(require_once __DIR__.'/../society/bootstrap/app.php')
->handleRequest(Request::capture());
Update the Paths: Ensure the paths point to the correct directories inside your society folder.
4. Set File Permissions
It’s essential that your Laravel project has the correct permissions:
Run the following command to ensure that the storage and bootstrap/cache directories are writable:
chmod -R 775 storage bootstrap/cache
5. Configure Your Environment Variables
Double-check the .env file in your society directory. Ensure all environment variables, such as APP_URL, DB_HOST, DB_DATABASE, DB_USERNAME, and DB_PASSWORD, are correctly set.
6. Database Setup
Using Hostinger’s hPanel, create a MySQL database:
Update the .env file with the new database credentials:
env
DB_HOST=your_database_host
DB_DATABASE=your_database_name
DB_USERNAME=your_database_username
DB_PASSWORD=your_database_password
7. Run Migrations
Access your site via S or use the web-based terminal in hPanel to run your migrations:
php artisan migrate --force
8. Configure Your Domain
Ensure your domain is pointing to the public_html directory. This ould be set up by default, but you can verify it in hPanel under “Domains” > “Manage.”
9. Set Up Cron Jobs (If Needed)
If your Laravel project requires scheduled tasks, set up cron jobs via hPanel.
No comments:
Post a Comment