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:
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:
Next, copy the HTTPS link from your GitHub Repo:
Then do this:
And, finally, do:
This should send your local Laravel App to GitHub.
Step 2, We login to our remote SSH Account from our terminal.
Open a new terminal, Do:
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!
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, 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
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,
Lets do our normal setup:
composer install
to install all dependencies specified incomposer.json
file- 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:
3. To fix that, do: php artisan key:gen
Refresh your domain / subdomain… you should have:
Congratulations! you have successfully deployed your Laravel app on a shared hosting with SSH.