Laravel is a popular PHP framework used to build modern web applications. This guide explains how to deploy a Laravel application on a cPanel hosting account.
Requirements
Before starting, make sure you have:
-
A Laravel application/project
-
cPanel access
-
A domain or subdomain added to your cPanel account
-
A database and database user, if required by the application
-
A PHP version compatible with your Laravel version
-
Required PHP extensions
-
Composer, if required by the application
-
Your Laravel
.envconfiguration
Important: Always check the PHP version and system requirements of your Laravel version before deployment.
1. Upload Your Laravel Application
-
Log in to cPanel.
-
Open File Manager.
-
Upload your Laravel project as a
.zipfile. -
Extract the project into your home directory or another location outside the public web directory.
For example:
/home/USERNAME/laravel-app/
The Laravel project should contain files and directories such as:
app/
bootstrap/
config/
database/
public/
resources/
routes/
storage/
artisan
composer.json
.env
Important: Do not expose the entire Laravel project directly to the Internet. The
publicdirectory should be the web-accessible directory.
2. Configure the PHP Version
Go to:
cPanel → MultiPHP Manager
Select your domain and choose a PHP version compatible with your Laravel application.
You can check the PHP version available through Terminal using:
php -v
You should also make sure the required PHP extensions are enabled.
Common Laravel extensions include:
Ctype
cURL
DOM
Fileinfo
Filter
Hash
Mbstring
OpenSSL
PCRE
PDO
Session
Tokenizer
XML
If the application uses MySQL, the appropriate database driver such as pdo_mysql should also be available.
You can check enabled CLI extensions using:
php -m
For example:
php -m | grep -i curl
Note: The PHP version used by the website may differ from the PHP version used by the command line. Verify the domain's PHP version in cPanel as well.
3. Create a Database
If your Laravel application requires a database, go to:
cPanel → MySQL Databases
Create:
-
A new database
-
A database user
-
A strong password
-
Add the database user to the database
-
Grant the required privileges, normally ALL PRIVILEGES
Keep the following information ready:
Database Name
Database Username
Database Password
Database Host
On many cPanel servers, the database host is:
localhost
Note: The database host may differ depending on the hosting environment. Use the database host provided by your hosting provider if it is different.
4. Configure the .env File
Open your Laravel project's .env file and update the application and database settings.
Example:
APP_NAME="My Laravel Application"
APP_ENV=production
APP_KEY=
APP_DEBUG=false
APP_URL=https://yourdomain.com
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=cpuser_database
DB_USERNAME=cpuser_dbuser
DB_PASSWORD=your_database_password
Replace the database values with the credentials created in cPanel.
Important
For a live/production website, make sure:
APP_DEBUG=false
Do not leave application debugging enabled on a production website because it can expose sensitive application information.
Security: Never expose the
.envfile publicly. It may contain database credentials, API keys, and other sensitive information.
5. Configure the Document Root
Laravel is designed so that only the public directory is accessible from the web.
The recommended document root is:
/home/USERNAME/laravel-app/public
Configure your domain or subdomain's document root to point to the Laravel application's public directory whenever your hosting environment allows it.
The request flow should be:
Domain
↓
Laravel /public
↓
public/index.php
↓
Laravel Application
Important: Avoid making the entire Laravel project publicly accessible because files such as
.env,app/,config/, and other application files should not be directly accessible from the Internet.
Note: If your hosting environment does not allow changing the document root, follow your hosting provider's recommended Laravel deployment procedure.
6. Install Composer Dependencies
Open:
cPanel → Terminal
Navigate to your Laravel project:
cd ~/laravel-app
Check whether Composer is available:
composer -V
If Composer is available, install the required production dependencies:
composer install --no-dev --optimize-autoloader
This installs the packages required by the application and creates the vendor directory.
If Composer reports an error, check the PHP version, required extensions, and the specific error message before making changes.
Note: Composer availability and the Composer command may vary depending on the hosting environment.
7. Generate the Laravel Application Key
From inside the Laravel project directory, run:
php artisan key:generate
This generates the APP_KEY in the .env file.
You can verify that an application key exists using:
grep APP_KEY .env
8. Import or Create the Database
If you have an existing database backup, import it using:
cPanel → phpMyAdmin
If the application uses Laravel migrations, run:
php artisan migrate --force
Warning: Only run migrations when you understand the application's database structure and deployment requirements.
9. Configure Laravel Storage
If your application uses file uploads, run:
php artisan storage:link
This creates the symbolic link required for files stored in Laravel's public storage to be accessible through the website.
Note: Some hosting environments restrict symbolic links. If the command is not permitted, check your hosting provider's restrictions or recommended procedure.
10. Set Required Permissions
Laravel requires write access to:
storage/
bootstrap/cache/
If you receive permission-related errors, check the ownership and permissions of these directories.
Avoid using:
chmod -R 777
as a permanent solution on a production website.
Important: The correct ownership and permission settings depend on the hosting environment. Follow your hosting provider's recommended permissions if available.
11. Clear Laravel Cache
After changing the .env file or other configuration, run:
php artisan optimize:clear
For production deployments, you may then cache the configuration:
php artisan config:cache
php artisan route:cache
php artisan view:cache
Important: Make sure your
.envconfiguration is correct before caching the configuration.
12. Configure SSL
Make sure SSL is enabled for your domain.
Your application should be accessible through:
https://yourdomain.com
If the website works on HTTP but not HTTPS, check the domain's SSL configuration and Laravel's application URL.
13. Configure Cron Jobs
Some Laravel applications require scheduled tasks.
The Laravel scheduler uses:
php artisan schedule:run
You can configure this through:
cPanel → Cron Jobs
The exact PHP executable path may vary depending on the server's PHP configuration.
Note: Check your application's Laravel documentation or deployment instructions to determine the required cron schedule.
14. Configure Queue Workers
If your Laravel application uses queues, a queue worker may need to be configured.
For example:
php artisan queue:work
Queue configuration depends on the application and hosting environment.
Important: A persistent queue worker may not be supported on all shared hosting environments. Check with your hosting provider for supported queue-worker or process-management options.
Troubleshooting Common Laravel Errors
500 Internal Server Error
A 500 error can be caused by:
-
PHP errors
-
Incorrect
.envconfiguration -
Missing Composer dependencies
-
Incorrect permissions
-
Missing PHP extensions
-
Application code errors
First check the Laravel log:
cd ~/laravel-app
tail -n 100 storage/logs/laravel.log
You can also monitor the log in real time:
tail -f storage/logs/laravel.log
"No application encryption key has been specified"
Run:
php artisan key:generate
Then check that APP_KEY exists in .env.
Database Connection Error
Check the following values in .env:
DB_HOST=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
Also make sure the database user has been added to the database with the required privileges.
Class or Interface Not Found
Try reinstalling Composer dependencies:
composer install --no-dev --optimize-autoloader
Make sure the vendor/ directory exists.
If the error persists, check whether the PHP version and installed dependencies meet the application's requirements.
Images or Uploaded Files Are Not Showing
Run:
php artisan storage:link
Then verify:
-
Storage configuration
-
File permissions
-
The existence of the required files
-
The application's filesystem configuration
404 Not Found
Check:
-
The domain's document root
-
Laravel's
publicdirectory -
.htaccess -
Application routes
-
Domain configuration
The domain should normally point to:
/home/USERNAME/laravel-app/public
403 Forbidden
Check:
-
File and directory permissions
-
Document root
-
.htaccess -
Directory access restrictions
-
Web server configuration
Composer Dependency Error
Check:
php -v
composer -V
Then review the Composer error carefully.
Common causes include:
-
Incompatible PHP version
-
Missing PHP extension
-
Incompatible package version
-
Incorrect
composer.json -
Package dependency conflicts
Final Deployment Checklist
Before considering the deployment complete, verify:
-
Domain/subdomain is added to cPanel
-
Compatible PHP version is selected
-
Required PHP extensions are enabled
-
Laravel project is uploaded correctly
-
Document root points to the
publicdirectory -
Database is created if required
-
Database user is connected to the database
-
.envis configured -
APP_KEYis generated -
Composer dependencies are installed
-
Database is imported or migrations are completed
-
storage:linkis configured if required -
Required permissions are set
-
Laravel cache is cleared/configured
-
SSL is working
-
Website loads correctly
-
Login and major functionality are tested
-
File uploads are tested
-
Email/API functionality is tested if required
-
Cron jobs are configured if required
-
Queue workers are configured if required and supported
Useful Laravel Commands
php artisan about
php artisan key:generate
php artisan migrate --force
php artisan storage:link
php artisan optimize:clear
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan queue:work
php artisan schedule:run
Important Security Notes
-
Never expose the
.envfile publicly. -
Keep
APP_DEBUG=falseon production websites. -
Do not use
chmod 777as a permanent permission fix. -
Do not share database passwords or API keys publicly.
-
Do not place the entire Laravel project inside the publicly accessible document root.
-
Keep Laravel, Composer packages, PHP, and other dependencies updated where compatible with the application.
-
Take appropriate backups before major application or database changes.