Skip to content

How to deploy Laravel project on cPanel 2023

Posted on:July 10, 2023 at 10:00 PM

Let’s imagine that you have developed an app with laravel, and then upload or deploy the app on shared hosting (cPanel). Unfortunately it’s not straight forward because of different directory structure of laravel and cPanel.

In this post, I will show you the step by step process how to upload or deploy a laravel project on cPanel.

Table of Content

Step 1: Create a zip of your laravel app

Compress (zip) your Laravel project folder.

Step 2: Upload the zipped project to cPanel

Step 3: Extract your zipped project

After uploading the zipped project, unzip it (in public_html).

Step 4: Update index.php file

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

TO:

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

Step 5: Import Database

Two steps you need to follow:

Create a database and user:

Import SQL file:

Step 6: Update database details

Go to public_html/.env file and update following section:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= # your database name
DB_USERNAME= # your database user name
DB_PASSWORD= # password for your database

Step 7: (optional) Clearing cache

php artisan route:cache
php artisan cache:clear
php artisan config:cache
php artisan view:clear
php artisan optimize

Now if you visit your site e.g. http://example.com it should render your app properly.