GitLab 6 + Apache + Phusion Passenger

I've successfully been running an instance of GitLab for almost a year now. The same server is running Redmine, hence both GitLab and Redmine are running in their respective sub-directories. Phusion Passenger is my application server of choice. Unfortunately, it became increasingly difficult to keep this setup running with newer versions of GitLab. First, GitLab officially is not supporting running it out of a sub-directory, second, by default it uses Unicorn. Here, I want to detail my setup how you still can achieve the GitLab + Apache + Phusion Passenger combo, because I could only find slightly outdated guides online.

As of this writing, my setup looks like the following:

  • Ubuntu 12.04 LTS
  • Apache 2.2.22
  • GitLab 6.1
  • passenger 4.0.19

First of all, you should obviously install Apache and passenger. For the latter follow the steps outlined here, and I assume you just installed the Apache package shipped by your distribution of choice first. After the basic setup, you can start setting up GitLab 6.1. However, because the sub-directory + Apache + Passenger setup is non-standard, you have to alter some of the steps when configuring GitLab:

  1. In the gitlab section of config/gitlab.yml, add relative_url_root: /gitlab
  2. In config/application.rb, uncomment the line containing config.relative_url_root = "/gitlab"
  3. Skip setting up the config/unicorn.rb file
  4. Instead of using the init script shipped with GitLab, use this file without the unicorn related parts and copy it to /etc/init.d/gitlab
  5. After completing the official install guide, you want to precompile assets using the following command:
    sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production RAILS_RELATIVE_URL_ROOT=/gitlab

You can check if everything worked so far by executing

sudo servive gitlab start
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

Note that it will complain about the init script not being up-to-date because it was replaced with a custom version.

Now it's time to configure Apache to run GitLab in the gitlab sub-directory. First of all, ensure that Passenger's Apache module is loaded. After that, go to /var/www/htdocs and create a symbolic link to /home/git/gitlab/public. Next, update your Apache configuration to look like this:

<VirtualHost *:80>
        DocumentRoot /var/www/htdocs
 
        <Directory /var/www/htdocs>
                Options FollowSymLinks
                Order allow,deny
                Allow from all
                PassengerResolveSymlinksInDocumentRoot on
        </Directory>
 
        Alias /gitlab "/var/www/htdocs/gitlab"
        <Directory /var/www/htdocs/gitlab>
                Options -MultiViews
                SetEnv RAILS_RELATIVE_URL_ROOT "/gitlab"
                PassengerAppRoot "/home/git/gitlab"
        </Directory>
</VirtualHost>

Finally, start apache and go to yourdomain.com/gitlab.

Comments

thanks for this tutorial searched for weeks to get it running with 6.1 and apache.
but I have a problem

git@fit-pc2:~/gitlab$ bundle exec rake assets:precompile RAILS_ENV=production RAILS_RELATIVE_URL_ROOT=/gitlab
/usr/local/bin/ruby /home/git/gitlab/vendor/bundle/ruby/2.0.0/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
Permission denied - /home/git/gitlab/public/assets
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/actionpack-3.2.13/lib/sprockets/static_compiler.rb:38:in `block in write_asset'
/home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/actionpack-3.2.13/lib/sprockets/static_compiler.rb:36:in `tap'

Thanks for any help in advance

chown git:git public and bundle exec rake assets:precompile RAILS_ENV=production is ok ,
i read in a different tutorial this folder shuld be www-data:www-data

I added to httpd.conf this and I hope its ok.
LoadModule passenger_module /usr/local/lib/ruby/gems/2.0.0/gems/passenger-4.0.20/buildout/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/2.0.0/gems/passenger-4.0.20
PassengerDefaultRuby /usr/local/bin/ruby

But is the gitlab file of instruction point Nr. 4 of correct.

git@fit-pc2:~/gitlab$ bundle exec rake gitlab:check RAILS_ENV=production
Checking Environment ...

Git configured for git user? ... yes
Has python2? ... yes
python2 is supported version? ... yes

Checking Environment ... Finished

Checking GitLab Shell ...

GitLab Shell version >= 1.7.0 ? ... OK (1.7.1)
Repo base directory exists? ... yes
Repo base directory is a symlink? ... no
Repo base owned by git:git? ... yes
Repo base access is drwxrws---? ... yes
update hook up-to-date? ... yes
update hooks in repos are links: ... can't check, you have no projects

Checking GitLab Shell ... Finished

Checking Sidekiq ...

Running? ... yes

Checking Sidekiq ... Finished

Checking GitLab ...

Database config exists? ... yes
Database is SQLite ... no
All migrations up? ... yes
GitLab config exists? ... yes
GitLab config outdated? ... no
Log directory writable? ... yes
Tmp directory writable? ... yes
Init script exists? ... yes
Init script up-to-date? ... no
Try fixing it:
Redownload the init script
For more information see:
doc/install/installation.md in section "Install Init Script"
Please fix the error above and rerun the checks.
Projects have satellites? ... can't check, you have no projects
Redis version >= 2.0.0? ... yes
Your git bin path is "/usr/bin/git"
Git version >= 1.7.10 ? ... yes (1.7.10)

Checking GitLab ... Finished

ok script is working, didn't paste everything sorry !
Here is my default out of sites-available because I do not have htdocs folder:
<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www

<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
PassengerResolveSymlinksInDocumentRoot on
</Directory>

Alias /gitlab "/var/www/gitlab"
<Directory /var/www/gitlab>
Options -MultiViews
SetEnv RAILS_RELATIVE_URL_ROOT "/gitlab"
PassengerAppRoot "/home/git/gitlab"
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Many, many thanks! Worked like a charm!

Thanks!!! Worked!!!!!!!!!!!!!!!!!!!

Hey! Many thanks for your work. Almost everything worked, except your init script.
Here is my version: http://pastebin.com/zvHditaQ
It's not using 'bundle exec' and works for me

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.