Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Main Section Web Server
  • Search

[HowTo] Install HTTP Git Server with Nginx on VestaCP Ubuntu 18.04 LTS

Questions regarding the Web Server
Apache + Nginx, Nginx + PHP5-FPM
Post Reply
  • Print view
Advanced search
1 post • Page 1 of 1
xorro
Posts: 87
Joined: Sun Nov 13, 2016 3:11 pm
Contact:
Contact xorro
Website Skype

Os: CentOS 6x
Web: apache + nginx
[HowTo] Install HTTP Git Server with Nginx on VestaCP Ubuntu 18.04 LTS
  • Quote

Post by xorro » Fri Sep 07, 2018 7:45 pm

Getting Started

Before starting, you will need to update your system with the latest stable version.

You can do this by running the following command:

Code: Select all

sudo apt-get update -y
sudo apt-get upgrade -y
Once your system is updated, restart your system and log in with sudo user.

Install Required Packages

First, you will need to install some required packages including nginx, git, nano, and fcgiwrap to your system. You can install all of them by running the following command:

Code: Select all

sudo apt-get install nginx git nano fcgiwrap apache2-utils -y
Once all the required packages are installed, you will need to create a directory for Git repository. You can do this by running the following command:

Code: Select all

sudo mkdir /var/www/html/git
Next, give proper permission to the Git directory:

Code: Select all

sudo chown -R www-data:www-data /var/www/html/git
Once you are done, you can proceed to configure Nginx VestaCP web server.

Configure Nginx

First, you will need to configure Nginx to pass on Git traffic to Git. You can do this by editing Nginx default configuration file:

Code: Select all

sudo nano /etc/nginx/sites-available/default
Change the file as shown below:

Code: Select all

# Default server configuration
#
server {
        listen 80 default_server;
        listen [::]:80 default_server;


        root /var/www/html/git;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

location ~ (/.*) {
    client_max_body_size 0; # Git pushes can be massive, just to make sure nginx doesn't suddenly cut the connection add this.
    auth_basic "Git Login"; # Whatever text will do.
    auth_basic_user_file "/var/www/html/git/htpasswd";
    include /etc/nginx/fastcgi_params; # Include the default fastcgi configs
    fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; # Tells fastcgi to pass the request to the git http backend executable
    fastcgi_param GIT_HTTP_EXPORT_ALL "";
    fastcgi_param GIT_PROJECT_ROOT /var/www/html/git; # /var/www/git is the location of all of your git repositories.
    fastcgi_param REMOTE_USER $remote_user;
    fastcgi_param PATH_INFO $1; # Takes the capture group from our location directive and gives git that.
    fastcgi_pass  unix:/var/run/fcgiwrap.socket; # Pass the request to fastcgi
}

}
Save and close the file when you are finished. Then test Nginx for any configuration error with the following command:

Code: Select all

sudo nginx -t
If everything is fine, you should see the following output:
Image

Next, you will need to create a user account of which you will need to use to browse of commit to the repository. You can create user with name yourname by using the htpasswd utility:

Code: Select all

sudo htpasswd -c /var/www/html/git/htpasswd yourpassword
Finally, restart Nginx to apply all the changes with the following command:

Code: Select all

sudo systemctl restart nginx
You can check the status of the Nginx server with the following command:

Code: Select all

sudo systemctl status nginx
You should see the following output:
Image

Create Git Repository

Once everything is configured properly, it's time to create Git repository.

You can create a repository with name anyname.git with the following command:

Code: Select all

cd /var/www/html/git
sudo mkdir firname.git
sudo cd anyname.git
sudo git --bare init
sudo git update-server-info
sudo chown -R www-data.www-data .
sudo chmod -R 755 .
Next, you will need to allow HTTP service through UFW firewall. By default UFW is disabled on your system, so you need to enable it first. You can enable it with the following command:

Code: Select all

sudo ufw enable
Once UFW firewall is enabled, you can allow HTTP and SSH service by running the following command:

Code: Select all

sudo ufw allow http
sudo ufw allow ssh
SSH is not needed for GIT, but you should enable it to be able to manage your server trough SSH.

You can now check the status of UFW firewall by running the following command:

Code: Select all

sudo ufw status
Ok that's it for the server side configuration. You can now move on to the client side to test Git.

Test Git on Client Machine

Before starting, you will need to install git on the client system. You can install it with the following command:

Code: Select all

sudo apt-get install git -y
First, create a local repository with the following command:

Code: Select all

sudo mkdir ~/testproject
Next, change the directory to 'testproject' and initiate the new remote repository with the following command:

Code: Select all

cd ~/testproject
git init
git remote add origin http://[email protected]/anyname.git
Next, create some files and directory with the following command:

Code: Select all

mkdir test1 test2 test3
echo "This is my first repository" > test1/repo1
echo "This is my second repository" > test2/repo2
echo "This is my third repository" > test3/repo3
Next, run the following command to add all the files and directories to the repository:

Code: Select all

git add .
git commit -a -m "Add files and directoires"
You should see the following output:

Code: Select all

[master 002fac9] Add files and directoires
 3 files changed, 3 insertions(+)
 create mode 100644 repo1
 create mode 100644 repo2
 create mode 100644 repo3
Next, push all the files and directories to the Git server with the following command:

Code: Select all

git push origin master
You should see the following output:

Code: Select all

Password for 'http://[email protected]': 
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (5/5), 422 bytes | 0 bytes/s, done.
Total 5 (delta 0), reused 0 (delta 0)
To http://[email protected]/anyname.git
   68f1270..002fac9  master -> master
Now, your all files and directories have been committed to your Git server.

Your Git repository creation process is now completed. You can now easily clone your repository in future. You can clone your repository using the following command on the remote system:

Code: Select all

git clone [email protected]:/var/www/html/git/anyname.git
You should see the following output:

Code: Select all

Cloning into 'anyname'...
[email protected]'s password: 
remote: Counting objects: 8, done.
remote: Compressing objects: 100% (3/3), done.
Receiving objects: 100% (8/8), 598 bytes | 0 bytes/s, done.
remote: Total 8 (delta 0), reused 0 (delta 0)
Checking connectivity... done.
Now, change the directory to the cloned repository with the following command:

Code: Select all

cd anyname
tree
You should see the following output:

Code: Select all

.
|-- test1
|   `-- repo1
|-- test2
|   `-- repo2
`-- test3
    `-- repo3

3 directories, 3 files
Download as VM

This tutorial is available as ready to use virtual machine image in ovf/ova format that is compatible with VMWare and Virtualbox. The virtual machine image uses the following login details:

SSH / Shell Login

Username: username
Password: password

This user has sudo rights.

GIT Login

Username: username
Password: password

The IP of the VM is 192.168.1.100, it can be changed in the file /etc/netplan/01-netcfg.yaml. Please change all the above passwords to secure the virtual machine.
Top


Post Reply
  • Print view
1 post • Page 1 of 1

Return to “Web Server”



  • Board index
  • All times are UTC
  • Delete all board cookies
  • The team
Powered by phpBB® Forum Software © phpBB Limited
*Original Author: Brad Veryard
*Updated to 3.2 by MannixMD
 

 

cron

Login  •  Register

I forgot my password