How to Deploy Laravel to cPanel via SSH (Git Pull Method – Simple & Clean)

Many Laravel tutorials for cPanel are overly complicated — moving the public folder, editing paths everywhere, and tweaking lots of configuration files. In this article, I’ll share a much simpler and cleaner way to deploy Laravel that I personally use in production: deploying with Git + SSH, without the hassle of moving files to the root directory.


Main Concept

Here’s the deployment flow I use:

  • Push the project to Git
  • Pull the project on the server via SSH
  • Set up the environment
  • Install dependencies
  • Run Laravel as usual
  • Configure .htaccess so it still uses the /public folder

This way, we don’t need to move the contents of the public folder into public_html.


1. Login to the Server via SSH

ssh username@domain.com

2. Clone Project from Git

Enter to your folder public_html:

cd public_html
git clone https://github.com/username/nama-project.git .

Note: the dot (.) means the project will be cloned directly into the root folder.


3. Setup Environment

cp .env.example .env
nano .env

Adjustment:

APP_ENV=production
APP_DEBUG=false
APP_URL=https://yourdomain.comDB_DATABASE=dbname
DB_USERNAME=userdb
DB_PASSWORD=password

4. Setup Database

  • Create a database in Cpanel
  • Import database (optional)

5. Install Dependency

composer install

6. Generate Key

php artisan key:generate

7. Set Permission

chmod -R 755 storage
chmod -R 755 bootstrap/cache

8. Optimize Laravel

php artisan config:cache
php artisan route:cache
php artisan view:cache

9. Setting .htaccess (THIS MAIN KEY)

Since we are not moving the public folder, we need to direct all requests to the /public directory.

Edit the .htaccess file inside public_html:

RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]

The following is the method I usually use to deploy Laravel applications to a cPanel server (Shared Hosting).

Deploying Laravel to cPanel doesn’t have to be complicated. By using the Git + SSH approach along with a small .htaccess configuration, we can run Laravel in a much simpler, cleaner, and more professional way.