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

Gather these items before you start:
| Requirement | Purpose |
|---|---|
| Laravel project | The application being deployed |
| cPanel hosting account | Stores and serves the application |
| Compatible PHP version | Runs the Laravel application |
| Composer | Installs PHP dependencies |
| MySQL database | Stores application data, if required |
| File Manager or FTP | Uploads project files |
| SSH or Terminal | Runs Composer and Artisan commands |
| Domain name | Provides 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
- Run the application locally.
- Check routes, forms, database connections and other essential features.
- Resolve errors before deployment.
- 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.

i) Upload Laravel Using cPanel File Manager
- Log in to cPanel.
- Open File Manager.
- Navigate to your home directory, outside public_html.
- Create a folder for the Laravel application, such as laravel-app.
- Upload the compressed project archive.
- 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:
- Keep the main Laravel application outside public_html.
- Copy the contents of Laravel’s public folder into the domain’s web root.
- Update the paths in index.php to reference the actual application directory.
- 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.

i) Create a MySQL Database
- Open MySQL Databases or MySQL Database Wizard in cPanel.
- Create a database.
- Create a database user and password.
- Add the user to the database.
- 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=productionidentifies the production environment.APP_DEBUG=falseprevents detailed error information from being exposed to visitors.APP_KEYmust be set to a valid application key.APP_URLshould 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.

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:
| Directory | Purpose |
|---|---|
| storage | Logs, sessions, cached files and application-generated files |
| bootstrap/cache | Framework-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:
- Visit the domain using HTTPS.
- Confirm that the Laravel welcome page or application homepage loads.
- Test the main routes and navigation.
- Test database-dependent features, including login and form submissions.
- Check image and file uploads.
- Confirm that CSS and JavaScript assets load correctly.
- Test error pages and application logs.
- 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
| Error | Possible cause | What to check |
|---|---|---|
| 500 Internal Server Error | PHP error, permissions or configuration issue | Laravel logs, PHP version and folder permissions |
| 404 Page Not Found | Incorrect document root or rewrite rules | Domain document root and .htaccess |
| Database connection error | Incorrect credentials | Database name, username, password and host in .env |
| Composer dependency error | Missing PHP extension or incompatible PHP version | Composer output and PHP extensions |
| Missing CSS or JavaScript | Front-end assets not built or uploaded | Vite/Mix build output and asset paths |
| Application key error | Missing or invalid APP_KEY | Production .env configuration |
| Uploaded files do not display | Missing storage link or incorrect permissions | storage: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?

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.
Domain RegistrationFind and register the perfect domain for your website.
.COM DomainChoose a widely recognized domain to build global credibility.
Domain TransferSeamless domain transfers with zero downtime and complete control.
All TLDsFind and register your perfect domain. Choose from local and global extensions.
whoisCheck domain ownership details, expiration dates, and registrar information.
US DomainRegister a .US domain and build trust in the USA.
Web HostingEverything your website needs to run smoothly
WordPress HostingWordPress hosting that just works
Windows HostingReliable hosting for Windows environments
Reseller HostingTurn hosting into your business
Email HostingEmail that looks professional and works anywhere
cPanel HostingFull control of your hosting with cPanel
Affiliate ProgramJoin as a partner and earn commissions on every referral you send our way.
Vps HostingScalable virtual servers that expand as you need.
Dedicated ServersGet complete access and full control over your dedicated physical server.
Managed vpsNot tech-savvy? We will take care of everything with our fully managed VPS hosting for you.







