How to Deploy GitHub Repositories to Cpanel | Learn Git Version Control and SSH key | Step by Step 🔥
Table of Contents
Introduction
This tutorial will guide you through the process of deploying GitHub repositories to cPanel using Git version control and SSH keys. By following these steps, you'll learn how to set up your environment, create SSH keys, and manage your Laravel project effectively on cPanel. This process is essential for developers looking to streamline their deployment workflows.
Step 1: Login to cPanel and Create SSH Key
-
Login to Your cPanel Account
- Access your cPanel account via your hosting provider’s URL.
-
Open the Terminal
- Navigate to the terminal or SSH access section in cPanel.
-
Generate SSH Key
- Use the following command to create an SSH key:
ssh-keygen -t ed25519 -C "your_email@example.com"
- This will create a new SSH key using the ed25519 encryption algorithm.
- Use the following command to create an SSH key:
-
Save the Key
- When prompted, save the key to the default location (usually
~/.ssh/id_ed25519
) and press Enter.
- When prompted, save the key to the default location (usually
-
Authorize the Key
- Copy the public key to the authorized_keys file:
cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keys
- Copy the public key to the authorized_keys file:
Step 2: Configure SSH Key with GitHub
-
Copy the SSH Key
- Display your public key using:
cat ~/.ssh/id_ed25519.pub
- Copy the displayed key to your clipboard.
- Display your public key using:
-
Add SSH Key to GitHub
- Go to your GitHub account settings.
- Navigate to SSH and GPG keys.
- Select "New SSH key," paste your key, and give it a title.
-
Test the Connection
- Use the following command to check the connection:
ssh -T git@github.com
- You should receive a success message confirming the connection.
- Use the following command to check the connection:
Step 3: Set Up Git Version Control in cPanel
-
Open Git Version Control
- In cPanel, find the "Git Version Control" feature.
-
Create a Repository
- Click on "Create" to start a new repository.
- Enter your GitHub project’s SSH link as the repository path.
-
Select the Write Folder
- Choose the directory where you want to deploy your project.
- Ensure that this folder is empty before proceeding.
Step 4: Configure Your Laravel Project
-
Create a .cpanel.yml File
- In your project root, create a file named
.cpanel.yml
. - Add the following code, replacing
your_cpanel_username
with your actual cPanel username:deployment: username: your_cpanel_username
- In your project root, create a file named
-
Create a .env File
- In your Laravel project, create a
.env
file. - Set up your database connection and other environment variables.
- In your Laravel project, create a
-
Open Terminal for Composer
- Access the terminal in cPanel.
-
Install Dependencies and Migrate Database
- Run the following commands:
composer install php artisan migrate
- Run the following commands:
Conclusion
Following these steps, you have successfully deployed your GitHub repository to cPanel using Git version control and SSH keys. You learned how to generate SSH keys, configure them with GitHub, set up Git in cPanel, and manage a Laravel project. For further exploration, consider learning about automated deployment tools or continuous integration to enhance your workflow even more.