How to Deploy a Laravel Project on CPanel?

Follow the steps below to deploy a Laravel project on a CPanel:

Sign in to your CPanel

If this is your first time signing in to your CPanel, use the username and password provided to you by your web hosting company.

Upload Laravel Project to CPanel

There are several ways to upload a project to CPanel but in this example, we will use the most simple one, that is by using the File Manager.

Go inside the File Manager, you will see directories of files and folders there.

Next, compress your Laravel project folder that you want to deploy to your CPanel as a .zip file and upload it in the root directory.

After your project folder is uploaded, extract it in the root directory.

Moving Project Public Files

Before moving your project public files, you should enable Show Hidden Files from your File Manager Settings which is on the top right corner.

After enabling this, go inside the public folder of your project. Inside the public folder, you should also see .htaccess file. Now select all the files and move them to the public_html folder located in the root directory of the File Manager.

Setting Up MySQL Database on CPanel

If your project is using a MySQL database, then you should configure it next. To create a new MySQL database, click on the MySQL® Databases . From this MySQL® Databases page, you can not only create a new database but also create users and add users to your database.

After setting up your database, you should also update the MySQL configuration in your application .env configuration file. Go to your main project folder from your CPanel File Manager and look for .env file. Right click on the .env file and select the edit option.

Here is an example of a .env file. This file is usually hidden, so in order to make it visible, you should enable Show Hidden File option from the CPanel Settings.

Note: Do not forget to disable the Show Hidden File option, once setting up your configuration is complete because it contains all the sensitive data of your application.


APP_NAME=MyAppName
APP_ENV=dev
APP_KEY=base64:YHon8mjCdjcc7TE+nlzdFn+hj8KNfLJfbhsjYKD37E5s=
APP_DEBUG=false
APP_URL=https://www.mydomain.com


LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=mysql
# use localhost if 127.0.0.1 does not work
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=my_database_name
DB_USERNAME=my_user
DB_PASSWORD=my_password

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=
#MAIL_PORT=
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=
MAIL_FROM_ADDRESS=
MAIL_FROM_NAME="$${`{APP_NAME}`}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="$${`{PUSHER_APP_KEY}`}"
MIX_PUSHER_APP_CLUSTER="$${`{PUSHER_APP_CLUSTER}`}"

Connect Your Domain To Your Hosting Package

Next, if your existing domain is registered somewhere else, then you will need to update the nameservers to point to your hosting package. For example - If your domain is registered with namecheap, then you will need to sign in to your namecheap account and update the nameservers from the domain settings.

Install SSL on Cpanel

Go to Security menu of your CPanel and click on SSL/TLS Status.

install free ssl on cpanel

Next, put check mark in the domain check box and click on the Run AutoSSL button. This will install free SSL on your domain.

how to install free ssl on cpanel

That's it! You can open your browser and test your application.