How To Deploy Laravel On Shared Hosting

How to set Larave project On shared hosting?

Easy and best way to deploy Laravel project on cPanel.

The most used but un-secure method

Two-three ways are available on the internet how to deploy a Laravel project on shared hosting. The easy but not secure method people usually follow is making a directory and moving all directories and files there. And moving the directories and files from the public folder to the root directory.

So you basically move the files and directories from the public directory to the root, which is not good practice for security reasons. Also, people face the symlink problem and no images properly appear on the pages.

Deploy Laravel with ease

If there is a better way to do the same and it is more secure, then why not follow?

So, you do not touch or move any files or directories. Just keep the same positions of all files and add one file which will tell which file to open first.

Create a .htaccess file and paste the lines. This file should be in the root directory.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

If you are not adding the directory, no need to edit the index.php file in the public directory. The project will run perfectly. Otherwise, you have to add the directory name there, like:

require DIR.'/../vendor/autoload.php';
require DIR.'/../[DIRECTORY]vendor/autoload.php';

And,

$app = require_once DIR.'/../bootstrap/app.php'; 
$app = require_once DIR.'/../[DIRECTORY]bootstrap/app.php'; 

Related Posts