India English
Kenya English
United Kingdom English
South Africa English
Nigeria English
United States English
United States Español
Indonesia English
Bangladesh English
Egypt العربية
Tanzania English
Ethiopia English
Uganda English
Congo - Kinshasa English
Ghana English
Côte d’Ivoire English
Zambia English
Cameroon English
Rwanda English
Germany Deutsch
France Français
Spain Català
Spain Español
Italy Italiano
Russia Русский
Japan English
Brazil Português
Brazil Português
Mexico Español
Philippines English
Pakistan English
Türkiye Türkçe
Vietnam English
Thailand English
South Korea English
Australia English
China 中文
Canada English
Canada Français
Somalia English
Netherlands Nederlands

How to Deploy Laravel to cPanel: A Step-by-Step Guide

Buy domains, business emails, hosting, VPS and more: Get Started

A Laravel application can work perfectly on your local machine and still refuse to run when you first upload it to a hosting account. 

Local tools hide a lot of work: the web server points at the right folder, the PHP version is already correct and the database is waiting. 

On shared hosting, you set all of that up yourself. 

This guide shows you how to deploy Laravel to cPanel without the usual surprises.

Here is what the guide covers:

  • Preparing the Laravel project for production.
  • Checking PHP and Composer requirements.
  • Uploading application files.
  • Configuring the domain’s document root.
  • Setting up the database and .env file.
  • Running Artisan commands and testing the application.

These instructions apply to an existing Laravel project that you want to put online, rather than a fresh Laravel installation. 

If your application already runs locally, you are ready to begin.

What You Need Before Deploying Laravel to cPanel

What You Need Before Deploying Laravel to cPanel

Gather these items before you start:

RequirementPurpose
Laravel projectThe application being deployed
cPanel hosting accountStores and serves the application
Compatible PHP versionRuns the Laravel application
ComposerInstalls PHP dependencies
MySQL databaseStores application data, if required
File Manager or FTPUploads project files
SSH or TerminalRuns Composer and Artisan commands
Domain nameProvides the application’s web address

SSH and Composer availability can depend on the hosting provider and package. 

If server-side Composer is unavailable, you can install dependencies locally and upload the resulting vendor directory instead. 

Check your Laravel version’s documentation for its minimum PHP version, then select that version in cPanel’s PHP settings.

a) Prepare Your Laravel Project for Deployment

Fixing problems on your own computer is far quicker than fixing them through a hosting panel. 

Spend a few minutes preparing the project before you upload anything.

i) Test the Application Locally

  1. Run the application locally.
  2. Check routes, forms, database connections and other essential features.
  3. Resolve errors before deployment.
  4. Confirm that the project uses the intended production configuration.

An error you can already see locally will appear on the server too, usually with less helpful feedback.

ii) Install Production Dependencies

Run this command in the project folder:

composer install --no-dev --optimize-autoloader

It installs the dependencies recorded in composer.lock without development packages, and it optimizes the autoloader for faster class loading. 

The result is a smaller vendor folder that contains only what the live site needs.

iii) Build Front-End Assets

For projects using Vite or another asset build system, compile the assets locally:

npm ci 
npm run build

Include the compiled assets in the deployment. 

You do not need Node.js on the hosting server if you build the assets on your own machine, which is the simplest route on shared hosting.

iv) Prepare the Project Files

Before you create the upload archive:

  • Exclude unnecessary development files such as node_modules and .git.
  • Keep composer.json and composer.lock.
  • Do not upload a development .env file containing local credentials.
  • Create a production .env file on the server, or configure it securely after uploading.

b) Upload Your Laravel Project to cPanel

You can upload the project through the browser-based File Manager or through SSH and Git. 

Pick the one that fits your access level.

Upload Your Laravel Project to cPanel

i) Upload Laravel Using cPanel File Manager

  1. Log in to cPanel.
  2. Open File Manager.
  3. Navigate to your home directory, outside public_html.
  4. Create a folder for the Laravel application, such as laravel-app.
  5. Upload the compressed project archive.
  6. Extract the archive inside the application folder.

Do not place the full Laravel project directly inside a publicly accessible directory. 

Doing so can expose configuration files and source code to anyone who guesses a URL.

ii) Upload Laravel Using SSH or Git

If your account offers SSH or Git access, you can fetch the project straight from a repository:

cd ~ 
git clone YOUR_REPOSITORY_URL laravel-app 
cd laravel-app

YOUR_REPOSITORY_URL is a placeholder, so replace it with your own address. 

Private repositories require appropriate authentication, such as a deploy key or an access token.

This method suits developers who update their applications regularly. 

Instead of uploading ZIP files again, you pull the latest changes with a single command.

c) Configure the Laravel Public Folder in cPanel

This is the most important security step when you deploy Laravel to cPanel. 

Laravel’s web-accessible files live in the public directory. 

The web server should serve that directory, not the Laravel project root. 

Everything else, including your .env file, your application code and your storage folder, should stay out of reach of the browser.

i) Point Your Domain’s Document Root to the Public Folder

A correct structure looks like this:

/home/username/
    laravel-app/
        app/
        bootstrap/
        config/
        database/
        public/
        resources/
        routes/
        storage/
        vendor/
        artisan
        composer.json
        .env

The domain’s document root should point to:

/home/username/laravel-app/public

Where your cPanel account allows it, open the Domains interface and set the document root of the domain or subdomain to that path. 

Save the change, then load the domain to confirm that Laravel responds. 

This is the cleanest arrangement, and it needs no changes to Laravel’s own files.

ii) What If You Cannot Change the Document Root?

Some cPanel environments do not let you edit the document root. In that case, use this alternative:

  1. Keep the main Laravel application outside public_html.
  2. Copy the contents of Laravel’s public folder into the domain’s web root.
  3. Update the paths in index.php to reference the actual application directory.
  4. Make sure .env, vendor, storage and other application files remain outside the public web directory.

The relevant changes in index.php look like this:

require __DIR__.'/../laravel-app/vendor/autoload.php';

$app = require_once __DIR__.'/../laravel-app/bootstrap/app.php';

The paths must match your actual folder structure. 

If your web root is public_html and the application sits beside it in laravel-app, the example above works. 

If the folders differ, adjust the paths accordingly.

Treat this as a fallback for hosts that block document root changes, not as the preferred arrangement. 

Never move the entire Laravel application into public_html, because that can expose sensitive application files.

d) Create a Database for Your Laravel Application

Most Laravel applications need a database, and cPanel makes it easy to create one.

Create a Database for Your Laravel Application

i) Create a MySQL Database

  1. Open MySQL Databases or MySQL Database Wizard in cPanel.
  2. Create a database.
  3. Create a database user and password.
  4. Add the user to the database.
  5. Grant the required privileges.

cPanel may automatically add an account prefix to database and username values, so a database you call shop might become username_shop. 

Write down the full names exactly as cPanel shows them, because Laravel needs the complete values.

ii) Update the Laravel Database Configuration

Add the details to your production .env file:

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_database_user
DB_PASSWORD=your_database_password

Use the actual credentials you created in cPanel and the database host specified by your hosting provider. 

On most cPanel servers the host is localhost, but confirm it if the connection fails.

e) Configure the Laravel Environment File

The .env file holds settings that change between environments, such as debug mode, the application URL and database credentials. 

Production settings must differ from local development settings, because a development configuration can leak details that attackers find useful.

A simplified production example looks like this:

APP_NAME="My Laravel App"
APP_ENV=production
APP_KEY=base64:YOUR_GENERATED_KEY
APP_DEBUG=false
APP_URL=https://example.com

Each setting has a job:

  • APP_ENV=production identifies the production environment.
  • APP_DEBUG=false prevents detailed error information from being exposed to visitors.
  • APP_KEY must be set to a valid application key.
  • APP_URL should use the application’s actual domain and HTTPS address.
  • Database credentials must match the cPanel database.

i) Generate the Laravel Application Key

From the project directory, run:

php artisan key:generate

This command generates the application encryption key and updates the .env file. 

Laravel uses the key to encrypt sessions and other data, so the application will not run properly without it.

If SSH is unavailable, generate the key in your local environment:

php artisan key:generate --show

Copy the value it prints and add it to the production .env file as APP_KEY.

f) Install Laravel Dependencies and Run Artisan Commands

Uploading the project does not automatically install its dependencies or prepare its database. 

A few commands finish the job.

Install Laravel Dependencies and Run Artisan Commands

i) Install Composer Dependencies

From the Laravel project directory, run:

composer install --no-dev --optimize-autoloader

If Composer is unavailable on the server, run the same command locally and upload the resulting vendor directory with the rest of the project. 

Make sure your local PHP version is close to the one on the server, so the installed packages work in both places.

ii) Run Database Migrations

php artisan migrate --force

The –force flag lets Laravel run migrations in production without the usual confirmation prompt. 

Back up existing databases before you run migrations, particularly when you deploy updates to an application that already has live data.

iii) Create the Storage Link

For applications that store publicly accessible uploaded files, run:

php artisan storage:link

This creates a symbolic link between storage/app/public and public/storage, so files saved by the application can be served through the web. 

Without it, uploaded images often return a 404 error.

iv) Clear and Cache Laravel Configuration

These commands are commonly used in production:

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

They cache configuration, routes and compiled views, which speeds up each request. 

Route caching can fail if the application contains routes that cannot be cached, such as routes defined with closures. 

If that happens, convert those routes to controller methods or skip route caching. 

Run the commands again after every change to your configuration or routes.

g) Set Laravel File and Folder Permissions

Laravel needs to write to a few directories:

DirectoryPurpose
storageLogs, sessions, cached files and application-generated files
bootstrap/cacheFramework-generated cache files

Adjust permissions through File Manager by right-clicking a folder and choosing Change Permissions, or through SSH:

chmod -R 775 storage bootstrap/cache

The correct permissions depend on the server’s PHP handler and ownership configuration. 

Do not use 777 as a general solution, since it lets any account on the server write to those folders. 

If 775 does not work, ask your hosting provider which ownership setup the account uses.

h) Test Your Laravel Application After Deployment

A short, structured test run catches most problems early:

  1. Visit the domain using HTTPS.
  2. Confirm that the Laravel welcome page or application homepage loads.
  3. Test the main routes and navigation.
  4. Test database-dependent features, including login and form submissions.
  5. Check image and file uploads.
  6. Confirm that CSS and JavaScript assets load correctly.
  7. Test error pages and application logs.
  8. Check that the application is not exposing .env or other private files.

A successful homepage load does not necessarily mean every application feature works. 

Pages that touch the database, the mail system or the file system can fail even when the homepage looks fine, which is why the checklist goes beyond the first screen. 

For the last item, try opening your-domain.com/.env in a browser. You should get an error, not a file.

How to Fix Common Laravel Deployment Errors on cPanel

ErrorPossible causeWhat to check
500 Internal Server ErrorPHP error, permissions or configuration issueLaravel logs, PHP version and folder permissions
404 Page Not FoundIncorrect document root or rewrite rulesDomain document root and .htaccess
Database connection errorIncorrect credentialsDatabase name, username, password and host in .env
Composer dependency errorMissing PHP extension or incompatible PHP versionComposer output and PHP extensions
Missing CSS or JavaScriptFront-end assets not built or uploadedVite/Mix build output and asset paths
Application key errorMissing or invalid APP_KEYProduction .env configuration
Uploaded files do not displayMissing storage link or incorrect permissionsstorage:link and storage permissions

Start with the Laravel log file in storage/logs, because it usually names the exact problem. 

After any change to .env, clear the cached configuration with php artisan config:clear so Laravel reads the new values.

Can You Deploy Laravel on Shared cPanel Hosting?

Can You Deploy Laravel on Shared cPanel Hosting?

Yes, in many cases. Laravel applications can run on shared cPanel hosting when the PHP version, extensions, dependencies and required access are available.

Small applications and projects with modest resource requirements may work well on shared hosting. 

Resource limits can affect Composer installations, migrations, scheduled tasks and application performance, so large projects may feel the strain during heavy operations.

Applications requiring persistent queue workers, WebSockets, custom server configuration or substantial resources may be better suited to a VPS, where you control the server fully.

Host Your Laravel Application With Truehost

Everything in this guide depends on the hosting environment you choose. 

Truehost cPanel hosting gives you a control panel for managing application files, databases, domains and other hosting settings in one place. 

That fits the workflow above, from the File Manager upload to the MySQL database setup.

Check the hosting page for details on PHP application support, including whether Laravel is among the supported applications, and for listed features such as SSD storage, SSL and backups. 

Before you buy, confirm the PHP version, required extensions, Composer availability and SSH access for your chosen package, since these decide how smoothly you can deploy Laravel to cPanel.

Ready to deploy your Laravel application? Explore Truehost cPanel hosting and choose a hosting plan that meets your application’s requirements.