Laravel

Laravel Deployment on cPanel – Step-by-Step Guide

Sep 28, 2025
Laravel
6 tags
Laravel Deployment on cPanel – Step-by-Step Guide

Laravel Deployment on cPanel – Step-by-Step Guide


Pre-Deployment Checklist

Before you start, make sure you have:  


- ✅ Production assets built (`public/build/`)  

- ✅ Security headers middleware in place  

- ✅ Laravel config optimized (`config:cache`)  

- ✅ Session & cache drivers set to `file`  

- ✅ Correct timezone (`Asia/Kathmandu`)  

- ✅ `.env.production` file template ready  


---


Step 1: Package Your Laravel App


Upload These:

```

app/

bootstrap/

config/

database/

public/

resources/

routes/

storage/

vendor/

artisan

composer.json

composer.lock

```


### Exclude These:

```

.git/

node_modules/

tests/

.env

.env.example

*.md

storage/logs/*

storage/framework/cache/*

storage/framework/sessions/*

storage/framework/views/*

```


---


Step 2: Upload to cPanel

1. Log in → **File Manager** → `public_html/`  

2. Upload your Laravel package (ZIP is easiest)  

3. Extract the files  


⚠️ **Document Root Setup:**  

- Go to **Domains → Manage → example.com**  

- Set **Document Root** → `public_html/public/`  


---


Step 3: Configure Environment

1. Create `.env` in `public_html/`  

2. Paste and update credentials (DB, mail, APP_KEY).  


Generate Key:

- If terminal available: `php artisan key:generate`  

- If not: run locally, copy to server.  


Example `.env` snippet:  


```

APP_NAME="My Laravel App"

APP_ENV=production

APP_KEY=base64:YOUR_GENERATED_KEY_HERE

APP_DEBUG=false

APP_URL=https://example.com

APP_TIMEZONE=Asia/Kathmandu


DB_CONNECTION=mysql

DB_HOST=localhost

DB_PORT=3306

DB_DATABASE=example_db

DB_USERNAME=example_user

DB_PASSWORD=example_pass


MAIL_MAILER=smtp

MAIL_HOST=mail.example.com

MAIL_PORT=587

MAIL_USERNAME=your_email@example.com

MAIL_PASSWORD=your_email_password

MAIL_ENCRYPTION=tls

MAIL_FROM_ADDRESS=your_email@example.com

MAIL_FROM_NAME="My Laravel App"

```


---


Step 4: Database Setup

1. Create database & user in **MySQL Databases**  

2. Assign user → database with **ALL PRIVILEGES**  

3. Update `.env` with DB credentials  


Migrations:

- With terminal: `php artisan migrate --force`  

- Without: use **phpMyAdmin → Import**  


---


Step 5: Permissions

- `storage/` → 755  

- `bootstrap/cache/` → 755  

- `.env` → 644  


---


Step 6: Final Optimization

If terminal available:  

```

php artisan config:clear

php artisan cache:clear

php artisan route:cache

php artisan view:cache

```


**Storage Link (CRITICAL for images):**  

```

php artisan storage:link

```


👉 Without terminal: manually copy `storage/app/public/` → `public/storage/`.  


---


Step 7: Test & Verify

- **Homepage:** `https://example.com`  

- **Admin Panel:** `https://example.com/admin`  

- **Forms, Blog, Contact pages**  


Check: **Error Logs** in cPanel → fix any PHP/database issues.  


---


Security & Performance

- ✅ HTTPS enforced (SSL)  

- ✅ Security headers (X-Frame, CSP, etc.)  

- ✅ CSRF protection  

- ✅ Minified assets  

- ✅ Config & route caching  


---


Troubleshooting

**White Page/500 Error** → Check `.env`, file permissions, root = `public/`.  

**DB Errors** → Wrong credentials or privileges.  

**Images Missing** → Run `storage:link` or copy manually.  

**Assets Not Loading** → Ensure `public/build/` exists.  


---


🎉 Done!

Your Laravel app is live, secure, and production-ready — all from cPanel, no SSH required! 🚀


Share this article

About the Author

K

Kushal Shrestha

Web & Flutter Developer

Passionate developer building modern web and mobile solutions with Laravel and Flutter.

Enjoyed this article?

Subscribe to my newsletter for more insights on web development and mobile apps.