laravel 3 years ago
php-based framework #Web Development

Deploy Laravel 8 to cPanel Shared hosting

In this video, I will show you how to easily upload a Laravel application to a shared hosting account via Cpanel

In this tutorial, you will learn from scratch on how to deploy a Laravel 8 project on shared hosting cpanel. Shared hosting is a type of Web hosting service that allows multiple websites to share a physical Web server and its resources among the hosted websites.


Upload Laravel 8 to Cpanel Step By Step

- First, compress the Entire Laravel Project Folder

- Then you can open your Shared Hosting CPanel and upload that into it.

1 - Click on ‘File Manager’

2 - Click on public_html

3 - Then Click on ‘Upload’

4 - Then upload the created zip file into the root directory.

5 - Extract the zipfile.

ALL FILES SHOULD BE IN THE public_html FOLDER!


- Once you upload and extract the files we have to make a .htaccess rewrite rule so when someone visits the website they automatically go to the public directory.


.htaccess in public_html folder:

RewriteEngine On

RewriteRule ^(.*)$ public/$1 [L]


- Update Index.php File (ALT)

Navigate to the public_html folder and find index.php file.

Then open this file by right click on it and select Code Edit from the menu.

Then update the following line of code into your index.php file as follows:


- Open Cpanel and create a MySQL user, password and database.

Create Database and user as follow:

1 - Go to Cpanel and click database wizard

2 - Create new database

3 - Create new user

4 - Associate user with created database


Import sql file as follow:

1 - Export your locally database as SQL file

2 - Go to cpanel again and click on phpmyadmin

3 - Click on your created database

4 - Click on import option and import sql file


Next, go to your uploaded project root directory and open .env file.

Then add database details as follow:

DB_CONNECTION=mysql 

DB_HOST=127.0.0.1 

DB_PORT=3306 

DB_DATABASE=your database name here

DB_USERNAME=your database username here

DB_PASSWORD=yor database password here


If you are getting can’t to connect error after this you can add a single quote 'database username' , 'databasepassword' like this in the env file. Then it will work perfectly.


Problem 1: Uncaught ErrorException: file_put_contents

Go to the directory laravel/bootstrap/cache and delete config.php file, or rename it as config.php.old

Remember to check if .env is available


Class "PDO" not found

Still a problem :(

Class \"PDO\" not found at /home/ogrooste/public_html/


NOPE...

It is not possible from cPanel, it is possible from WHM,

You will find Easy Apache in WHM to configure PHP settings

If you are on shared hosting contact your hosting provider, they will enable it for you...

NOPE...

You could use this step:

First, put this code in your .htaccess, edit with what you need:

suPHP_ConfigPath /home/your_cpanel_user/public_html


Then create php.ini in your public_html directory, then add following lines:

extension=php_pdo.dll

extension=php_pdo_firebird.dll

extension=php_pdo_informix.dll

extension=php_pdo_mssql.dll

extension=php_pdo_mysql.dll

extension=php_pdo_oci.dll

extension=php_pdo_oci8.dll

extension=php_pdo_odbc.dll

extension=php_pdo_pgsql.dll

extension=php_pdo_sqlite.dll  


Problem2: Try this if NOTHING is not working:

change

require __DIR__.'/../bootstrap/autoload.php';

$app = require_once __DIR__.'/../bootstrap/app.php';


to

require __DIR__.'/bootstrap/autoload.php';

$app = require_once __DIR__.'/bootstrap/app.php';

So remove the ../ at the beginning!









Laravel
by taylor otwell