Instructions to upload Laravel to cPanel hosting - HOSTVN Blog

    There are a lot of tutorials out there on uploading Laravel to cPanel hosting, but they are either inaccurate or outdated. In this article, HOSTVN will guide you how to deploy Laravel on hosting most accurately.

    Instructions to upload Laravel to cPanel hosting

    Step 1: Compress the code

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

    clear cache

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

    Note:

    • For you to use git then when compressed ignores uncompressed directory .git
    • If you use Phpstorm so the code skips uncompressed directory .idea

    Screenshot_79

    Screenshot_80

    Step 2: Export the database

    After compressing the code you will need to export the database to import on 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 receive a file of the form name-database.sql Use to import into hosting in the following steps

    Screenshot_82

    Step 3: Upload code to hosting

    To upload code to hosting you log into cPanel -> Filemanger

    Screenshot_83

    Next you need to determine the directory that will contain the source code. If the domain name you want to use is the main domain name (The domain name used when registering hosting), the directory to upload the code to will be public_html. Where your domain name is domain addon or subdomain then the directory to upload will be the directory with the same name domain addon or subdomain.

    Screenshot_84

    After you've determined the directory to upload the source code, click on the folder and then select Upload -> Select Select file and choose the zipped zip file. After the upload process is complete please click on Go back to to return to the source directory

    Screenshot_86

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

    Screenshot_87

    Screenshot_88

    Screenshot_89

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

    Screenshot_90 - upload Laravel to cPanel hosting

    Screenshot_91 - upload Laravel to cPanel hosting

    Step 4: Create database, Mysql user and import Database

    After creating the Database you access 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

    After creating the database, the user and the database import, 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 : Correct true to false
    • APP_URL : Enter the domain website 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 : Enter the User Mysql created in step 4
    • DB_PASSWORD : Enter the password Mysql created in step 4

    Screenshot_98 - upload Laravel to cPanel hosting

    Step 6: Remove public from the Url

    By default of Laravel all requests will go into the public directory so there will be more in the url / public.

    Screenshot_101

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

    Screenshot_102 - upload Laravel to cPanel hosting

    Screenshot_103 - upload Laravel to cPanel hosting

    Screenshot_104 - upload Laravel to cPanel hosting

    Step 7: Some notes

    • After uploading the code you need to make sure the directory's chmod is 0755 and the file's chmod is 0644 If not, you'll get a 403 error.
    • In case of error 500 please check again PHP version on hosting and Mysql connection See if it's correct or not. For Laravel 5.6 and above use PHP 7 to give the best performance.

    Conclude

    Through this article, HOSTVN has instructed you on how to upload Laravel to cPanel hosting most accurately. If you have any comments you can leave a comment below. In addition, you can view other shared articles of HOSTVN here.

    No comments