Skip to content

Instantly share code, notes, and snippets.

@xyluz
Created May 21, 2021 13:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save xyluz/f44cc3099f5c00fbe9b8f51064e61d81 to your computer and use it in GitHub Desktop.
Save xyluz/f44cc3099f5c00fbe9b8f51064e61d81 to your computer and use it in GitHub Desktop.
Deploying Laravel to a Shared Hosting with SSH

You need to have SSH access to your server, Its almost impossible and definitely unadvisable to deploy Laravel to a server with a file upload app like filezilla, for a lot of reasons, but mostly because of dependencies.

The first thing you need to check is; if your host server gives you access to SSH.

After checking with your host company, and ensuring you have SSH access, you can now install Laravel on your local machine, if you don’t know how to do that, check this: https://medium.com/staybusyng/getting-started-with-laravel-69d288229de8

Steps to Deloying your Laravel App

STEP 1: Use Git

I recommend you deloy from a version control platform, such as GitHub. I’ll be using GitHub for my sample deployment. First, push your locally created laravel app to a remote repo.

Create a repo, go to github.com, create an account, login and create a new repo (how to do that: https://guides.github.com/activities/hello-world/)

We’ll be working from staybusy practice repo:

Creating a new repo

PS: Don’t initiate the repo with README. Just to avoid running into some novice errors.

The repo above is here, https://github.com/StayBusy/practiceLaravel

Next, lets initiate git on our local repo, open new terminal at your laravel project and do the following:

git init — to make your local repo a git repo

do: git add .

commit and add a commit message

Next, copy the HTTPS link from your GitHub Repo:

https repo link

Next, copy the HTTPS link from your GitHub Repo:

https repo link

Then do this:

Note Highlighted Repo link

Set the new remote

And, finally, do:

push to remote repo

This should send your local Laravel App to GitHub.

Laravel Now on remote GitHub Repo

Step 2, We login to our remote SSH Account from our terminal.

Open a new terminal, Do:

login to ssh

basically, you are saying, I want to access ip address using username via ssh.

You should have: a. IP address to your server b. SSH Username.

It will prompt you for a password, enter your password.

PS: You won’t see it as you enter it, but it’ll give you error or log you in when you hit enter.

I’m in!

ssh login to server successful

I won’t be showing you my username or anything like that 😄

Next, navigate to the root of your folders, mine is at www most servers have their root at www including WAMP.

To navigate to the root folder: do: cd www

now in root folder

Now, clone the repo into your root folder, if its a private repo its a different story, but we are working with a public repo for now

clone the repo

Repo cloned

Now, your Laravel App is on your server… Though its useless for now, lets make it useful.

Step 3, point your domain to the right place.

For this example, i’ll be using practice.staybusy.ng From your hosting (I’m going to assume you are using CPANEL or something similar, add your domain, or create your subdomain.

I’ll be using CPANEL for this, while creating the subdomain make sure your Document Root points to [location of the app on the server]/public as public folder is the access point of all Laravel Applications.

For me, I have practiceLaravel/public

Visiting the domain /sub domain right now shows nothing, or tells you it cannot be reached. Its okay, we’ll be able to see something useful when we complete Laravel setup.

Step 4, Setup Your Laravel App

Return back to your terminal, and cd into the directory holding your Laravel app,

cd into your laravel app

Lets do our normal setup:

  1. composer install to install all dependencies specified in composer.json file
  2. do: cp .env.example .env

This will copy the sample configuration file, and make yours for you, now visit your domain / subdomain, you should see something like this:

error due to no encryption key

  1. To fix that, do: php artisan key:gen

Refresh your domain / subdomain… you should have:

Laravel app deploy successful!

Congratulations! you have successfully deployed your Laravel app on a shared hosting with SSH.

@ajadi473
Copy link

ajadi473 commented Sep 2, 2021

This is so cool... Thanks Seyi

@andrew21-mch
Copy link

@xyluz please whats the other story for private repository 🙏

@mohammedalborih
Copy link

That is very interesting, but
I've I question , what about the database.?
U didn't talk how to confige and manage the DB

@dimasbk
Copy link

dimasbk commented Nov 3, 2023

That is very interesting, but I've I question , what about the database.? U didn't talk how to confige and manage the DB

u should just configure the database from the cpanel first, then adjust the credential such as host, username, and password in the env

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment