Deploy Laravel Project in Server without change public directory

Deploy Laravel Project
Spread the love

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 in Server 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 an User for your application’s database. Well, after then you have to create a 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 seperate users along with database then you have to create otherwise you can skip this step.

Read More : The @class Blade Directive in Laravel 8.51x

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.

Spread the love

About Anisur Rahman Shahin

Hello. My name is Shahin. I'm a tech enthusiast guy. Personally, I’m an Optimistic and always in hurry kinda person. I'm a freelance web developer. I am working at Zakir Soft as Laravel Developer. My Portfolio website:

View all posts by Anisur Rahman Shahin →

Leave a Reply

Your email address will not be published.