How can I deploy my Laravel project to root folder in Hostinger with git?
Asked Answered
C

3

8

I'm trying deploy my project to Hostinger with git, but I can't deploy direct to root folder (/home/uXXXXXXXX). The path in cPanel is directly to /home/uXXXXXXX/public_html.

Is there anyway to deploy to root folder? My project is in Laravel. What is the best way to deploy to shared host? Because part of the folders need to be in the root and others in /public_html. Will I have always move folders manualy in my hosting?

I'm a little confused in this part. I'll appreciate any help

Cooperation answered 15/5, 2018 at 0:24 Comment(6)
regarding the git, i doubt they offer that out of the box. as for to only expose your public folder you will need to edit at least two files if i remember correctly, one the most obvious one is index.php on the public folder to set the correct path the second one is the bootstrap.php.Raven
Here's step by step instructions to deploy a laravel 5.5 project to Hostgator.Deluge
See also this discussion. It has additional links to deploying on shared hosting.Deluge
Also found this gist on how to git push to hostgator. Don't know any caveats for Laravel though...Deluge
You might also look at Deployer for which is configured out of the box to install Laravel projects.Deluge
and 2020 i'm still doing it manually, sadly hostinger only allowed deploy from git to public_folder or it subfolder.Sierrasiesser
A
7

The other answers might work but there's no way am complicating something so basic. What if you have the website working locally in a public folder rather than public_html and then you have to make changes to your local branch and re-deploy to git? You'll face errors when your local branch is not in sync with your remote branch.

The best way to do is:

  1. create a new .htaccess file inside public_html directory
  2. Add these codes
  RewriteCond %{HTTP_HOST} ^your-domain.com$ [NC,OR]
  RewriteCond %{HTTP_HOST} ^www.your-domain.com$
  RewriteCond %{REQUEST_URI} !your-laravel-folder/public/
  RewriteRule (.*) /your-laravel-folder/public/$1 [L]

In the above lines you should replace the following: your-domain.com – Type your own domain name and also replace your-laravel-folder with your folder name.

Alluring answered 22/12, 2020 at 8:56 Comment(2)
this is the perfect solution, I came across this answer at the first attempt. Thank you!Mitsukomitt
this does not work properly when deploying projects on a subdomain. Do we need to make any changes to that? the only first page is showing and the other pages do not work.Melodee
P
1

you can actually clone it using ssh access.

open ur ssh for a particular domain. go to the root folder. u can clone it there.

you can keep your project files there. even though u have top copy the contents of puclic folder inside your laravel project to public_html folder, and also edit the index.php so that all resources must be pointed to the project folder outside public_html

Inorder to update your project you will have to clone it from ssh again

Pudding answered 1/11, 2020 at 16:51 Comment(0)
A
-2

Step 1: configuration

  • Install Laravel locally.
  • Rename public folder to public_html
  • add Schema::defaultStringLength(191); to boot function in App/Providers/AppServiceProvider.php.
  • Initialize git and commit.

Step 2: push to GitHub

  • create a repo in github

  • push local repo just created moments ago to GitHub.

step 3: server management

  • Login with SSH from your local terminal

  • change directory to correct domain (if you have many domains)

  • run ls command it should return public_html (only if there are no other files in root directory, if any backup and delete them)

  • backup and delete public_html directory. rm -rf public_html

    basically all your data is located in public_html/ directory

  • run git clone YOUR-REPO@git ./

useful links:

Aguish answered 16/6, 2019 at 16:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.