Laravel 9 Deploy on Shared Hosting cPanel

To deploy laravel 9 on shared hosting cpanel; Through this tutorial, i am going to show you how to deploy laravel 9 project on shared hosting cpanel.

Shared hosting, also referred to as virtual hosting, is a way to host your website on a single physical server that also hosts additional sites.

Laravel 9 Deploy on Shared Hosting cPanel

Use the below given steps to deploy laravel 9 app project on shared hosting cpanel:

  • Step 1 – Compress the Entire Laravel Project Directory
  • Step 2 – Open Shared Hosting CPanel
  • Step 3 – Extract Laravel Project Directory
  • Step 4 – Update Index.php File
  • Step 5 – Upload Database
  • Step 6 – Connect App to Database Details

Step 1 -Compress the Entire Laravel Project Directory

Create zip file of your laravel project or Compress the laravel project folder on your local machine.

Step 2 – Open Shared Hosting CPanel

Open your shared hosting cPanel to deploy laravel project on Cpanel. And then follow the below steps:

  1. Click on ‘File Manager’
  2. Click on public_html
  3. Then Click on ‘Upload’
  4. Then upload the created zip file into the root directory. In side public_html direcotry.

Step 3 – Extract Laravel Project Directory

Then extract laravel project zip file inside public_html folder on web server.

Step 4 – Update Index.php File

Navigate to the public_html folder and find index.php file. Then open this file by right click on it and select Code Edit from the menu.

After that it open in next tab.

It’s time to update the following line of code into your index.php file as follow:

require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
to:
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';

Step 5 – Upload Database

Visit your shared hosting Cpanel and Create and import sql file into database as follow:

Create Database and user, as follow:

  • 1: Go to Cpanel and click database wizard
  • 2: Create new database
  • 3: Create new user
  • 4: Associate user with created database

Import sql file as follow:

  • 1: Now, you need to export your locally database as SQL file
  • 2: Go to cpanel again and click on phpmyadmin
  • 3: After that, click on your created database
  • 4: Click on import option and import sql file

Step 6 – Connect App to Database Details

Visit your uploaded laravel project root directory and open .env file. Then add database details as follow:

 DB_CONNECTION=mysql 
 DB_HOST=127.0.0.1 
 DB_PORT=3306 
 DB_DATABASE=here your database name here
 DB_USERNAME=here database username here
 DB_PASSWORD=here database password here

Note that these details are entered correctly.

Conclusion

Deploy laravel 9 on shared hosting cpanel example; In this tutorial, you have learned from scratch on how to deploy laravel 9 project on shared hosting cpanel.

Recommended Laravel Tutorials

Be First to Comment

Leave a Reply

Your email address will not be published.