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
- Login into your cPanel
- Click on File Manager
- Go inside the
public_html
- Click on Upload
- In the pop-up, then choose the zipped project (which you did in step 1)
Step 3: Extract your zipped project
After uploading the zipped project, unzip it (in public_html
).
Step 4: Update index.php
file
- Edit your
index.php
file from:
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:
- Go to Cpanel and click Database wizard
- Create a new database
- Create a new user
- Associate newly created user with newly created database
Import SQL file:
- Export your local database as an SQL file
- Go to PHPMyAdmin in cPanel
- Open the created database
- Click on the import option and 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.