Source :

1. Update system

pkg update
pkg upgrade

2. Install dependencies

pkg install sudo bash icu cmake pkgconf git go nginx node ruby ruby21-gems logrotate redis postgresql94-server postgresql94-contrib postfix krb5
gem install bundler --no-ri --no-rdoc

Add this to /etc/rc.conf:

# GitLab services

# Web server

# Postfix/Sendmail

3. Create git user

Create user git :

pw add user -n git -m -s /usr/local/bin/bash -c "GitLab"

Add git user to redis group :

pw user mod git -G redis

4. Set up Postgres database

As root, make sure that Postgres is running:

service postgresql start

Set up the database:

# Initialize First start of PG DB
service postgresql initdb

# Initialise Postgres db
service postgresql start

# Log in to Postgres user account
su - pgsql

# Connect to Postgres database
psql -d template1

When logged into the database:

# Create a user for GitLab
template1=# CREATE USER git CREATEDB;

# Create the GitLab production database & grant all privileges on database
template1=# CREATE DATABASE gitlabhq_production OWNER git encoding='UTF8';

# Create extension

# Quit the database session
template1=# \q

Then type exit to drop back to the root user. Try connecting to the new database with the git user:

su - git
psql -d gitlabhq_production

If this succeeds, quit the database session by typing \q or hitting CTRL-D.

5. Install and set up Redis

Back up the original Redis config file:

cp /usr/local/etc/redis.conf /usr/local/etc/redis.conf.orig

Edit /usr/local/etc/redis.conf to obtain:

unixsocket /usr/local/var/run/redis/redis.sock
unixsocketperm 770

daemonize yes
pidfile /var/run/redis/

port 6379
tcp-backlog 511

timeout 0
tcp-keepalive 0
loglevel notice
logfile /var/log/redis/redis.log

databases 16

save 900 1
save 300 10
save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename dump.rdb
dir /var/db/redis/

slave-serve-stale-data yes
slave-read-only yes

repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100

appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes

lua-time-limit 5000

slowlog-log-slower-than 10000
slowlog-max-len 128

latency-monitor-threshold 0
notify-keyspace-events ""

hash-max-ziplist-entries 512
hash-max-ziplist-value 64

list-max-ziplist-entries 512
list-max-ziplist-value 64

set-max-intset-entries 512

zset-max-ziplist-entries 128
zset-max-ziplist-value 64

hll-sparse-max-bytes 3000

activerehashing yes

client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

aof-rewrite-incremental-fsync yes


mkdir -p /usr/local/var/run/redis
chown redis:redis /usr/local/var/run/redis
chmod 755 /usr/local/var/run/redis

And we restart Redis:

service redis restart

6. Install and set up GitLab

Change to git home directory:

cd /home/git

Clone GitLab source:

sudo -u git -H git clone -b 7-7-stable gitlab

Go to GitLab source folder:

cd /home/git/gitlab

Copy the example GitLab config:

sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

Edit the GitLab configuration file:

sudo -u git -H vim config/gitlab.yml

The option host: should be set to your domain, e.g. “”.
The line bin_path: should be set to FreeBSD’s git location: /usr/local/bin/git.
Change /home/ to be /usr/home/ (home is a symbolic link that doesn’t work)

As root:

cd /home/git/gitlab
chown -R git log/
chown -R git tmp/
chmod -R u+rwX,go-w log/
chmod -R u+rwX tmp/

Make folder for satellites and set the right permissions:

sudo -u git -H mkdir /home/git/gitlab-satellites
sudo -u git -H chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites

Make sure GitLab can write to the tmp/pids/ and tmp/sockets/ directories:

sudo -u git -H chmod -R u+rwX tmp/pids/
sudo -u git -H chmod -R u+rwX tmp/sockets/

Make sure GitLab can write to the public/uploads/ directory:

mkdir -p public/uploads
sudo -u git -H chmod -R u+rwX  public/uploads

Copy the example Unicorn config:

sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb

Set the number of workers to at least the number of cores:

sudo -u git -H vim config/unicorn.rb

Copy the example Rack attack config:

sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb

Configure Git global settings for git user, useful when editing via web

# Edit according to what is set in gitlab.yml
sudo -u git -H git config --global "GitLab"
sudo -u git -H git config --global ""
sudo -u git -H git config --global core.autocrlf input

Copy Redis connection settings:

sudo -u git -H cp config/resque.yml.example config/resque.yml

Configure Redis to use the modified socket path:

# Change 'production' line to 'unix:/usr/local/var/run/redis/redis.sock'
sudo -u git -H vim config/resque.yml

Copy database config:

sudo -u git -H cp config/database.yml.postgresql config/database.yml

Install Ruby Gems:

sudo -u git -H bundle install --deployment --without development test mysql aws

7. GitLab Shell

Run the rake task for installing gitlab-shell:

sudo -u git -H bundle exec rake gitlab:shell:install[v2.4.1] REDIS_URL=unix:/usr/local/var/run/redis/redis.sock RAILS_ENV=production

Edit the gitlab-shell config:

# Change /home/* to be /usr/home/*  (home is a symbolic link that doesn't work)
# Change the 'socket' option to '/usr/local/var/run/redis/redis.sock'
# Change the 'gitlab_url' option to 'http://localhost:8080/'
# Don't bother configuring any SSL stuff in here because it's used internally
sudo -u git -H vim /home/git/gitlab-shell/config.yml

8. Initialise Database

Initialize Database and Activate Advanced Features:

sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=yourpassword
# Type 'yes' to create the database tables.
# When done you see 'Administrator account created:'

9. Init script

Download the FreeBSD init script as root:

wget -O /usr/local/etc/rc.d/gitlab

10. Check Configuration and Compile Assets

cd /home/git/gitlab
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

If this all passes (all green and/or no errors are reported), then go ahead and compile all of the assets for GitLab. This can take ~10-15 minutes on a smaller machine, so don’t panic if it takes a while!

sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production

11. Start GitLab service

As root:

service gitlab start

12. Nginx

You might want to create /usr/local/etc/nginx/conf.d/ and include it in nginx.conf first.

wget -O /usr/local/etc/nginx/conf.d/gitlab.conf

Edit /usr/local/etc/nginx/conf.d/gitlab.conf and replace with your FQDN. Make sure to read the comments in order to properly set up SSL.

Add nginx user to git group:

pw usermod -a -G git nginx
chmod g+rx /home/git/

Finally start nginx with:

service nginx start


504 – Gateway Timed Out errors

  • Check the logs! Look in /home/git/gitlab/log for clues.
  • Check what’s running! The command sockstat -4l usually gives an idea of which services are running on which ports. (Redis uses port 6379, Unicorn uses port 8080, and Postgres uses port 5432).

What it usually boils down to:

  • GitLab’s assets haven’t been precompiled (there is a command above)
  • Postgres isn’t running or the database isn’t set up properly
  • Redis isn’t running
  • Nginx isn’t set up properly

Unicorn / nginx: “Failed to set accept_filter=httpready”

This is to do with an HTTP buffering kernel module in FreeBSD that some HTTP servers expect to be loaded. Run this:

kldload accf_http
echo 'accf_http_load="YES"' >> /boot/loader.conf

sudo service gitlab restart
sudo service redis restart
sudo service nginx restart