Laravel Deployment GitHub

Deploy Laravel 8 on cPanel
with GitHub Integration

Laravel Deployment Banner

Laravel is an open-source PHP framework built on the MVC pattern — designed to make web apps faster and easier to build. When it comes to deployment, shared cPanel hosting is the most affordable option for small-scale businesses and side projects. This guide walks you through deploying a production-ready Laravel 8 app on cPanel using GitHub for version control.

Prerequisites

  • PHP 7.3 or above
  • Composer installed locally
  • VS Code (or any code editor)
  • XAMPP for local development
  • GitHub account
  • cPanel hosting account
01

Phase 1

Creating & configuring the Laravel 8 application locally

Step 1 — Create a new Laravel project

Terminal
composer create-project laravel/laravel my-app
Create Laravel project
Laravel project created

Your Laravel project is created. Now configure it for local development.

Step 2 — Configure the .env file

Open the .env file in your project root and fill in your database credentials, third-party API keys, and mail settings.

Configure .env file

Run the following artisan commands to set up your local environment:

Artisan Commands
php artisan migrate
php artisan key:generate
php artisan storage:link
Artisan migrate
Key generate
Storage link

Step 3 — Test locally with php artisan serve

Terminal
php artisan serve

Open the URL shown in your terminal (usually http://127.0.0.1:8000) to verify the app is working.

Artisan serve
Laravel running locally
Phase 1 complete — Laravel app running locally
02

Phase 2

Pushing the project to a GitHub repository

Step 1 — Create a public GitHub repository

Create GitHub repo

Step 2 — Copy the clone URL and initialize Git locally

Copy clone URL

Navigate to your project root in the terminal and run:

Terminal — Git Init
git init
git remote add origin <YOUR_REPOSITORY_URL>
git status

Then commit and push your code:

Terminal — Push to GitHub
git add .
git commit -m "Initial commit"
git push origin main
Git init
Git add commit
Git push
Repo on GitHub
Phase 2 complete — code pushed to GitHub
03

Phase 3

Configuring the domain and deploying via cPanel

Where to buy cPanel hosting

Step 1 — Log in to cPanel

Login to cPanel

Step 2 — Create a domain or subdomain

Go to Domains → Subdomains (or Addon Domains) and fill in:

  • Subdomain name
  • Domain name
  • Subdomain root directory

Then click Create.

Subdomain setup
Fill subdomain fields
Subdomain created

Verify the folder was created in File Manager.

Subdomain folder in file manager

Step 3 — Connect your GitHub repo via Git Version Control

In cPanel, find Git™ Version Control and click Create:

  • Paste your GitHub clone URL into the Clone URL field
  • Select the subdomain root directory as the repository path
  • Give the repository a name
  • Click Create
Git Version Control in cPanel
Create git repo in cPanel
Fill git repo details

Verify your subdomain directory is now linked to the GitHub repo.

Repo connected

Step 4 — Clear the directory and pull from GitHub

Open the cPanel Terminal, navigate to the subdomain root, and clear it:

cPanel Terminal
cd ~/public_html/your-subdomain
rm -rf *
Navigate to directory
Remove files

Go back to Git Version Control → Manage → Pull or Deploy, set your branch, and click Update from Remote.

Git manage
Set branch
Pull or Deploy tab

Verify the repo files are now in the File Manager.

Files cloned to server

Step 5 — Set the document root to Laravel's public/ directory

Update document root to public
Not Recommended — .htaccess Redirect

Alternatively you can add a redirect in a root-level .htaccess file, but this exposes your application files to the web and creates security risks. Avoid unless your cPanel version doesn't support changing the document root.

Create .htaccess
Add htaccess redirect

Step 6 — Final configuration in cPanel Terminal

Navigate to the subdomain root and run:

cPanel Terminal — Final Setup
composer install --ignore-platform-reqs
php artisan key:generate
chmod -R 775 storage
Composer install
Key generate and chmod

Now open your domain or subdomain URL in a browser:

Laravel deployed successfully
Deployment successful — your Laravel 8 app is live!

Quick Reference

Local Setup
composer create-project
php artisan migrate
php artisan key:generate
php artisan storage:link
GitHub Push
git init
git remote add origin <url>
git add . && git commit
git push origin main
cPanel Deploy
composer install --ignore-platform-reqs
php artisan key:generate
chmod -R 775 storage