
Deploy Your Laravel 8 Application With GitHub & Cpanel
Laravel is an open source PHP platform created by Taylor Otwell that's designed
to make web apps easier and faster. It follows a pattern of Model View
Controller (MVC) configuration. Laravel reuses the current components of various
frameworks that help to build a web application.
The major part is to deploy Laravel application there are so many options but i
choose Cpanel hosting because Capnel hosting is lower in cost and affordable for
small
scale business.
In this blog, I'm trying to explain how we can deploy our production ready
laravel 8 application on Cpanel shared hosting with GitHub.
Prerequisite
- PHP Version 7.3 or above
- Composer
- VScode
- XAMPP server
- GitHub Account
- Cpanel
Phase 1:
Creating Laravel 8 application
Step 1: Create laravel Project


Now We have Successfully created laravel Application.
Step 2: Local Configuration of laravel Project
Here, we have to fill Database credentials, 3rd party API keys, Mail credentials
etc.

Use following artisan commands
php artisan migrate
php artisan key:generate
php artisan storage:link



We have Done it.....!
Now We need to test our laravel application on localhost.
Now use php artisan serve

Now hit localhost url into browser given in terminal.
Output

Here We completed our Phase 1.
Phase 2:
Configuring GitHub.
Step 1: Creating Public GIT Repository

Step 2: Copy GIT Repository clone link & GIT init

Now, to initialize git in Project.
Goto root Directory of project & use following git commands.
- git init
- git remode add "repository url"
- git status (check your branch)
Finally push code to git repository
- git add .
- git commit -m "message"
- git push origin "branch name"




So now you can see your changes of git repository
Phase 3:
Configuring domain.
You can buy Cpanel from below websites
Step 1: Login to Cpanel

Step 2: create domain/subdomain to deploy laravel project

Choose domain or subdomain option as per your requirement, here in my case I'm choosing subdomain.
- Enter your subdomain name
- Domain name
- Select subdomain root Directory

- 4. hit create button

Now Goto the file manager & find the domain / subdomain folder is created or not.

Now we Successfully created subdomain.
Step 3: Project integration with GitHub repository
Select Git version control option

Here we get list of all git connected projects
let's integrate our project with git repository.

Click on create button
- 1. Copy your git repository clone link & paste it into clone url field.
- 2. Select your project Directory
- 3. Give your repository name
- 4. Press create button

Go to Cpanel and again choose Git version control you can see our subdomain directory is connected with Git repository

Now Goto Cpanel terminal
- 1. Navigate to root Directory of domain or subdomain
- 2. remove all files & folder from root directory using rm -rf command


Now Goto Git version control.
- 1. Find your repository name and verify the root directory.
- 2. Goto Manage.

- 3. Update your branch to be fetch from git
- 2. Goto Manage.

- 4. Goto Pull or Deploy Tab.

Here you can see all details of your git repository.
Choose Update from remote branch.
Now Goto File manager find your domain / subdomain root directory. Verify that your repository is cloned.

Here we completed our step 3....!
Step 4: Project Configuration & Deployement on Cpanel
There are 2 options
- Update document root directory to Public directory of laravel. (Recomended )
- Add redirection in .htaccess file in root directory. (Not Recomended)
Update domain document root directory
- Goto Domain section.
- Click on repository path.
- Change the path to Public

OR
Add redirection in .htaccess file (Not Recomended)
Adding redirection in .htaccess file in root directory leads to security
issues.
- 1. Create .htaccess file in root directory.

- 2. Add redirection code in htaccess to redirect to laravel Public folder.

- 3. Save changes.
Now Goto Cpanel terminal.
Navigate to domain / subdomain root directory
Use following commands
- 1. composer install --ignore-platform-reqs
- 2. php artisan key:generate
- 3.chmod -R 775 storage


Finally efforts are over. It's time to see results....!
Goto Your browser & hit your domain / subdomain URL.

Hurray we did It...!
10 April 2022