Laravel

Deploy Laravel 9 On Shared Hosting | Hostinger

Hello, there I hope you are doing well, In this blog will get to know how to deploy Laravel 9 on shared hosting, well sometimes it is a bit challenging to host Laravel on shared due, to the index file present inside the public folder.

There are several ways to deploy laravel on shared hostings, like changes in index.php file.

I tell you the correct way of deploying laravel on your shared hosting, well in the market there many shared hosting like godaddy, hostingraja, bluehost, hostgator etc. In this blog, I am going to use hostinger web hosting, and the reason behind purchasing the hostinger web hosting over the other is hostinger provides, Free SSL, LiteSpeed, and Cloudflare Integration at a low cost as compared to the other hosting services.

We will follow the below step to host laravel on hostinger

  1. Create an account on hostinger
  2. Sign in to your account
  3. Purchase one domain
  4. Install Laravel On the Local System
  5. Upload the file
  6. Setting up .htacces
  7. Create a database
  8. Run the migration
  9. Test the laravel Website

Step: 1 Create an account on hostinger

To create an account on hostinger with upto 35% off click on this link , when you click on the link you have the image like something below.

When you scroll down the few, you will be able to see their plans
Choose any one of them at your convenience, and get started, I suggest you go for premium web hosting, as they offer 100 websites at a very reasonable cost plus they will also provide a free domain with this plan. In this blog, I will add premium web hosting to our cart.

When you click on add to cart you will be able to see something like the below image.

Then scroll down the few to create your account and get up to 35% off on the total price.When you scroll tdown he few you will abe ble to see the below image, I have marked the places where you have to enter you email to create your account.
Now it’s time to apply our coupon done code007, to get upto 35% off, so copy this code007 coupon code and then scroll down the few, I have marked the place where you have to enter this coupon code and then you choose any payment gateway to proceed with your payment

Step:2 Sign in to your account

Now when you first time signs in to your account you have something like the below one.

Step:3 Purchase One Doman

If you have purchased the premium web hosting then you don’t need to purchase one domain, if you have bought single web hosting then you have to purchase one domain, to purchase the domain click on the domain, I have marked in the below image.

Then click on the get a new domain

Then you have to look for your desired domain name.

For example, I have added bikewaaala.com and the domain is available to buy, will click on the buy button to purchase the domain and connect it with our hosting.

Step:4 Install Laravel in local system

I will show you how to install laravel in the local system inside the xampp, and I am using a windows device as my operating system.

Go to xammp/htdocs and on the top in the address bar type cmd and then press enter, it will open the command panel.

In your command write the below code to install laravel 9, then press enter it will install the project under the example app folder

composer create-project laravel/laravel example-app
You can see in the below image that laravel has successfully installed in the example app folder.

Step:5 Upload the Project folder

First, we have to make the zip of our example-app folder, then we upload that zip to our hostinger services.

Go to your hostinger account and click on the manage button, I have marked in the below image

Then you have to search for file manager, and then you can click on the file manager beta
To check whether you uploading file on right domain or not see the marked sign in the below image

We have to upload our project inside the public_html folder, double click on the public_html to go inside it.

when you click on the publc_html you have the image like something below, click on the upload icon, and then choose the file to upload your zip.
You can see in the below image, that I have upload the zip folder
Then do the right click on your zip folder and click on unarchive

When you click on unarchive they will ask for the folder name at the place of folder name just add a forward slash /.

Now will move the code outside the example-app folder. Then click on the select mark all the folder and files, which we have to move outside the project folder, then click on the move and mark the move to the public_html.

After moving it into the public_html delete the example-app and default.php file

Step:6 Change in .htacces

To change in .htacces, first we have to copy our .htaccess file from the public folder to the public_html folder.

After the copy click on the edit and add the below code into the .htacess and then save the file.
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]
 
    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    RewriteRule ^(.*)$ public/$1 

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

Step:7 Create the database

Search for the database, then click on that to create a new database. Then fill in your database name, username and password, and click on the create button

Now we have to connect our database to our laravel project, look for .env file and enter the database details, which your have created.

To run the migration, we must have to enable ssh access in our hosting services, to enable the ssh, go back to your dashboard and the search for the ssh.
Click on the ssh access, we have to enable the ssh in order to run the command over the hostinger.
Then set your SSh password and copy the below command which I have marked in the below image.
then your command and just paste the code which you have copied in the last step, then enter your password and you are able to access the terminal, now we will migrate to the project root folder and run the migration command.

In the public_html we will use the below command to run the migration and create the laravel default table.

Step:8 Run the migration

php artisan migrate

If you see the below error, just search for the PHP and we will change our PHP version to 8.1

Search for the PHP configuration then change it to the PHP 8.1

Now again go back to the terminal and try to run the command again.

Step:9 Test the laravel Website

Now, it’s time to test our maticodairy.com, you can see in the below image the site is working fine.

Horray, we have successfully hosted our website on hostinger shared hosting.I hope you love it.

Shaiv Roy

Hy Myself shaiv roy, I am a passionate blogger and love to share ideas among people, I am having good experience with laravel, vue js, react, flutter and doing website and app development work from last 7 years.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button