There are many websites available on internet which share information about deployment of Laravel application on shared hosting server, but they are not very helpful as they are out of date in respect of latest changes of Laravel.

Steps to deploy application on shared server:-

1. Remove Public from Url

We are unable to run php artisan command on shared hosting server such as ‘php artisan serve’. In this case, we have to remove ‘public’ from the url in your laravel project. So that we can easily access your laravel project.Follow below steps:

a. Cut index.php and .htaccess from public folder and paste into the project root directory

b. Open index.php file and make below mentioned changes and save the file

Change line 24 to require __DIR__.’/vendor/autoload.php’;

Change line 38 to $app = require_once __DIR__.’/bootstrap/app.php’;

index.php

2. Make ZIP of your Laravel Code.

Select all files from project except git and node_modules folder if exist and then zip all the files.

3. Export Database from your local environment.

Open your Phpmyadmin and export your database locally.

4. Create Database in your Cpanel.

5. Import the exported Database into shared server.

phpmyadmin

6. Upload project ZIP file to public_html folder and extract it using cpanel.

Now upload zip of your laravel project to shared hosting server

7. Update .env file

You have to update your database, mailing related information and other required parameters.

8. Some security setup

We have to hide or protect our htaccess and env file from direct access and also need to disable directory browsing for our laravel application. For this open .htaccess file from public_html folder and add below code at the end of the file and save it.

#disable directory browsing

Options -Indexes

#To Protect Env File

<Files .env>

order allow,deny

Deny from all

</Files>

#To Protect Htaccess File

<Files .htaccess>

order allow,deny

Deny from all

</Files>

9. Set 777 permission to folder ‘Storage’ as Laravel saves all error log in this folder.

10. Finally you are done with the deployment process of Laravel on Shared Hosting server and ready to access the application from the browser.