Many developers assume Laravel requires a VPS. In reality, a Laravel application can run on a much cheaper cPanel shared hosting, as long as the host supports a compatible PHP version. This article guides you through deploying Laravel to cPanel from scratch to live, step by step.
Prerequisites
- cPanel hosting with PHP 8.1 or higher (match it to your Laravel version).
- Access to File Manager and MySQL Databases in cPanel.
- A Laravel project already running on your local machine.
Step 1: Prepare the Project Locally
Before uploading, make sure the dependencies and cache are ready. Run this in your local project:
composer install --optimize-autoloader --no-dev
php artisan config:clear
php artisan cache:clear
Compress the entire project into a .zip (excluding the node_modules folder to keep the size small). Include the vendor folder if the host does not provide Composer.
Step 2: Upload and Extract in cPanel
Ideally, place Laravel's core files outside public_html for security. Recommended structure:
/home/user/
├── laravel_app/ ← all Laravel files (app, routes, vendor, .env, etc.)
└── public_html/ ← the contents of Laravel's "public" folder go here
How to do it: upload the zip to /home/user/, extract it as laravel_app. Then move the contents of the laravel_app/public folder into public_html.
Step 3: Adjust index.php
Because the public folder has been moved, edit public_html/index.php so it points to the new location. Change these two path lines:
// BEFORE
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
// AFTER
require __DIR__.'/../laravel_app/vendor/autoload.php';
$app = require_once __DIR__.'/../laravel_app/bootstrap/app.php';
Step 4: Create the Database in cPanel
- Open MySQL Databases in cPanel.
- Create a new database, e.g.
user_appdb. - Create a database user and note its password.
- Add the user to the database with ALL PRIVILEGES.
Step 5: Configure the .env File
Edit laravel_app/.env to match your hosting credentials:
APP_ENV=production
APP_DEBUG=false
APP_URL=https://yourdomain.com
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=user_appdb
DB_USERNAME=user_appuser
DB_PASSWORD=secretpassword
Set APP_DEBUG=false in production so error details are not exposed publicly.
Step 6: Migrate the Database
If your host has Terminal access in cPanel, run:
cd laravel_app
php artisan migrate --force
php artisan storage:link
If there is no Terminal, you can import the database structure via phpMyAdmin (export from local first), or create a temporary route that calls Artisan::call('migrate') and delete it once done.
Step 7: Generate APP_KEY & Clear the Cache
php artisan key:generate
php artisan config:cache
php artisan route:cache
If there is no Terminal, fill in APP_KEY manually with the value from your local project (the APP_KEY=base64:... line in your local .env).
Step 8: Set Folder Permissions
Make sure the following folders are writable by the server, so you don't get a 500 error:
chmod -R 775 laravel_app/storage
chmod -R 775 laravel_app/bootstrap/cache
Troubleshooting Common Errors
- 500 Internal Server Error: check the permissions on
storage&bootstrap/cache, and make sure the PHP version matches (change it in cPanel's "Select PHP Version" menu). - Blank page / white screen: temporarily set
APP_DEBUG=trueto see the error message, then set it back tofalse. - 404 on every page except the home page: make sure the
.htaccessfile was uploaded topublic_htmland themod_rewritemodule is enabled. - 419 error on login: see our guide on fixing the 419 Page Expired error in Laravel.
Conclusion
Deploying Laravel to cPanel shared hosting is entirely possible without a VPS — the key is separating the public folder, adjusting the paths in index.php, and setting up the .env and permissions correctly. After all the steps above, your Laravel application is publicly accessible. For higher traffic down the road, that is when you should consider upgrading to a VPS.