7

I'm trying to install GitLab, but I want to install it on an Apache web server on my VPS.

I know that GitLab was built for nginx, but I honestly don't want to use it. I was wondering how I would be able to have a setup so that mysite.com would retrieve the files (like index.html, folders with more files in them, etc.) in /var/www/html lab.mysite.com would retrieve GitLab. I've heard you're supposed to use a virtual host, but remember, I'm still an amateur at best with this kind of stuff, so if anyone here is kind enough to make a short step-by-step guide to do this, I'd appreciate this.

Note: Before I've been using this guide to install GitLab, however this is for Nginx, so I was wondering if I was to use this guide but then add onto it, or if I'm going about this all wrong.

4
  • 2
    With your current level of expertise I would suggest following the install guide to the letter, and use nginx if that is what they use. When you get more experienced you can deviate from the installation guide as you then know what you are doing. Commented May 1, 2016 at 21:22
  • @ThorbjørnRavnAndersen Okay, then new question. I have an assortment of web files already.... how could I host my files on mydomain.com and the GitLab ones on lab.mydomain.com on the same VPS? (Still wanting to use CentOS 7 here, I'm just very VERY new to Nginx. I've been able to setup GitLab on mydomain.com, but I need to add an index page, etc.) Commented May 1, 2016 at 21:25
  • I have no idea. I would think you have too many things you are too unfamiliar with in play at the same time, and you should consider simplifying this to get more experience so you actually know what you are doing. As you are not having an actual programming question but more need handholding with setting up programs you might be better of asking on superuser or the unix sites. Commented May 1, 2016 at 21:34
  • @ThorbjørnRavnAndersen Alrighty, thanks. Will do. Commented May 1, 2016 at 21:39

1 Answer 1

11

By default GitLab will install nginx but usually won't add nginx to your system's service manager (service or systemctl). This makes it confusing when trying to enable Apache (Apache won't start due to default port 80 in use by nginx).

Assuming you've installed Gitlab according to the default install instructions, the Nginx service will now be managed by the gitlab-ctl service manager (which is installed when installed Gitlab).

To stop Nginx, run the following from a command line as root:

gitlab-ctl stop nginx

Now that port 80 is free, you can start Apache (don't forget to install Apache if it's not already / Instructions are for RHEL systems - modify accordingly for Ubuntu etc). Assumes you are root user:

yum install -y httpd;
systemctl start httpd;
systemctl enable httpd;

Let's edit the Gitlab config file to disable nginx and tell gitlab to use apache:

vi /etc/gitlab/gitlab.rb

Add either your domain or IP to the following:

external_url 'http://git.yourdomain.com/'

Find:

# web_server['external_users'] = []

Change to (don't forget to remove the leading '#'):

web_server['external_users'] = ['apache']

Find:

# nginx['enable'] = true

Change to:

nginx['enable'] = false

And finally we have to run a "recompile" with:

gitlab-ctl reconfigure

gitlab-ctl restart

Now the Apache config. When we installed Gitlab, it added a user group called gitlab-www. We need to allow the apache user access to that group. The following assumes you've installed apache and the user apache (48) exists:

To check which group gitlab installed itself under, you can run:

getent group

Now lets modify apache's user and add it to the gitlab-www group:

usermod apache --append --groups gitlab-www

Now we need an Apache Virtual Host to point to the gitlab install.

Add a virtual host to Apache's conf.d directory (this will create a new file):

vi /etc/httpd/conf.d/gitlab.conf

Add the following (tweak according to your needs):

<VirtualHost *:80>
    ServerName git.yourdomain.com
    ServerSignature Off

    ProxyPreserveHost On

    <Location />
      Order deny,allow
      Allow from all

      ProxyPassReverse http://127.0.0.1:8080
      ProxyPassReverse http://git.yourdomain.com/
    </Location>

    RewriteEngine on
    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
    RewriteRule .* http://127.0.0.1:8080%{REQUEST_URI} [P,QSA]

    # needed for downloading attachments
    DocumentRoot /opt/gitlab/embedded/service/gitlab-rails/public

    ErrorLog /var/log/httpd/error_log
    CustomLog /var/log/httpd/access_log combined env=!dontlog
</VirtualHost>

... And now restart Apache:

systemctl start httpd

You may run into issues with things like selinux - You can set things to permissive for debugging purposes.

setenforce 0

I hope this helps someone!

Sign up to request clarification or add additional context in comments.

2 Comments

I use your solution, it is OK for me. But i don't have domain so use port forwarding and had to change your vhost files.
Works like charm! THX

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.