[Info] Hướng dẫn upload Laravel lên hosting cPanel

Currently there are a lot of tutorials on the net regarding uploading Laravel to cPanel hosting, but they are all incorrect or out of date.

There are a lot of tutorials out there on the net regarding uploading Laravel to cPanel hosting now, but they are all incorrect or out of date. In this article, HOSTVN will guide you how to deploy Laravel on hosting correctly.

Instructions for uploading Laravel to cPanel hosting

Step 1: Compress the code

The first step to do is to compress the entire code as a zip file so that it can be uploaded to the hosting quickly. But remember before compressing the code, please clear all Laravel cache with the following command:

php artisan cache:clear
php artisan view:clear

clear cache

After clearing the cache, you proceed to compress the code as a zip file with Winrar.

Note:

  • For those of you who use git then, when compressing, skip not compressing the directory .git
  • If you use Phpstorm to code, skip uncompressing the folder .idea

Screenshot_79

Screenshot_80

Step 2: Export the database

After you have compressed the code, you will need to export to the database to import to hosting. If you are using Localhost software like Xampp, Laragon, you can use Phpmyadmin to export the database as a .sql file.

Screenshot_81

After exporting you will get a file in the form name-database.sql used to import to hosting in the following steps

Screenshot_82

Step 3: Upload the code to hosting

To upload the code to your hosting, log in to cPanel -> Filemanger

Screenshot_83

Next you need to specify the folder that will contain the source code. If the domain name you want to use is the main domain name (Domain name used when registering for hosting), the directory where you need to upload the code will be public_html. Where your domain name is domain addon or subdomains then the folder to upload will be the folder with the same name as domain addon or subdomains.

Screenshot_84

After determining the folder to upload the source code, click on the folder then select Upload -> Select Select files and select the compressed zip file. Once the upload is complete, click Go back to to return to the directory containing the source code

Screenshot_86

Next, right click on the zip file and select Extract to extract it

Screenshot_87

Screenshot_88

Screenshot_89

After extracting, don’t forget to delete the zip file that you have uploaded

Screenshot_90 - upload Laravel to cPanel hosting

Screenshot_91 - upload Laravel to cPanel hosting

Step 4: Create database, user Mysql and import Database

After you have created the Database, you can access it Phpmyadmin and select the database to import the exported database in step 2

Screenshot_93 - upload Laravel to cPanel hosting

Screenshot_94 - upload Laravel to cPanel hosting

Screenshot_95 - upload Laravel to cPanel hosting

Step 5: Configure the database connection in the .env . file

Before the name to be able to view and edit the file .envyou need to enable show hidden files

Screenshot at Dec 29 10-10-51

After creating the database, user, import database, you proceed to configure the database connection in the file .env. Right click on the .env file and select Edit

Screenshot_96 - upload Laravel to cPanel hosting

Screenshot_97 - upload Laravel to cPanel hosting

Here you need to correct some of the following information

  • APP_DEBUG : Change true to false
  • APP_URL : enter the website domain in the form http://domain.com or https://domain.com if using SSL
  • DB_DATABASE : Enter the name of the database created in step 4
  • DB_USERNAME : Fill in the Mysql User created in step 4
  • DB_PASSWORD : Enter the User Mysql password created in step 4

Screenshot_98 - upload Laravel to cPanel hosting

Step 6: Remove public from Url

By default of Laravel all requests will go to the public folder so in the Url there will be /public.

Screenshot_101

To remove /public from the url you create a file .htaccess directory peer public with the following content

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/public/
    RewriteRule ^(.*)$ /public/$1 [L,QSA]
</IfModule>

Screenshot_102 - upload Laravel to cPanel hosting

Screenshot_103 - upload Laravel to cPanel hosting

Screenshot_104 - upload Laravel to cPanel hosting

Step 7: Setup Cronjob

In case you use Laravel’s queue work, you will need to configure Cronjob on hosting to work. Access cPanel -> Cron Jobs to configure Cron

Screenshot_106

Here you configure the cronjob similar to the following

Screenshot_107

Screenshot_108

/usr/local/bin/php /home/support1/public_html/artisan queue:work --sleep=1 --tries=3 --timeout=120 >/dev/null 2>&1

In there:

  • /home/support1/public_html/ : Path to the directory containing the code
  • >/dev/null 2>&1 : Don’t spam mail every time you run cronjob

Step 8: Some notes

  • After uploading the code, you need to make sure the chmod of the folder is 0755 and the chmod of the file is 0644 otherwise you will get a 403 error.
  • In case of error 500, please check again PHP version on hosting and Mysql connection see if it is correct. For Laravel 5.6 and above use PHP 7 for best performance.

Conclusion

Through this article, HOSTVN has guided you in detail how to upload Laravel to cPanel hosting in the most accurate way. If you have any suggestions, you can leave a comment below. In addition, you can register to use cheap hosting or see other shared articles of HOSTVN here.

Viết một bình luận

bahis10bets.com betvole1.com casinomaxi-giris.com interbahis-giris1.com klasbahis1.com mobilbahisguncelgiris1.com piabetgiris1.com tipobettgiris.com tumbetgiris1.com betboro 1xbet giriş
bahis10bets.com betvole1.com casinomaxi-giris.com interbahis-giris1.com klasbahis1.com mobilbahisguncelgiris1.com piabetgiris1.com tipobettgiris.com tumbetgiris1.com betboro 1xbet giriş
antalya bayan escort
antalya bayan escort
antalya bayan escort