Web Hosting Blog by Nest Nepal | Domain & Hosting Tips

How to Deploy a Laravel App on cPanel or VPS Hosting (2025 Guide – Laravel 11 Ready)

Modern PHP development has come a long way, and today’s frameworks offer tools that make development seamless, maintainable, and scalable, like Laravel. But when it comes to going live, deploying your web application isn’t quite as simple as uploading files to a folder, especially if you’re using advanced tooling, routing, and environment-based configuration.

laravel

In this comprehensive, 2025-ready deployment guide, you’ll learn how to bring your PHP framework (Laravel)-based app online using two common environments:

This tutorial is designed to work with virtually any provider—Nest Nepal, Hostinger, A2 Hosting, or your own VPS.

vps


Before You Begin: System Requirements

Before jumping into deployment, make sure the following tools and conditions are met:

  • You’ve built and tested your app locally using the latest version of Laravel (Laravel 11)

  • Your hosting environment provides SSH access (either via cPanel Terminal or full root access on a VPS)

  • Git access, or an FTP/SFTP client if Git is unavailable

  • PHP version 8.1 or higher is installed on the server

  • Composer for Laravel is installed on the server

  • A database like MySQL or MariaDB is ready to be connected


Option 1: Deploying on cPanel with SSH Access

This is the more accessible option for many developers, especially those using shared hosting plans.

1. Upload the App

Start by zipping your project directory, but exclude the vendor/ folder and .env file to keep things secure and reduce the size.

You can upload it using the File Manager or clone the repository directly via Git if available.

2. File Placement and Structure

Do not place the entire app inside the public_html/ directory. Instead, upload the full project to a separate folder, like /home/username/myapp/. Then:

  • Either copy the contents of your public/ folder to public_html/

  • Or, if symbolic links are supported, link the public/ directory to public_html/

    bash
    ln -s ~/myapp/public ~/public_html

3. Set Permissions

Run the following via the terminal:

bash
chmod -R 775 storage
chmod -R 775 bootstrap/cache

This ensures the necessary directories are writable.

4. Environment Configuration

Upload your .env file separately and update the database credentials accordingly.

Then, generate the app key using:

vbnet
php artisan key:generate

5. Database Setup

Use cPanel’s MySQL tools to create your database and user, then assign privileges.

Once the .env is ready, migrate your database:

nginx
php artisan migrate

6. Update .htaccess for Routing

Make sure the .htaccess inside public_html/ is properly handling route requests:

apache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L] </IfModule>

Option 2: Deploying on VPS (Ubuntu/Debian)

This method gives you full control over the environment and is preferred for more complex or high-performance apps.

1. Connect via SSH

bash
ssh user@your-server-ip

2. Install Required Software

If not already set up, install all necessary packages:

bash
sudo apt
update
sudo apt
install php8.1 php8.1-fpm php8.1-mbstring php8.1-xml php8.1-mysql unzip curl
git composer nginx mysql-server

3. Upload or Clone the Code

Navigate to your web directory and pull the source code:

bash
cd /var/www
sudo git clone https://github.com/yourname/yourproject.git

4. Fix Ownership and Permissions

bash
sudo chown -R www-data:www-data yourproject
chmod -R 775 storage bootstrap/cache

5. Create the Database

Log in to MySQL and create your database and user:

sql
CREATE DATABASE myapp_db;
CREATE USER 'myapp_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON myapp_db.* TO 'myapp_user'@'localhost';
FLUSH PRIVILEGES;

Update the environment config and run:

bash
composer install
php artisan migrate
php artisan config:cache

6. Set Up Nginx

Here’s a basic Nginx config block:

nginx
server {
listen 80;
server_name yourdomain.com;
root /var/www/yourproject/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.

php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

Restart Nginx:

nginx
sudo systemctl restart nginx

Post-Deployment Checklist

After the app is live:

  • Cache configuration and routes:

    pgsql
    php artisan config:cache
    php artisan route:cache
  • Set up workers if you use queues:

    cpp
    php artisan queue:work
  • Add a cron job for scheduled tasks:

    bash
    * * * * * cd /var/www/yourproject && php artisan schedule:run >> /dev/null 2>&1

Common Errors and Quick Fixes

Issue Cause Fix
500 Internal Error Bad file permissions, no .env Check logs, set correct permissions
Class Not Found Missing vendor folder Run composer install
Forbidden Access Wrong root directory Verify the Nginx path or .htaccess

Final Thoughts

Deploying your modern PHP Laravel application on shared or private servers doesn’t have to be painful. By following structured steps—uploading your code properly, configuring permissions, managing environment variables, and setting up web servers—you can go live with confidence.

For advanced workflows, consider integrating tools like GitHub Actions, Laravel Forge, Envoyer, or Ploi to automate deployment.

Happy launching!

Share this article
Shareable URL
Prev Post

Why Cloud-Based Email (Like Zoho or Workspace) Beats cPanel Email?

Leave a Reply

Your email address will not be published. Required fields are marked *

Read next