I previously wrote an article to get GitBucket working with Heroku which was awesome for testing purposes, however if you actually plan on using GitBucket, you probably want an environment that saves your data and users! Fear not, it's easier then I thought. Follow this guide to get GitBucket working in a production-like environment.

Install Your Server

I used CentOS 6 x86_64 for my server. I just got it running in a VPS environment. You can use DigitalOcean, it's nice and cheap and super easy to use.

Install Java

Next you'll want to make sure Java is installed. This is quite simple as well.

cd /opt/
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/7u60-b19/jdk-7u60-linux-i586.tar.gz"

This will download Java for you. Next let's unpack the archive.

tar zxvf jdk-7u60-linux-i586.tar.gz

Next, we'll use Alternatives to get Java installed to your system.

cd /opt/jdk1.7.0_60/
alternatives --install /usr/bin/java java /opt/jdk1.7.0_60/bin/java 2
alternatives --config java

You should get the output of something like:

There is 1 program that provides 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /opt/jdk1.7.0_60/bin/java

Just hit the 'Enter' key at the prompt and it'll proceed with your installation. If all went well Java should be installed:

[root@git jdk1.7.0_60]# java -version
java version "1.7.0_60"

You'll also want to setup some environment variables:

export JAVA_HOME=/opt/jdk1.7.0_60
export JRE_HOME=/opt/jdk1.7.0_60/jre
export PATH=$PATH:/opt/jdk1.7.0_60/bin:/opt/jdk1.7.0_60/jre/bin

That completes the installation of Java onto your system.

Install GitBucket

Next grab a copy of the latest release of GitBucket. The version as of writing was 2.0.

cd /opt
mkdir gitbucket
cd gitbucket/
wget https://github.com/takezoe/gitbucket/releases/download/2.0/gitbucket.war

That's pretty much all we'll do with it for now. We'll come back to the war file in a bit.

Install Nginx

Since I prefer to not have :8080 in my URLs and I like Nginx, I'll install it as a front-end proxy to GitBucket. It's really easy!

cd /usr/src
wget http://nginx.org/packages/rhel/6/noarch/RPMS/nginx-release-rhel-6-0.el6.ngx.noarch.rpm
rpm -ivh nginx-release-rhel-6-0.el6.ngx.noarch.rpm
yum install nginx

If all went well you should see something like:

Installing : nginx-1.6.0-1.el6.ngx.x86_64                                                                                                                                                                   1/1 
----------------------------------------------------------------------

Thanks for using nginx!

Please find the official documentation for nginx here:
* http://nginx.org/en/docs/

Commercial subscriptions for nginx are available on:
* http://nginx.com/products/

----------------------------------------------------------------------
  Verifying  : nginx-1.6.0-1.el6.ngx.x86_64                                                                                                                                                                   1/1 

Installed:
  nginx.x86_64 0:1.6.0-1.el6.ngx                                                                                                                                                                                  

Complete!

Now, we'll need to add a configuration file for your GitBucket install. Navigate to the /etc/nginx/conf.d folder and create a file named gitbucket.conf:

nano gitbucket.conf

Simple! Now add the following into the file:

server {
        listen   80; # The default is 80 but this here if you want to change it.
        server_name gitbucket.example.com;

  location / {
    proxy_pass              http://localhost:8080;
    proxy_set_header        Host $host;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_connect_timeout   150;
    proxy_send_timeout      100;
    proxy_read_timeout      100;
    proxy_buffers           4 32k;
    client_max_body_size    500m; # Big number is we can post big commits.
    client_body_buffer_size 128k;

  }
}

Remember to change the server_name setting to your URL. In my case I did:

server_name gitneko.com;

Also, you may want to set Nginx to start up on boot.

chkconfig nginx on

Running GitBucket

You're on the final stretch! Open a new screen (you may need to install screen if it's not installed already).

screen
cd /opt/gitbucket
java -jar gitbucket.war

This will start up GitBucket. Once it's started up hit Ctrl+A, Ctrl+D to get out of screen. Now we're going to start up Nginx.

/etc/init.d/nginx restart

Don't worry if you see something like:

[root@git conf.d]# /etc/init.d/nginx restart
Stopping nginx:                                            [FAILED]
Starting nginx:                                            [  OK  ]

It only failed to stop because it wasn't running. You could even just start instead of restart...

At this point you should be able to visit http://yourdomain.com and you'll see your GitBucket instance running! Done and done!

Updating GitBucket

Thankfully the developers of GitBucket have made it extremely easy to upgrade GitBucket. You simply need to download the new .war file and replace your current one with it. I then recommend restarting Nginx as well for good measure.

Resources