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 Use L5-Swagger for API Documentation in Laravel

Integrating Swagger in Laravel: Annotations, JSON, and YAML What is Swagger? Swagger (OpenAPI) is a powerful tool for generating interactive API documentation. It helps developers understand and test your API easily. ✅ Step-by-Step Guide to Setup L5-Swagger 1. Install L5-Swagger Package composer require "darkaonline/l5-swagger" 2. Publish Config & View Files This command publishes the config file to config/l5-swagger.php : php artisan vendor:publish --provider "L5Swagger\L5SwaggerServiceProvider" 3. Configure Swagger (Optional) Edit the file config/l5-swagger.php to update: API Title Base Path Directories to scan for annotations 4. Add Swagger Annotations Add these before your controller class: /** * @OA\Info( * version="1.0.0", * title="Your API Title", * description=...

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...

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...