Deploying a web application can be a complicated process, but with the right guidance, you can do it easily. In this article, you will learn how to deploy your Laravel 11 project on Hostinger using their web hosting service. Below, I present a step-by-step guide that will help you get your application online without any hitches.
Prerequisites
Before starting the deployment process, make sure you have the following items:
- An active account on Hostinger.
- Access to an FTP client (such as FileZilla).
- A Laravel 11 project ready to be deployed.
- Basic knowledge of database management and command line (optional).
Step 1: Set up the environment on Hostinger
To begin, log in to your Hostinger account and go to the control panel. From there, select the "Manage" option in the Hosting section to access your domain's settings.
Create a database
- Click on "Databases" in the control panel menu.
- Select "Create Database".
- Fill in the required fields, such as the database name, username, and password. Remember to save this information, as you will need it later.
Step 2: Configure Laravel
Before proceeding with uploading files, it is vital to make some adjustments to your Laravel project.
Modify the .env file
Locate the .env file at the root of your project and update the following variables with the information from the database created in the previous step:
DB_DATABASE=your_database_name DB_USERNAME=username DB_PASSWORD=password
Create a production version
Run the following command in your terminal to prepare your project for production:
php artisan config:cache php artisan route:cache php artisan view:cache
This will help improve the performance of your application.
Step 3: Upload files to Hostinger
To transfer your Laravel project to Hostinger, use your FTP client. Connect to your server and follow these steps:
- Go to the public_html folder.
- Upload all files of your project, except the node_modules folder and any files that are not necessary for production.
- Make sure to upload the contents of the Laravel public folder within the public_html folder, adapting the index.php file according to the file structure. Change the references for the following files:
require __DIR__.'/../vendor/autoload.php'; $app = require_once __DIR__.'/../bootstrap/app.php';
- To:
require __DIR__.'/../your-folder/vendor/autoload.php'; $app = require_once __DIR__.'/../your-folder/bootstrap/app.php';
Step 4: Set directory permissions
It is essential to configure file and directory permissions:
- Ensure that the storage and bootstrap/cache folders have permissions set to 755.
- Check that the files within these folders are accessible and that there are no permission issues.
Step 5: Finalize the process
Now that you have uploaded the files and configured everything properly, access your domain. You should see your Laravel 11 application running.
If you encounter any difficulties, check the error logs provided by Hostinger or review the database configuration.
Conclusion
Deploying Laravel 11 on Hostinger is an accessible process if you follow these steps. Now your application is ready to use, and you can enjoy its features online. For more guides and news related to web development, I invite you to keep reading on my blog. Until next time!