How to Clone a Private Laravel Project on a VPS: Step-by-Step Guide

L earn how to securely clone a private Laravel project on your VPS. This step-by-step guide covers SSH access, setting up authentication with SSH keys or GitHub tokens, cloning the repository, installing dependencies, configuring environment variables, and setting proper permission

Follow this step-by-step guide to clone a private Laravel project on your VPS and set it up seamlessly
Follow this step-by-step guide to clone a private Laravel project on your VPS and set it up seamlessly Learn how to clone a private Laravel project onto your VPS with this detailed guide. We walk you through connecting to your VPS via SSH, setting up SSH keys or GitHub tokens for authentication, and cloning a private repository securely. Additionally, you'll learn how to install Laravel dependencies, configure environment variables, and set folder permissions to ensure your application runs smoothly. Whether you’re deploying a new project or updating an existing one, this guide will help you complete the process efficiently.

Steps to Clone a Private Repository on a VPS:
    SSH into your VPS: As usual, SSH into your VPS:
ssh username@your_vps_ip
Navigate to the desired directory: Navigate to the directory where you want to clone the project:

cd /path/to/your/project/directory
Authenticate using SSH key or GitHub Token:
Option 1: Using SSH Key
    Generate an SSH key (if you don't have one already): On your VPS, run:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Press Enter to accept the default location, and optionally, add a passphrase.

Add your SSH key to the SSH agent:

eval "$(ssh-agent -s)"

ssh-add ~/.ssh/id_rsa

ssh -T git@github.com
Copy the SSH key to your clipboard:

cat ~/.ssh/id_rsa.pub
Copy the output (your SSH public key). Add the SSH key to your GitHub account:
   git clone git@github.com:your_username/your_private_repo.git
Option 2: Using GitHub Personal Access Token
Generate a Personal Access Token:
Clone using HTTPS and authenticate with the token: When cloning, use the following syntax:

    git clone https://your_github_username:your_github_token@github.com/your_username/your_private_repo.git
    Replace your_github_username with your GitHub username, and your_github_token with the Personal Access Token you generated.

Continue with the Setup: After cloning the repository, follow the usual Laravel setup steps:

    Navigate into the project directory:  

cd your_private_repo
Install dependencies:

composer install
Set up the environment variables:

cp .env.example .env
Generate the application key:

php artisan key:generate
Set permissions:

   sudo chown -R www-data:www-data storage
   sudo chown -R www-data:www-data bootstrap/cache
This should allow you to successfully clone a private repository and set up the Laravel project on your VPS. Let me know if you need more details!


Thank you for taking the time to read my blog post! I hope this guide has been helpful in walking you through the process of cloning a private Laravel project on your VPS. Setting up projects can be challenging, but with the right steps, it becomes much easier. Whether you’re deploying a new application or managing an existing one, I’m glad I could assist you in this journey.

If you have any further questions or need additional support, feel free to reach out. I appreciate your visit and look forward to providing more valuable content in the future.

Happy coding!

  • Go to your GitHub SSH Keys Settings.
  • Click New SSH Key and paste the public key you copied from the VPS.
  • Clone the private repository using SSH:
  • Go to your GitHub Developer Settings.
  • Click on Generate new token and select the required scopes (e.g., repo).
  • Copy the generated token.
2 Comments
John
1 year ago
Good job
1 replies
Amankhalsa
1 year ago
Thanks
Dev
1 year ago
Keep it up
1 replies
Amankhalsa
1 year ago
Thanks
Leave a Comment

Video