Install GerritReview with Own Hostname

Introduction to setup GerritReview on http://gerrit.example.com

Preparation

Gerrit requires JDK

sudo apt install openjdk-11-jre-headless

Download the gerrit-version.war file, for example the folder /home/gerrit/app/

Initial Site

To initial the gerrit site, the site/etc/gerrit.config will be generated

cd /home/gerrit/app/
java -jar gerrit-3.1.4.war init -d site
  • Check /home/gerrit/app/site/etc/gerrit.config as following
[gerrit]
        basePath = git
        canonicalWebUrl = http://gerrit.example.com
        serverId = e52b7bb9-4814-4a7b-9534-a1af694d91fd
[container]
        javaOptions = "-Dflogger.backend_factory=com.google.common.flogger.backend.log4j.Log4jBackendFactory#getInstance"
        javaOptions = "-Dflogger.logging_context=com.google.gerrit.server.logging.LoggingContext#getInstance"
        user = gerrit
        javaHome = /usr/lib/jvm/java-11-openjdk-amd64
[index]
        type = lucene
[auth]
        type = HTTP
[receive]
        enableSignedPush = true
[sendemail]
        smtpServer = localhost
[sshd]
        listenAddress = *:29418
[httpd]
        listenUrl = http://*:8081/
[cache]
        directory = cache

Initial Gerrit Account of Admin

Create the first account as admin

cd /home/gerrit/app/
htpasswd -c PASSWORD admin

Apache2 Configuation

Edit a gerrit.conf in /etc/apache2/sites-available

vim /etc/apache2/sites-available/gerrit.conf

Example:

<virtualhost *:80>

    servername gerrit.example.com
    AllowEncodedSlashes On
    ProxyPreserveHost On
    ProxyPass / http://localhost:8081/ nocanon
    ProxyPassReverse / http://localhost:8081/ nocanon
    ProxyPassReverseCookiePath / /
    
    
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
    
    <Location /login/>
        AuthType Basic
        AuthName "Gerrit Code Review"
        Require valid-user
        AuthBasicProvider file
        AuthUserFile /home/gerrit/app/PASSWORD
    </Location>


</virtualhost>

Finalize Installation

  1. Restart the GerritReview webserver
cd /home/gerrit/app/
./site/bin/gerrit.sh restart
  1. Create a new user account
htpasswd -m PASSWORD user
  1. Reload Apache2 service
sudo systemctl reload apache2