Ratapof
Ratapof

Reputation: 15

Deploying laravel 8 with breeze and laratrust on Shared Hosting

i am trying to deploy my newly created project with laravel 8, Laravel Breeze, and laratrust, to my shared hosting with Hostinger company. In a subdomain.

I have done nothing else yet, other than install these packages.

Domain name: myappdomain.com

Subdomain i am trying to deploy to: testing.myappdomain.com

On my local machine­, using "uWamp" OR "php artisan serve", everything works fine. I can login and register fine.

When i upload my project to hostinger's public_html/testing/, laravel's index.php is shown, but i cant access testing.myappdomain.com/login or /register. I get a 404.

here is what i do:

  1. I ziped my whole www/ directory on my local machine and uploaded it to Hostinger, in my public_html/testing folder of my domain.

  2. i unzip the package and move all files back up 1 directory, for them to be well under public_html/testing and NOT public_html/zipFileName/testing

  3. I updated the .env file with new correct values for my domain:

APP_URL=https://testing.myappdomain.com

  1. i add a .htaccess file in public_html/testing and add this line, to use laravel's public folder.

DirectoryIndex public/index.php

  1. i access testing.myappdomain.com in my browser and Laravel's default index page is shown. but when i click the default login button or register button added by breeze, i get a Page Not Foud 404.

Upvotes: 0

Views: 2602

Answers (2)

Pasan Bhanu Guruge
Pasan Bhanu Guruge

Reputation: 286

Here the steps to host Laravel application in Shared Hosting.

  • Edit the .env file and add your new domain of deployment (testing.myappdomain.com)
  • Add database username, password and name (The details which are used in your hosting)
  • Run php artisan config:cache
  • Run php artisan view:cache
  • Run php artisan route:cache
  • Zip all files and upload to the subdomain directory and extract it
  • Goto subdomain manager of your hosting and point the domain root to public folder in the extracted Laravel folder

This is the simplest method if you don't have ssh access. If you have ssh access, you can use github for the deployment.

Edit : If you can't change the document root,

  • Move your public folder contents to public_html folder (root folder for domain)
  • Modify index.php by adding the folder which contains your files

require __DIR__.’/../bootstrap/autoload.php’; $app = require_once __DIR__.’/../bootstrap/app.php’;

to

require __DIR__.’/../myLaravelProject/bootstrap/autoload.php’; $app = require_once __DIR__.’/../myLaravelProject/bootstrap/app.php’;

(myLaravelProject is a folder located outside public_html and your laravel project is uploaded to this)

Upvotes: 0

Ratapof
Ratapof

Reputation: 15

I got it working! there was no explicit way of changing document root in hostinger-cpanel. I had to delete the sub-domain and re-create it. By default the cPanel generates document root for you in this manner:

public_html/subdomainName

I had to tick the box "custom folder for subdomain" and change it to

public_html/subdomainName/public

Upvotes: 1

Related Questions