Laravel 11,Mysqli Upload to Live Server-Cpanel

codestarch

Laravel

2025-06-02

Image

In this tutorial we look on how to upload a laravel project to live server as simple as i know how.

There are a bunch of tutorials out there that shows how to go about it but if not properly done, it can prove to be complicated or even expose the site to risks eg giving access to private files.It is important to seperate public folder files from the other project files.

This tutorial assumes you are using CPanel in Live server.

We will follow the following steps:

  1. Make sure the project is working well on the local server.
    Clean the files. Make sure all files are properly formatted and commented as much as possible for easy future references.
  2. Make a backup of your project.
  3. Configure Database and Email Server in Live server.
  • Logging to CPanel then to Manage my databases and create your database
  • Scroll down to Database users and Add a new user.
    Go to Add User to Database and add the user to database.
  • Go back to Cpanel Tools then to PhpMyAdmin and confirm your database has been added successifully.

NB: Note the Database name, Database Username and Password.

       Go back to your project in your local machine.

      4. open .env ,and edit these configurations

APP_NAME=Name-of-your-project
APP_ENV=production
APP_KEY=base64:pEKzNl2ZpgIdcikNI8XuywhdLvn3F2eyZZgcW5A7j38=
APP_DEBUG=false
APP_TIMEZONE=UTC
APP_URL=your-site-domain

       For APP_DEBUG you can leave as true if you need to debug your on live serve.Make sure to set it to false after debuging.

       APP_KEY will already been generate  when creating the project through composer but if there is no key simply run 

php artisan key:generate

       5. Edit the database configurations also. Use the details we created in the live server

           This applies to mysqli. but if using sqlite just set and upload the sqlite database

DB_CONNECTION=mysql
DB_HOST=your-site
DB_PORT=3306
DB_DATABASE=database-name
DB_USERNAME=database-username 
DB_PASSWORD=database-password

       6. Edit Email configurations

         For this tutorial we will be using third party email server.This configs are for google mail server, gmail.

        Please create an App pasword in your google account.This enables us to use gmail outside google apps.

        Checkout google mail server to learn how to create App password

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com 
MAIL_PORT=587 
MAIL_USERNAME=your-email
MAIL_PASSWORD=app-password
MAIL_ENCRYPTION=tls 
MAIL_FROM_ADDRESS="your-email"
MAIL_FROM_NAME="${APP_NAME}"

       7. Then run following code in terminal to clear config cache

php artisan config:cache

       8. Run the code to rebuild all classes

composer dump-autoload

        9. Zip the project folder.

10. Upload the zipped folder to live server

  •  Go to Cpanel Tools then File Manager and upload, Navigate to the compressed project folder  directory and select the file and upload. Locate the uploaded file and uncompress.
  •  In your project folder go to public folder and cut everything inside. 
  •  Navigate back and go to public_html and paste the files in the folder.

NB: We have seperated the public folder files from the rest of the files for security purposes.

  •  Edit these files in index.php
if (file_exists($maintenance = __DIR__.'/../your-project-folder-name/storage/framework/maintenance.php')) {
    require $maintenance;
}

require __DIR__.'/../your-project-folder-name/vendor/autoload.php';

$app = require_once __DIR__.'/../your-project-folder-name/bootstrap/app.php';

     11. Next we upload the database.

        Go to PhpMyAdmin in the local machine and open the database.Go to the Menu -> export and export.Note the directly where the database dump file has been saved.

        Back to live server, go to Cpanel Tools then PhpMyAdmin and click the database we created earlier the on menu click import the Browse and Locate the database file we exported then open.

        click import. 

     12. Browse your site to test.

         If you are using later versions of laravel probably you are using php 8.0 and above.If so you will get an php version error.

         NB:the error will be visible if you left APP_DEBUG true 

         To solve php version error,

  •  Go to Cpanel Tools and search MultiPHP Manager.
  •  You will see your site and the php version set in Live server.If your project was using example  PHP 8.2, on the right go to php version and choose PHP 8.2 (ea-php82)  and apply.

           Notice the PHP version changes. 

  • Go to Cpanel Tools, File Manager and in your-project-folder look for composer.json
  • Add  "php": "8.2.0",  as below
"config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true,
        "php": "8.2.0",
        "allow-plugins": {
            "pestphp/pest-plugin": true,
            "php-http/discovery": true
        }
    },
  • Now browse the site again

         

0 Comments


Codestarch

Enjoy quick fix with our code snippets and complete projects templates.



Useful links

Your Account

Help


Contact

codestarch@gmail.com


©2026 Copyright: All rights reserved.