installation.md 10.9 KB
Newer Older
1
## Platform requirements:
Valery Sizov's avatar
Valery Sizov committed
2

3
**The project is designed for the Linux operating system.**
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
4 5 6

It may work on FreeBSD and Mac OS, but we don't test our application for these systems and can't guarantee stability and full functionality.

7
We officially support (recent versions of) these Linux distributions:
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
8

9 10
- Ubuntu Linux
- Debian/GNU Linux
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
11 12 13 14 15

It should work on:

- Fedora
- CentOs
16
- RedHat
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
17

18
You might have some luck using these, but no guarantees:
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
19

20
 - MacOS X
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
21 22
 - FreeBSD

23
GitLab does **not** run on Windows and we have no plans of making GitLab compatible.
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
24

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
25 26 27 28 29 30

## Hardware: 

We recommend to use server with at least 1GB RAM for gitlab instance.


31
## This installation guide created for Debian/Ubuntu and properly tested.
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
32

33 34 35

### IMPORTANT

36
Please make sure you have followed all the steps below before posting to the mailing list with installation and configuration questions.
37

38
Only create a GitHub Issue if you want a specific part of this installation guide updated.
Valery Sizov's avatar
Valery Sizov committed
39

40
Also read the [Read this before you submit an issue](https://github.com/gitlabhq/gitlabhq/wiki/Read-this-before-you-submit-an-issue) wiki page.
Valery Sizov's avatar
Valery Sizov committed
41

randx's avatar
randx committed
42 43 44 45 46 47 48 49 50 51 52 53

# Basic setup

The basic installation will provide you a GitLab setup with options:

1. ruby 1.9.3
2. mysql as main db
3. gitolite v3 fork by gitlab
4. nginx + unicorn

The installation consists of next steps:

randx's avatar
randx committed
54 55 56 57 58 59
1. packages / dependencies
2. ruby
3. gitolite
4. mysql
5. GitLab.
6. nginx 
Valery Sizov's avatar
Valery Sizov committed
60

randx's avatar
randx committed
61

Valery Sizov's avatar
Valery Sizov committed
62 63
# 1. Install packages

64 65 66 67 68
*Keep in mind that `sudo` is not installed on Debian by default. You should install it as root:*

    apt-get update && apt-get upgrade && apt-get install sudo

Now install the required packages:
Valery Sizov's avatar
Valery Sizov committed
69 70 71 72

    sudo apt-get update
    sudo apt-get upgrade

73
    sudo apt-get install -y wget curl gcc checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libreadline6-dev libc6-dev libssl-dev libmysql++-dev make build-essential zlib1g-dev libicu-dev redis-server openssh-server git-core python-dev python-pip libyaml-dev postfix libpq-dev
74

75
# 2. Install Ruby
Valery Sizov's avatar
Valery Sizov committed
76

randx's avatar
randx committed
77 78 79
    wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz
    tar xfvz ruby-1.9.3-p194.tar.gz
    cd ruby-1.9.3-p194
Valery Sizov's avatar
Valery Sizov committed
80 81 82 83
    ./configure
    make
    sudo make install

84
# 3. Install Gitolite
Valery Sizov's avatar
Valery Sizov committed
85 86

Create user for git:
87

Valery Sizov's avatar
Valery Sizov committed
88 89 90 91 92 93 94 95 96
    sudo adduser \
      --system \
      --shell /bin/sh \
      --gecos 'git version control' \
      --group \
      --disabled-password \
      --home /home/git \
      git

97
Create user for GitLab:
98

Valery Sizov's avatar
Valery Sizov committed
99
    # ubuntu/debian
100
    sudo adduser --disabled-login --gecos 'gitlab system' gitlab
Valery Sizov's avatar
Valery Sizov committed
101

102
Add your user to the `git` group:
103

Valery Sizov's avatar
Valery Sizov committed
104 105
    sudo usermod -a -G git gitlab

Saito's avatar
Saito committed
106 107 108 109
Add `git` user to `gitlab` group:

    sudo usermod -a -G gitlab git

Valery Sizov's avatar
Valery Sizov committed
110
Generate key:
111

Valery Sizov's avatar
Valery Sizov committed
112 113
    sudo -H -u gitlab ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa

114
Clone GitLab's fork of the Gitolite source code:
115

randx's avatar
randx committed
116
    sudo -H -u git git clone -b gl-v304 https://github.com/gitlabhq/gitolite.git /home/git/gitolite
Valery Sizov's avatar
Valery Sizov committed
117 118

Setup:
119

randx's avatar
randx committed
120 121
    cd /home/git
    sudo -u git -H mkdir bin
122
    sudo -u git sh -c 'echo -e "PATH=\$PATH:/home/git/bin\nexport PATH" >> /home/git/.profile'
randx's avatar
randx committed
123 124
    sudo -u git sh -c 'gitolite/install -ln /home/git/bin'

Valery Sizov's avatar
Valery Sizov committed
125
    sudo cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub
126
    sudo chmod 0444 /home/git/gitlab.pub
Valery Sizov's avatar
Valery Sizov committed
127

randx's avatar
randx committed
128 129
    sudo -u git -H sh -c "PATH=/home/git/bin:$PATH; gitolite setup -pk /home/git/gitlab.pub"
    sudo -u git -H sed -i 's/0077/0007/g' /home/git/.gitolite.rc
Saito's avatar
Saito committed
130
    sudo -u git -H sed -i "s/\(GIT_CONFIG_KEYS\s*=>*\s*\).\{2\}/\1'\.\*'/g" /home/git/.gitolite.rc
131

Valery Sizov's avatar
Valery Sizov committed
132
Permissions:
133

Valery Sizov's avatar
Valery Sizov committed
134 135 136 137
    sudo chmod -R g+rwX /home/git/repositories/
    sudo chown -R git:git /home/git/repositories/

#### CHECK: Logout & login again to apply git group to your user
138

Valery Sizov's avatar
Valery Sizov committed
139 140
    # clone admin repo to add localhost to known_hosts
    # & be sure your user has access to gitolite
141
    sudo -u gitlab -H git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin
Valery Sizov's avatar
Valery Sizov committed
142 143

    # if succeed  you can remove it
144
    sudo rm -rf /tmp/gitolite-admin
Valery Sizov's avatar
Valery Sizov committed
145

146 147 148
**IMPORTANT! If you can't clone `gitolite-admin` repository - DO NOT PROCEED WITH INSTALLATION**
Check the [Trouble Shooting Guide](https://github.com/gitlabhq/gitlab-public-wiki/wiki/Trouble-Shooting-Guide)
and ensure you have followed all of the above steps carefully.
Valery Sizov's avatar
Valery Sizov committed
149

randx's avatar
randx committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168

# 4. Mysql database

    sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev

    # Login to MySQL
    $ mysql -u root -p

    # Create the GitLab production database
    mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;

    # Create the MySQL User change $password to a real password
    mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY '$password';

    # Grant proper permissions to the MySQL User
    mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';


# 5. Clone GitLab source and install prerequisites
Valery Sizov's avatar
Valery Sizov committed
169

170
    sudo gem install charlock_holmes --version '0.6.8'
Valery Sizov's avatar
Valery Sizov committed
171 172 173
    sudo pip install pygments
    sudo gem install bundler
    cd /home/gitlab
174 175

    # Get gitlab code. Use this for stable setup
176
    sudo -H -u gitlab git clone -b stable https://github.com/gitlabhq/gitlabhq.git gitlab
177 178 179 180 181

    # Skip this for stable setup.
    # Master branch (recent changes, less stable)
    sudo -H -u gitlab git clone -b master https://github.com/gitlabhq/gitlabhq.git gitlab

Valery Sizov's avatar
Valery Sizov committed
182
    cd gitlab
183

Valery Sizov's avatar
Valery Sizov committed
184 185 186
    # Rename config files
    sudo -u gitlab cp config/gitlab.yml.example config/gitlab.yml

randx's avatar
randx committed
187
    # Copy mysql db config
188
    # make sure to update username/password in config/database.yml
randx's avatar
randx committed
189
    sudo -u gitlab cp config/database.yml.mysql config/database.yml
Andrey Kumanyaev's avatar
Andrey Kumanyaev committed
190

Valery Sizov's avatar
Valery Sizov committed
191
#### Install gems
192

193
    # mysql
Andrey Kumanyaev's avatar
Andrey Kumanyaev committed
194
    sudo -u gitlab -H bundle install --without development test sqlite postgres  --deployment
195

196
#### Setup database
197

198
    sudo -u gitlab bundle exec rake gitlab:app:setup RAILS_ENV=production
199

randx's avatar
randx committed
200 201 202 203 204
#### Copy unicorn config

    cd /home/gitlab/gitlab
    sudo -u gitlab cp config/unicorn.rb.example config/unicorn.rb

205
#### Setup GitLab hooks
206

randx's avatar
randx committed
207 208
    sudo cp ./lib/hooks/post-receive /home/git/.gitolite/hooks/common/post-receive
    sudo chown git:git /home/git/.gitolite/hooks/common/post-receive
209

210 211
#### Check application status

Valery Sizov's avatar
Valery Sizov committed
212
Checking status:
213

214
    sudo -u gitlab bundle exec rake gitlab:app:status RAILS_ENV=production
Valery Sizov's avatar
Valery Sizov committed
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229


    # OUTPUT EXAMPLE
    Starting diagnostic
    config/database.yml............exists
    config/gitlab.yml............exists
    /home/git/repositories/............exists
    /home/git/repositories/ is writable?............YES
    remote: Counting objects: 603, done.
    remote: Compressing objects: 100% (466/466), done.
    remote: Total 603 (delta 174), reused 0 (delta 0)
    Receiving objects: 100% (603/603), 53.29 KiB, done.
    Resolving deltas: 100% (174/174), done.
    Can clone gitolite-admin?............YES
    UMASK for .gitolite.rc is 0007? ............YES
230
    /home/git/share/gitolite/hooks/common/post-receive exists? ............YES
Valery Sizov's avatar
Valery Sizov committed
231

randx's avatar
randx committed
232
If you got all YES - congratulations! You can run a GitLab app.
Valery Sizov's avatar
Valery Sizov committed
233

randx's avatar
randx committed
234
### init script
randx's avatar
randx committed
235

randx's avatar
randx committed
236 237 238 239 240 241 242 243 244 245 246 247
Create init script in /etc/init.d/gitlab:

    sudo wget https://raw.github.com/gitlabhq/gitlab-recipes/master/init.d/gitlab -P /etc/init.d/
    sudo chmod +x /etc/init.d/gitlab

GitLab autostart:

    sudo update-rc.d gitlab defaults 21

### Now you should start GitLab application:

    sudo service gitlab start
randx's avatar
randx committed
248 249


randx's avatar
randx committed
250
# 7. Nginx
randx's avatar
randx committed
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265

    # Install first
    sudo apt-get install nginx

    # Add GitLab to nginx sites & change with your host specific settings
    sudo wget https://raw.github.com/gitlabhq/gitlab-recipes/master/nginx/gitlab -P /etc/nginx/sites-available/
    sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab

    # Change **YOUR_SERVER_IP** and **YOUR_SERVER_FQDN**
    # to the IP address and fully-qualified domain name
    # of the host serving GitLab.
    sudo vim /etc/nginx/sites-enabled/gitlab

    # Restart nginx:
    sudo /etc/init.d/nginx restart
Valery Sizov's avatar
Valery Sizov committed
266

267

randx's avatar
randx committed
268
# Done!  Visit **YOUR_SERVER_FQDN** for gitlab instance
Valery Sizov's avatar
Valery Sizov committed
269

270 271 272 273 274
You can login via web using admin generated with setup:

    admin@local.host
    5iveL!fe

Valery Sizov's avatar
Valery Sizov committed
275 276


randx's avatar
randx committed
277 278
# Advanced setup tips:

randx's avatar
randx committed
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
> - - -
> The first 3 steps of this guide can be easily skipped by executing an install script:
>
>     # Install curl and sudo
>     apt-get install curl sudo
>
>     # 3 steps in 1 command :)
>     curl https://raw.github.com/gitlabhq/gitlab-recipes/master/install/debian_ubuntu.sh | sh
>
> Now you can go to [Step 4](#4-install-gitlab-and-configuration-check-status-configuration)
>
> Or if you are installing on Amazon Web Services using Ubuntu 12.04 you can do all steps (1 to 6) at once with:
>
>     curl https://raw.github.com/gitlabhq/gitlab-recipes/master/install/debian_ubuntu_aws.sh | sh
>
> for more detailed instructions read the HOWTO section of [the script](https://github.com/gitlabhq/gitlab-recipes/blob/master/install/debian_ubuntu_aws.sh)
> - - -
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
296

297 298 299 300 301 302 303 304
## Customizing Resque's Redis connection

If you'd like Resque to connect to a Redis server on a non-standard port or on
a different host, you can configure its connection string in the
**config/resque.yml** file:

    production: redis.example.com:6379

305
**Ok - we have a working application now. **
306
**But keep going - there are some things that should be done **
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
307

Valery Sizov's avatar
Valery Sizov committed
308

randx's avatar
randx committed
309
# Database
310

randx's avatar
randx committed
311
## SQLite
Valery Sizov's avatar
Valery Sizov committed
312

randx's avatar
randx committed
313
    sudo apt-get install -y sqlite3 libsqlite3-dev 
314

randx's avatar
randx committed
315
## MySQL
316

randx's avatar
randx committed
317
    sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev
Valery Sizov's avatar
Valery Sizov committed
318

randx's avatar
randx committed
319 320
    # Login to MySQL
    $ mysql -u root -p
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
321

randx's avatar
randx committed
322 323
    # Create the GitLab production database
    mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
324

randx's avatar
randx committed
325 326
    # Create the MySQL User change $password to a real password
    mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY '$password';
327

randx's avatar
randx committed
328 329
    # Grant proper permissions to the MySQL User
    mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
330

Valery Sizov's avatar
Valery Sizov committed
331

randx's avatar
randx committed
332
## PostgreSQL
333

randx's avatar
randx committed
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
    sudo apt-get install -y postgresql-9.2 postgresql-server-dev-9.2

    # Connect to database server
    sudo -u postgres psql -d template1

    # Add a user called gitlab. Change $password to a real password
    template1=# CREATE USER gitlab WITH PASSWORD '$password';

    # Create the GitLab production database
    template1=# CREATE DATABASE IF NOT EXISTS gitlabhq_production;

    # Grant all privileges on database
    template1=# GRANT ALL PRIVILEGES ON DATABASE gitlabhq_production to gitlab;

    # Quit from PostgreSQL server
    template1=# \q

    # Try connect to new database
    $ su - gitlab
    $ psql -d gitlabhq_production -U gitlab



#### Select the database you want to use

    # SQLite
    sudo -u gitlab cp config/database.yml.sqlite config/database.yml

    # Mysql
    sudo -u gitlab cp config/database.yml.mysql config/database.yml

    # PostgreSQL
    sudo -u gitlab cp config/database.yml.postgres config/database.yml
Valery Sizov's avatar
Valery Sizov committed
367

randx's avatar
randx committed
368
    # make sure to update username/password in config/database.yml
369

randx's avatar
randx committed
370 371 372 373 374 375 376 377 378 379
#### Install gems

    # mysql
    sudo -u gitlab -H bundle install --without development test sqlite postgres  --deployment

    # or postgres
    sudo -u gitlab -H bundle install --without development test sqlite mysql --deployment

    # or sqlite
    sudo -u gitlab -H bundle install --without development test mysql postgres  --deployment