Situs Web QUAPE

Cara Menginstal Laravel di cPanel Langkah demi Langkah

Cara Menginstal Laravel di cPanel Langkah demi Langkah

Laravel is a world-class PHP framework known for its elegant syntax, powerful features, and robust developer ecosystem. However, deploying it on traditional shared hosting or a cPanel environment isn’t as simple as uploading files.

Unlike a one-click install for an app like WordPress, Laravel is a modern framework that relies on a dependency manager (Composer) and has a specific public directory structure for security. A common hurdle for developers is correctly pointing the domain to Laravel’s /public map.

This guide will walk you through the professional, step-by-step method to install a fresh Laravel application on any cPanel-powered host using Composer and the built-in Terminal.

Steps to install Laravel on cPanel Hosting

Steps to install Laravel on cPanel Hosting

Before You Begin: Prerequisites

To follow this guide, you will need:

  • cPanel Access: Full access to your hosting control panel.
  • Terminal or SSH Access: Most modern cPanel hosts (like Quape) include a “Terminal” feature. Full SSH access is even better, but the cPanel Terminal is all you need.
  • Correct PHP Version: Laravel 11 (the current version) requires PHP 8.2 or higher.
  • Composer: Laravel’s dependency manager. We will check if it’s installed.

Step 1: Set Up Your cPanel Environment

First, we need to ensure your server is ready for Laravel.

1. Set the Correct PHP Version

  1. In your cPanel dashboard, find and click on “Select PHP Version” (it may be called “MultiPHP Manager” on some hosts).
  2. If you are using “MultiPHP Manager,” select your domain from the list and choose PHP 8.2 atau PHP 8.3 from the dropdown menu, then click “Apply.”
  3. If you are using “Select PHP Version,” set the “Current PHP version” to 8.2 or 8.3.

2. Enable Required PHP Extensions

In the same “Select PHP Version” screen, click on the “Extensions” tab. Laravel requires several extensions to be enabled. Ensure the following are all checked:

  • dom
  • fileinfo
  • mbstring
  • openssl
  • pdo_mysql (if you’re using MySQL)
  • xml
  • ctype
  • json

Click “Save” if you make any changes.

Step 2: Access the Terminal and Check for Composer

Now, let’s go to the command line.

  1. In your cPanel dashboard, find and click on the “Terminal” icon (usually under the “Advanced” section). This will open a command-line interface directly in your browser.
  2. To verify Composer is installed and available, type the following command and press Enter:
    composer -V
    
  3. If you see a version number (e.g., Composer version 2.7.6...), you are ready to proceed! If not, you may need to install Composer manually or ask your hosting provider to enable it. Modern developer-friendly hosts should have it pre-installed.

Step 3: Install Laravel Using Composer

This is where we create the actual project. It’s a security best practice to install Laravel di luar of your publik_html direktori. This keeps your sensitive files (like .env) from being publicly accessible.

  1. You should already be in your home directory (e.g., /home/your_username). This is the perfect place.
  2. Run the following Composer command to create a new Laravel project. You can replace my_project with your desired application name.
    composer create-project laravel/laravel my_project
    
  3. Composer will now download Laravel and all its dependencies. This may take a minute or two. Once it’s finished, you will have a new directory named my_project in your home folder.

Step 4: The Critical Step — Point Your Domain to the /public Folder

This is the most important part and the one most people get wrong. Your domain needs to point to /home/your_username/my_project/public, not just /home/your_username/public_html.

You have two primary methods to accomplish this. Method 1 is the cleanest and most recommended.

Method 1: The Best Way (Using a Subdomain)

Using a subdomain is the easiest way to control the “Document Root” (the folder the domain loads).

  1. Di cPanel, buka “Subdomain”.
  2. Create a new subdomain (e.g., app atau laravel).
  3. Select the parent domain (e.g., domainanda.com).
  4. Crucially: Di dalam “Document Root” field, cPanel will auto-fill something like public_html/app. Delete this and replace it with the exact path to your Laravel project’s public folder:publik_html (This is wrong!) home/your_username/my_project/public (This is correct!)

    Note: cPanel might just show the field editable after public_html/. You may need to click outside the box to edit the full path. If you can’t, use Method 2.

  5. Klik "Membuat". Your subdomain app.yourdomain.com now points directly to your Laravel application’s entry point.

Method 2: The Symlink Way (For Your Primary Domain)

If you harus use your primary domain (e.g., domainanda.com) and it’s tied to the publik_html folder, this is the best workaround. We will replace the publik_html folder with a “symbolic link” (a shortcut) to our project’s public directory.

  1. Di cPanel, buka “File Manager”.
  2. If you have an existing publik_html folder, back up any files inside it, Kemudian delete the folder.
  3. Kembali ke cPanel Terminal.
  4. Run the following command to create the symbolic link. Make sure to replace your_username Dan my_project with your actual paths.
    ln -s /home/your_username/my_project/public /home/your_username/public_html
    

This command tells the server, “When someone asks for publik_html, just send them to my_project/public instead.”

Step 5: Configure Your Environment (.env) File

Your Laravel app needs to connect to a database and know its own URL.

  1. Create a Database: Di cPanel, buka “MySQL Database Wizard”. Follow the steps to create a new database, a new user, and add that user to the database with “All Privileges.” Note down the database name, username, and password.
  2. Edit the .env Mengajukan:
    • In the cPanel Manajer Berkas, navigate to your project folder (e.g., /home/your_username/my_project).
    • You may need to click “Settings” and “Show Hidden Files” to see the .env mengajukan.
    • If you only see .env.example, right-click it and “Copy” it to a new file named .env.
    • Klik kanan .env file and select “Edit.”
    • Perbarui APP_URL to match your subdomain or domain: APP_URL=https://app.yourdomain.com
    • Perbarui DB_ values with the database, username, and password you just created. Catatan: In cPanel, the database and username are often prefixed (e.g., cpaneluser_mydb, cpaneluser_dbuser).
      DB_HOST=127.0.0.1
      DB_DATABASE=cpaneluser_mydb
      DB_USERNAME=cpaneluser_dbuser
      DB_PASSWORD=your_strong_password
      
  3. Generate App Key: Di dalam Terminal, navigate to your project folder (cd my_project) and run:
    php artisan key:generate
    

Step 6: Run Migrations and Test

You’re all set! Let’s test the database connection and see the site.

  1. Di dalam Terminal, while inside your project directory, run the database migrations:
    php artisan migrate
    
  2. If it says “Migration successful,” your database connection is working perfectly!
  3. Open your browser and navigate to the subdomain or domain you configured.

You should now see the default Laravel welcome page.

Conclusion: Your Laravel App is Live on cPanel

While deploying Laravel on cPanel involves more steps than a simple upload, it’s a very manageable process. By using Composer in the Terminal and correctly setting your document root, you’ve created a secure, professional, and high-performance setup.

This entire workflow depends on a hosting environment that gives developers the tools they need. A reliable host with SSH/Terminal access, up-to-date PHP versions, and full Git/Composer support is essential. At Quape, our hosting web are designed for modern developers, providing the power and flexibility you need to run frameworks like Laravel right out of the box.

paket hosting web

Achmad Farid
Achmad Farid

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

Mari Berhubungan!

Bermimpilah besar dan mulailah perjalanan Anda bersama kami. Kami berfokus pada inovasi dan mewujudkan berbagai hal.