We are happy to announce that Vesta is back under active development as of 25 February 2024. We are working on v1 candidate and expect to engage more with the community over the coming months. We are committed to open source, and we encourage contributors to help us build the future of Vesta.
[HowTo] Install HTTP Git Server with Nginx on VestaCP Ubuntu 18.04 LTS
[HowTo] Install HTTP Git Server with Nginx on VestaCP Ubuntu 18.04 LTS
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:
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:
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:
Next, give proper permission to the Git directory:
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:
Change the file as shown below:
Save and close the file when you are finished. Then test Nginx for any configuration error with the following command:
If everything is fine, you should see the following output:
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:
Finally, restart Nginx to apply all the changes with the following command:
You can check the status of the Nginx server with the following command:
You should see the following output:
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:
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:
Once UFW firewall is enabled, you can allow HTTP and SSH service by running the following command:
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:
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:
First, create a local repository with the following command:
Next, change the directory to 'testproject' and initiate the new remote repository with the following command:
Next, create some files and directory with the following command:
Next, run the following command to add all the files and directories to the repository:
You should see the following output:
Next, push all the files and directories to the Git server with the following command:
You should see the following output:
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:
You should see the following output:
Now, change the directory to the cloned repository with the following command:
You should see the following output:
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.
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
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
Code: Select all
sudo mkdir /var/www/html/git
Code: Select all
sudo chown -R www-data:www-data /var/www/html/git
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
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
}
}
Code: Select all
sudo nginx -t
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
Code: Select all
sudo systemctl restart nginx
Code: Select all
sudo systemctl status nginx
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 .
Code: Select all
sudo ufw enable
Code: Select all
sudo ufw allow http
sudo ufw allow ssh
You can now check the status of UFW firewall by running the following command:
Code: Select all
sudo ufw status
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
Code: Select all
sudo mkdir ~/testproject
Code: Select all
cd ~/testproject
git init
git remote add origin http://[email protected]/anyname.git
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
Code: Select all
git add .
git commit -a -m "Add files and directoires"
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
Code: Select all
git push origin master
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
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
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.
Code: Select all
cd anyname
tree
Code: Select all
.
|-- test1
| `-- repo1
|-- test2
| `-- repo2
`-- test3
`-- repo3
3 directories, 3 files
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.