Laravel 8 E-Commerce - Project Deployment On Shared Hosting
In this video, we will learn how to deploy a Laravel project on shared hosting.
Let's explore the steps to deploy our Laravel project on shared hosting.
First, go to the project directory and select all files. Compress these files into a zip file by right-clicking and choosing "Compress to zip file".
Next, go to http://localhost/phpmyadmin/ and open the database laravel8ecommercedb. Export this database by clicking on the "Export" link and selecting the .sql format.
This will generate a laravel8ecommercedb.sql file.
Now, log in to your shared hosting cPanel and check the PHP version. In the "Software" section, click on "Change version" and verify that the current version is PHP 7.2. However, Laravel 8 requires PHP 7.3, so let's change the PHP version to 7.3 and click "Save".
Return to the cPanel dashboard and create a new database. Click on "Database" and enter a name for the database, such as ecommerce.
Add a new user and enter the username and password. Assign privileges to the user by selecting the user and database in the "Privileges" section. Click "Add" and select all privileges, then click "Save".
Go back to the cPanel dashboard and click on the "phpMyAdmin" icon. Open the database and click on the "SQL" tab. Open the exported database SQL file in a text editor, copy all the text, and paste it into the SQL tab. Click "Go".
All tables should now be added to the database.
Next, upload the project zip file. Open the "File Manager" and navigate to the public_html directory. Click on "Upload" and browse to the project zip file. Select the file and click "Upload".
Extract the zip file and delete the original zip file.
Open the public folder and move all files to the public_html directory. Select all files, click "Move", and remove the public path from the file path. Click "Move".
Open the index.php file and make the necessary changes:
<?php
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Check If Application Is Under Maintenance
|--------------------------------------------------------------------------
|
| If the application is maintenance / demo mode via the "down" command we
| will require this file so that any prerendered template can be shown
| instead of starting the framework, which could cause an exception.
|
*/
if (file_exists(__DIR__.'/storage/framework/maintenance.php')) {
require __DIR__.'/storage/framework/maintenance.php';
}
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| this application. We just need to utilize it! We'll simply require it
| into the script here so we don't need to manually load our classes.
|
*/
require __DIR__.'/vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/
$app = require_once __DIR__.'/bootstrap/app.php';
$kernel = $app->make(Kernel::class);
$response = tap($kernel->handle(
$request = Request::capture()
))->send();
$kernel->terminate($request, $response);
Add the database credentials to the .env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=databasename_here
DB_USERNAME=user_here
DB_PASSWORD=password_here
That's it! Let's check the result.
Go to http://yourdomain.com/ and verify that our e-commerce project is now live.
In this way, you can deploy a Laravel project on shared hosting.