Skip to main content

How to Upload a PHP/Laravel Project on cPanel

How to Upload a PHP/Laravel Project on cPanel

Deploying a Laravel project on cPanel can seem tricky, especially if you're coming from a local development environment. But don’t worry — in this post, I’ll walk you through every step to make your Laravel application live on shared hosting via cPanel.

๐Ÿ› ️ Prerequisites

  • Laravel project ready on your local machine
  • cPanel access with PHP 8.0+ support
  • Access to MySQL via phpMyAdmin

๐Ÿ“ Step 1: Prepare Your Laravel Project

  1. Run composer install --optimize-autoloader --no-dev to install only production dependencies.
  2. Run php artisan config:cache and php artisan route:cache.
  3. Zip the entire Laravel project.

๐Ÿ“ค Step 2: Upload Project to cPanel

  1. Login to your cPanel account.
  2. Open File Manager.
  3. Navigate to the public_html directory.
  4. Upload your Laravel zip file and extract it.

๐Ÿ”„ Step 3: Move Folders Appropriately

cPanel serves from public_html, but Laravel expects its entry point in public/. Do this:

  1. Move all contents from your Laravel project’s public/ folder into public_html/.
  2. Edit index.php in public_html:
    require __DIR__.'/../vendor/autoload.php';
    $app = require_once __DIR__.'/../bootstrap/app.php';
            
    Change paths to:
    require __DIR__.'/../your-laravel-folder/vendor/autoload.php';
    $app = require_once __DIR__.'/../your-laravel-folder/bootstrap/app.php';
            

๐Ÿ’พ Step 4: Set Up the Database

  1. Access phpMyAdmin:

    Log in to your cPanel dashboard. Scroll down to the Databases section and click on phpMyAdmin. This will open a web-based interface where you can manage MySQL databases.

  2. Create a New Database and User:

    Go back to the cPanel dashboard and open MySQL® Databases. Under the Create New Database section, enter a name and click Create Database.
    Scroll down to the MySQL Users section to create a new user with a secure password. After that, use the Add User to Database section to link the user with the new database.
    Ensure that All Privileges are granted to the user.

  3. Import Your Local SQL File:

    Return to phpMyAdmin and select your new database from the sidebar. Click on the Import tab in the top menu.
    Click Choose File and upload your exported .sql file from your local Laravel project. Then click Go to import the database structure and content.

  4. Configure Your Laravel .env File:

    Open the .env file in your Laravel project root and update the database configuration with the credentials created in cPanel. Example:

    
    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=your_db_name
    DB_USERNAME=your_db_user
    DB_PASSWORD=your_db_password
        

    Save the changes. If you're editing locally, re-upload the updated .env file to your server.

๐Ÿ” Step 5: Configure .env and Permissions

  • Set APP_ENV=production and APP_DEBUG=false
  • Set proper write permissions for storage and bootstrap/cache

๐ŸŒ Step 6: Test Everything

  • Clear browser cache and reload your domain.
  • If errors occur, check storage/logs/laravel.log or enable temporary debug mode.

๐ŸŽ‰ Done!

Your Laravel app should now be live on your cPanel-hosted domain. Make sure to monitor logs and update dependencies regularly.


If this helped you, feel free to share or connect with me on LinkedIn!

Comments

Popular posts from this blog

How to Display Flash Messages in EJS using Node.js and Express

Displaying Flash Messages in EJS with Node.js and Express Flash messages are a great way to give users quick feedback — like "Login successful!" or "Please enter all fields!" . In this guide, you’ll learn how to implement them using: express-session connect-flash EJS templating ๐Ÿ“ฆ Step 1: Install Required Packages npm install express express-session connect-flash ejs ⚙️ Step 2: Setup Express App and Middleware const express = require('express'); const session = require('express-session'); const flash = require('connect-flash'); const app = express(); // Set view engine app.set('view engine', 'ejs'); // Middleware app.use(express.urlencoded({ extended: true })); app.use(session({ secret: 'yourSecretKey', resave: false, saveUninitialized: true })); app.use(flash()); // Make flash messages available to all views app.use((req, res, next) => { res.lo...

Realtime Device Tracker using Node.js, Socket.IO & Leaflet

Realtime Device Tracker using Node.js, Socket.IO & Leaflet In this tutorial, you’ll learn how to build a realtime location tracking application that uses the browser’s GPS, Socket.IO for live communication, and Leaflet.js to display users on a map. ๐Ÿš€ Project Overview Backend: Node.js, Express.js, Socket.IO Frontend: HTML, Leaflet.js, Socket.IO client Features: Live GPS tracking, multi-user map, disconnect cleanup ๐Ÿ“ Folder Structure project-root/ ├── app.js ├── package.json ├── src/ │ ├── public/ │ │ ├── css/ │ │ │ └── style.css │ │ └── js/ │ │ └── script.js │ ├── routes/ │ │ └── routers.js │ ├── socket/ │ │ └── socketHandler.js │ └── views/ │ └── index.ejs ๐Ÿง  How It Works Each user shares their location using the browser's navigator.geolocation API. Location is sent to the server via Socket.IO . The server broadcasts each user’s position to all clien...

How to Send Emails in Node.js using Nodemailer and Ethereal

How to Send Email in Node.js using Nodemailer Email functionality is essential in modern web applications. Whether you're sending confirmation emails, password resets, or notifications, Node.js with Nodemailer makes this simple. In this blog, we'll walk through setting up email sending using Node.js , Express , and Ethereal Email for testing. ๐Ÿงพ Prerequisites Node.js installed Basic knowledge of Express.js Internet connection ๐Ÿ“ Project Structure project-folder/ ├── index.js ├── .env ├── package.json └── app/ └── controller/ └── emailSendController.js ๐Ÿ“ฆ Step 1: Install Dependencies npm init -y npm install express nodemailer dotenv npm install --save-dev nodemon ๐Ÿ” Configure nodemon (Optional but Recommended) Update your package.json with a custom start script: "scripts": { "start": "nodemon index.js" } ๐Ÿ” Step 2: Create a .env File Create a .env file a...