How to Upload Laravel 13 to cPanel Hosting

How to Upload Laravel 13 to cPanel Hosting

If you want to upload Laravel 13 to cPanel hosting, the process might be different from uploading other CMS platforms like WordPress. However, this method is actually the same as installing previous versions of Laravel.

You can follow this tutorial on uploading Laravel 13 to cPanel hosting if you have already built a website with Laravel 13 on localhost. Or if you do not have one yet, you can try creating it first with laravel starter on localhost, and once all configurations and the design are ready locally, you can upload it to your hosting by following the steps on this page.

How to Upload Laravel 13 to cPanel Hosting

Before starting, make sure you have built and run Laravel on localhost. When using Laravel 13 and Vite, you need to run npm build, and you cannot run this directly in cPanel unless you create a Node.js app, which actually makes deploying Laravel in cPanel more complicated.

Once it is running smoothly on localhost, you can start with the first step:

1. Prepare All Files and Upload

Open your Laravel folder on localhost, then select all files and folders except node_modules, then compress the files into a .zip file.

Cara Upload Laravel 13 ke Hosting cPanel - WPGan - 1.1

After compressing, you can upload the .zip file to the public_html folder or your domain document root from the File Manager in cPanel.

Cara Upload Laravel 13 ke Hosting cPanel - WPGan - 1.2

Once the upload is successful, make sure to extract the zip file you just uploaded.

Cara Upload Laravel 13 ke Hosting cPanel - WPGan - 1.3

2. Adjust Folder Locations

All files have been successfully uploaded to the hosting, but you cannot access the website directly yet. The solution is to go to the home folder first, then create a new folder parallel to the public_html folder, for example, a folder named laravel

Before moving the files, make sure the setting to show hidden files is enabled.

Cara Upload Laravel 13 ke Hosting cPanel - WPGan - 2.1

Now return to the public_html folder or the location where you uploaded the files previously and select all files and folders except the public folder and move them into the /laravel folder you just created.

Cara Upload Laravel 13 ke Hosting cPanel - WPGan - 2.2

Still in the first upload folder (public_html), open the publicfolder, then move all its contents to the domain document root folder (for example, public_html).

Cara Upload Laravel 13 ke Hosting cPanel - WPGan - 2.3

3. Adjust the Index File

So that the files moved to the Laravel folder can be read, you need to edit the index.php file located in the public_html folder and adjust all require directories. If you use the same folder structure as this tutorial, the index file will look like this.

<?php
use Illuminate\Foundation\Application;use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
// Determine if the application is in maintenance mode...if (file_exists($maintenance = __DIR__.'/../laravel/storage/framework/maintenance.php')) {    require $maintenance;}
// Register the Composer autoloader...require __DIR__.'/../laravel/vendor/autoload.php';
// Bootstrap Laravel and handle the request.../** @var Application $app */$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
$app->handleRequest(Request::capture());

The core of the change is adding the /laravel/ path before the Laravel core folders such as maintenance mode, autoloader, and bootstrap. If you use a different folder name, you can change the /laravel/ path to the path you created.

Cara Upload Laravel 13 ke Hosting cPanel - WPGan - 3.1

4. Adjust Environment Variables

Before accessing the website, make sure to update the .env file located in the /laravel/ folder according to your website configuration, such as base_url, database, and others. This is because when in cPanel, you cannot use the root user like you do on localhost.

If you have not created a database, you can follow this tutorial: How to Create a Database in cPanel. Also, ensure your database has been imported into cPanel. To import a database, you can follow this tutorial: How to Import a Database in cPanel

Cara Upload Laravel 13 ke Hosting cPanel - WPGan - 4.1

In Laravel 13, you usually use Vite, and there will be Vite build results that also need a symlink. Additionally, if you use storage, a symlink needs to be created for that as well.

To create a symlink, you can run this command in the Terminal found in your cPanel hosting.

# Hapus storage jika sudah ada di public_htmlrm -rf /home/contohny/public_html/storage
# Buat symlink dari public_html/storage -> laravel/storage/app/publicln -s /home/contohny/laravel/storage/app/public /home/contohny/public_html/storage
# Buat folder laravel/public/build jika belum adamkdir /home/contohny/laravel/public/ 
# Buat symlink dari laravel/public/build -> public_html/buildln -s /home/contohny/public_html/build /home/contohny/laravel/public/build

Make sure to change user with your cPanel username, and laravel with the folder path you are using. If your hosting does not have a Terminal feature, you can use a cron job to run this command by following this tutorial: How to Create a Symlink in cPanel Without SSH.

Cara Upload Laravel 13 ke Hosting cPanel - WPGan - 5.1

After all configurations are complete, you can now access your website, and the Laravel 13 project you created can now be accessed online.

Cara Upload Laravel 13 ke Hosting cPanel - WPGan - 5.2

That is the easy way to install Laravel 13 on cPanel hosting. Also, make sure to use PHP 8.4 or higher, because Laravel 13 can only run on PHP 8.4 or higher.

Written by

Muhammad Khoirun Nasikin

I enjoy tinkering with WordPress, hosting, VPS, web development, and various small experiments related to websites. I have over 3 years of experience in the web hosting industry.

COMMENTS

Loading...