Deploying Laravel 5 Applications on Shared Hosting Part 1
After successfully developing your laravel application, you most definitely will start thinking of where to deploy your application. It happened to me a few hours ago when I decided to host this blog. This blog post list the steps you can take to successfully deploy your laravel application on shared hosting the way I successfully did.
Shared Hosting vs VPS
Deploying a Laravel application on a shared host is never recommended. It will be better to subscribe to a Virtual Private Server instead. Computing resources has become a lot cheaper recently and you could easily get a good VPS for less than 20 USD a month. If circumstances prevents you from using a VPS, like in situation where your client already have investments in a shared hosting account, the following explanation will get you through hosting your Laravel application on a shared host.
This article is in two parts.
- The first part will discuss how to actually move your files to the server and ensure your server serves your files
- The second part will discuss migrating your database from your localhost to your remote machine.
Let's get Started
You will need to use an FTP client to connect to your remote host. I will be using a free FTP client called FTP Voyager. You could use voyager or if you have Filezella installed go ahead and use that.
Enter your remote host FTP host and credentials into your preferred FTP client and connect.
Navigate to the root folder of your host - not the public_html
Create a folder* e.g. blog* in the root folder of your remote server and upload all the files and folders of your application except the public folder into the folder you just created.
Open the index.php file in your local folder and modify the following lines in the file from
require __DIR__.'../bootstrap/autoload.php'; ... $app = require_once __DIR__.'/../bootstrap/app.php'; to require __DIR__.'/../blog/bootstrap/autoload.php'; ... $app = require_once __DIR__.'/../blog/bootstrap/app.php';
Change blog above to the name of the folder you created earlier
Then on the remote host, navigate to the public_html folder and upload everything including the .htaccess file in your local public folder into the public_html folder.
Go to your website now and test your application. You should either see the home page of your application, or you will get database errors if your homepage depends on calls to the database.
In the next part we will discuss how to set up your database connections and migrate your tables to your remote host.
If you have any question or comment, please enter them below and I will get back to you as soon as possible.