How to Deploy a Laravel App to cPanel

So you’ve developed a fantastic Laravel application and now it’s time to deploy it for the world to see. In this article, we’ll guide you through the process of deploying your Laravel app to cPanel, a popular web hosting control panel.

Step 1: Install Laravel on your cPanel server

Before you can deploy your Laravel app, you need to make sure that Laravel is installed on your cPanel server. If you haven’t already done so, follow these steps to install Laravel:

  • Log in to your cPanel account and navigate to the ‘File Manager’
  • Create a new directory where you want to install Laravel
  • Download Laravel using Composer by running the command composer create-project --prefer-dist laravel/laravel myLaravelApp

Step 2: Configure the .env file

Next, you’ll need to configure the .env file for your Laravel app. This file contains important settings such as your database connection details and app key. Follow these steps to configure the .env file:

  • Navigate to the root directory of your Laravel app
  • Make a copy of the .env.example file and rename it to .env
  • Edit the .env file and update the following settings:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_database_username
DB_PASSWORD=your_database_password

Step 3: Uploading your Laravel app to cPanel

Once you have Laravel installed and configured, it’s time to upload your app to cPanel. Follow these steps to upload your Laravel app:

  • Zip your Laravel app folder
  • Upload the zip file to the directory where you want to deploy your app
  • Extract the contents of the zip file

Step 4: Set the document root

To ensure that your Laravel app is served correctly, you need to set the document root to the public directory of your Laravel app. Follow these steps to set the document root:

  • Log in to your cPanel account and navigate to ‘Domains’ -> ‘Addon Domains’
  • Click on ‘Document Root’ and set it to the ‘public’ directory of your Laravel app

Step 5: Update your database

Lastly, you need to update your database with the necessary tables and data for your Laravel app to function properly. You can do this by running the following command in the terminal:

php artisan migrate

And that’s it! Your Laravel app is now deployed to cPanel and ready to be accessed by users around the world. We hope this guide has been helpful in getting your Laravel app up and running on cPanel. Happy coding!