Deploying Laravel 5 applications on shared hosting without the use of SSH
Tags: laravel, tutorial
Published: 2018-03-03 09:35:51

---
title: Deploying Laravel 5 applications on shared hosting without the use of SSH
published: true
description: Laravel Tutorial
tags: Laravel, tutorial
---
First, it is well discouraged to use a shared hosting for your Laravel 5 app. There are other very cheap web hosting starting from USD $7 per month.

But some clients (- very low budget clients ) or circumstance (for instance, you want to have something tested and move on) might call for you to use shared hosting.

I particularly had to host an app recently on a shared host. I noticed there were fragmented and incomplete articles on how to this on the Internet. So I decided to come up something complete.

I will cover the following here:

1. How to deploy your app to shared hosting.

2. How to migrate your databases without running migration commands!


Step one:

I assume you've finished building your app – at least a functional app that is working on your localhost. I also assume you are using Laravel 5.0 – although this article would be relevant for Laravel 5.1.

Let's say your laravel project is named laravel50 with the following folder structure:

![Your Project Structure](https://thepracticaldev.s3.amazonaws.com/i/gkdyzo3cffk3o38xvybr.png)

Note: I advise you to leave everything as it is including the .htaccess file.

1. Compress the entire project folder on your local machine. You'll get a zip file – laravel50.zip

2. Open your shared hosting cPanel.
![cPanel Home on shared hosting](https://thepracticaldev.s3.amazonaws.com/i/cezwa3tda9fwjc8ps075.png)

3. Click on ‘File Manager’

4. Click on ‘Upload’

5. Upload the laravel50.zip to the root directory – *not the public_html.*

6. Extract the laravel50.zip. Your cPanel file manager should be looking something close to this:

![cPanel File manager](https://thepracticaldev.s3.amazonaws.com/i/la3tti3vh7toc7fpf9fa.png)

7. Open the laravel50 folder and MOVE the CONTENTS of the public folder to your cpanel’s public_html folder. You can as well delete the empty public folder now.

8. Navigate to the public_html folder and locate the index.php file. Right-click on it and select Code Edit from the menu.

9. This will open up another tab showing the cpanel code editor.

10. change the following lines (22 and 36) from


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

         to

        `require __DIR__.'/../laravel50/bootstrap/autoload.php';
         ...
         $app = require_once __DIR__.'/../laravel50/bootstrap/app.php';`

_NB: According to your projects folder name_

11. Please do not change the contents of your .htaccess file (Unless you know what you are doing 🙂)
the .htaccess file should look something like this.

                         `<IfModule mod_rewrite.c>
                          <IfModule mod_negotiation.c>
                          Options -MultiViews
                          </IfModule>

                          RewriteEngine On

                        # Redirect Trailing Slashes…
                          RewriteRule ^(.*)/$ /$1 [L,R=301]

                        # Handle Front Controller…
                          RewriteCond %{REQUEST_FILENAME} !-d
                          RewriteCond %{REQUEST_FILENAME} !-f
                          RewriteRule ^ index.php [L]
                          </IfModule>`

12. If everything went well, going to http://yourdomain.com should throw database errors (if you have models running on your app). Not to worry! The next phase is migrating your databases to your shared hosting.

<h2>Migrating your tables</h2>

One sweet thing about Laravel Framework is that it enables you to quickly setup defined databases with a single command `php artisan migrate`. Since we are using shared hosting, we can not do this without the use of SSH. This can be done easily if you have up to 10 tables. Its straightforward so let's start:

Create a database on your web host.

1. Most cPanel comes with PHPMyAdmin and Mysql Database Wizard. Use the Mysql Database wizard to create a [Database and User] then assign the user to the database allowing all privileges. Note down the username and password you'll need that soon.

2. Use the cpanel's PHPMyAdmin to create your tables. To do this efficiently, open up PHPMyAdmin on your local machine. For each table structure create the exact structure on your cPanel’s PHPMyAdmin.
![This is an Example](https://thepracticaldev.s3.amazonaws.com/i/ej9k5nvva1epsyezlolo.png)

3. There's another way of importing and exporting databases from a local machine.
login to PHPMyAdmin from your computer locate the database your project uses, from the toolbar find the export tool.

![This is an Example](https://thepracticaldev.s3.amazonaws.com/i/tu33626wo11s1gpztc2c.png)
After exporting move over to your shared hosting and do the same, but this time we are using the import tool

![This is an Example](https://thepracticaldev.s3.amazonaws.com/i/5ojdu1c9r4r1hkmqft6c.png)
If successfully uploaded you'll see the 'Success Message"

4. On your cpanel file manager, navigate to laravel50 (or your laravel project directory). Go to `config/database.php` . Right-click and select ‘Code Edit’. Locate line 55 – Your MySQL configuration Section.

Change the username and password to your MySQL username and password from your cpanel (You noted Earlier).

*Ensure that these details are entered correctly.*

If all goes well, you should have your site working fine now. So go ahead and try it out.