Sabbir Hossen Chowdhury 29-Jul-2021

How to Deploy Laravel Project in Live Server without change public directory

How to Deploy Laravel Project in Live Server without change public directory

Deploy a Laravel Project in the server is a common thing for a Laravel developer. In this tutorial, I will show you how to Deploy a Laravel Application into a shared hosting without change public directory.

Deploy Laravel Project

Deploy Laravel Project

Usually when we deploy a laravel application in shared hosting, firstly we have to move the index.php file from public directory to the root directory. In today’s tutorial, we are going to see that how to deploy ours on a shared server. I will show you everything step by step. So here we go

After completing your application then you have to log in to your cPanel. After then you have to create a User for your application’s database. Well, after then you have to create an MYSQL database. Then assign this user to the database which you have created. You may assign another user if you want. ( Creating a new user isn’t mandatory). If you want to separate users along with database then you have to create otherwise you can skip this step.


Well, now you have to import the project’s data into your cPanel’s database. Then upload your Project in cPanel. It will take a couple of times according to application size. Then you have to edit the .env file replace database credentials and replace it according to your created database.

Note :

Before uploading in Cpanel, you have to clear the cache of your application. Run this command in your project’s terminal. And Zip your project for uploading to the server.

php artisan optimize:clear

Well, Then create a .htaccess file in your application root directory (It’s not your public directory) and paste this code below.

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ ^$1 [N]
    RewriteCond %{REQUEST_URI} (.w+$) [NC]
    RewriteRule ^(.*)$ public/$1 
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ server.php

Well, Now unzip your project in cPanel. Then hit your domain, visit your project. (It takes a couple of times)

Hope it will help you.