...

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

Learn 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

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.

William Anderson

I am a versatile Full-Stack Web Developer with a strong focus on Laravel, Livewire, Vue.js, and Tailwind CSS. With extensive experience in backend development, I specialize in building scalable, efficient, and high-performance web applications.