Need to have your .LK Domain within 15 mins? - Click Here

How to Host a Laravel Website Using cPanel Step-by-Step Guide

Laravel is a powerful tool for building websites. But once your Laravel site is ready, you need to make it available online so that others can access it. If your web host uses cPanel, this guide will show you how to host your Laravel website there, without complicated technical talk!

Step 1: Prepare Your Laravel Project

Before uploading your project to cPanel, do these on your computer:

    • Run composer install in your Laravel project folder.

    • configure your .env file with your settings.

    • Run php artisan key: generate to create your app key.

    • To create a database, run php artisan migrate to create tables.

Step 2: Log in to cPanel

    • Go to your cPanel login page.

    • Enter your username and password.

Step 3: Upload Your Laravel Files

  Option A: Upload ZIP file

    1. Compress your Laravel project folder into a ZIP file format.

    2. In cPanel, go to File Manager.

    3. go to the public_html folder.

    4. Upload your project ZIP file here.

    5. After uploading, select the ZIP file and click Extract to unzip it.

  Option B: Upload files via FTP

    • Use an FTP client like FileZilla.

    • Connect to your hosting server using FTP details.

    • Upload all your Laravel files into public_html.     

Step 4: Set the Correct Public Folder

Laravel’s main entry point is the public folder. But by default, cPanel points to public_html.

Here’s what to do:

    • Create a folder outside the public_html and move the other Laravel files and folders (like app, bootstrap, routes, etc) outside public_html — place them into that folder you already created.

    • Select all the stuff inside and move everything inside the public folder to the public_html folder.

    • Open the index.php file inside public_html.

    • Edit these two lines to point to the correct Laravel folder path: (Imagine you created a folder called "laravel_test".This is how you need to change this code.)

           require __DIR__.'/../laravel_test/bootstrap/autoload.php';

           $app = require_once __DIR__.'/../laravel_test/bootstrap/app.php';

Change '../' to the path where you put the Laravel files if needed.

Step 5: Set File and Folder Permissions

    • Log in to cPanel and open the File Manager.

    • Select the storage folder, then select Change Permissions

    • Set the permissions to 775 so that Laravel can read and write files there.

    • Do the same with the bootstrap/cache folder.

    • This step will be important for your website to run smoothly.

Step 6: Create Your Database in cPanel

 In cPanel, go to MySQL Databases. (Recommend choosing the cPanel Database Wizard to create a database)

    • Create a new database, giving it a name you will remember. 

    • Create a new database user and assign it a strong password.

    • Make sure to give this user all privileges on the database.

    • After that, update your Laravel .env file with the database name, username, and password so your app can connect to it.

Step 7: Perform database migrations, if necessary

    • Open a terminal or SSH if your host permits it.

    • To automatically set up your database tables, run this command:

           php artisan migrate

    • If you don't have SSH access, how can you migrate PHP Artisan? No issue! You can use phpMyAdmin to import your database.    

Step 8: Give Your Website a Test

    • Launch your web browser.

    • If all went according to plan, your Laravel site will be live and operational after you enter the domain name of your website and press Enter.

Final Advice: 

    • Protect your .env file, which contains sensitive information, and never share it with the public.

    • To protect your visitors, turn on SSL (HTTPS); many hosts provide free certificates.

    • Verify your file permissions and folder paths are correct if you encounter any problems.

  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

How to fix Wordpress 403 Forbidden error?

You can easy to fix this 403 Forbidden Error in WordPress. Login to cPanel > ModSecurity....

How to Speed up your WordPress site by AccelerateWP

Here is the method to Speed up your WordPress site. After do this, your sites will be load faster...

How to Install a Node.js App in cPanel – Easy Guide

If you have a Node.js app and want to run it on your hosting, cPanel makes it easy to do so. You...

How to Install WordPress with Softaculous Step-by-Step

Step 1: Log in to cPanel   • Open your hosting login page (usually something like...