Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to install GitLab on Apache on CentOS 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.

like image 528
Miles Jefferson Avatar asked May 01 '16 21:05

Miles Jefferson


People also ask

Does GitLab use Apache?

The gitlab server uses nginx as its default server, while our projects use apache server to serve contents. Running two internal servers simultaneously can pose a lot of issues (ports … etc).


1 Answers

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!

like image 143
recurse Avatar answered Oct 20 '22 00:10

recurse