Looking for a digital agency?

Install and Configure Gitlab and Website on Apache Server in Your VPS

LOGO
Chigisoft

Sometime last year, we had our CTO install gitlab on our servers to better manage our development projects. He documented his processes.


Looking for a digital agency? Post a Project



Step 1:

sudo apt-get install curl openssh-server ca-certificates postfix
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
sudo apt-get install gitlab-ce


Step 2:

sudo nano /etc/gitlab/gitlab.rb

external_url “http://<yourdomain>”

sudo gitlab-ctl reconfigure


Step 3:

sudo apt-get update
sudo apt-get install apache2

sudo a2enmod proxy_http
sudo a2enmod rewrite
sudo a2enmod ssl
sudo a2enmod headers
sudo service apache2 restart

sudo systemctl status apache2

external_url “http://<yourdomain>”
# Disable nginx
nginx[‘enable’] = false
# Give apache user privileges to listen to GitLab
web_server[‘external_users’] = [‘www-data’]

<VirtualHost *:80> ServerName <your_domain_or_sub_domain>
ServerSignature Off

ProxyPreserveHost On
AllowEncodedSlashes NoDecode

<Location />
Require all granted

ProxyPassReverse http://127.0.0.1:8080
ProxyPassReverse <your_domain_or_sub_domain>
</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

#Set up apache error documents, if back end goes down (i.e. 503 error) then a maintenance/deploy page is thrown up.
ErrorDocument 404 /404.html
ErrorDocument 422 /422.html
ErrorDocument 500 /500.html
ErrorDocument 503 /deploy.html

LogFormat “%{X-Forwarded-For}i %l %u %t \”%r\” %>s %b” common_forwarded
ErrorLog /var/log/httpd/logs/<your_domain_or_sub_domain>_error.log
CustomLog /var/log/httpd/logs/<your_domain_or_sub_domain>_forwarded.log common_forwarded
CustomLog /var/log/httpd/logs/<your_domain_or_sub_domain>_access.log combined env=!dontlog
CustomLog /var/log/httpd/logs/<your_domain_or_sub_domain>.log combined

</VirtualHost>

#Enable gitlab
sudo a2ensite gitlab#Restart apache
sudo service apache2 restart#Reconfigure gitlab
sudo gitlab-ctl reconfigure#Restart gitlab server
sudo gitlab-ctl restart


#Create directory for new site
sudo mkdir -p /var/www/new_site/public_html#Allow regular users to modify files in the directory
sudo chown -R $USER:$USER /var/www/new_site/public_html#Allow general read access to our web directory
sudo chmod -R 755 /var/www

<VirtualHost *:80>
ServerName <site-domain>
ServerAlias <site-domain>
ServerAdmin <site-admin-email>
DocumentRoot /var/www/new_site/public_html #Folder directory created earlier
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

sudo a2ensite new_site.conf
sudo service apache2 restart


Gitlab Admin Login Details:

sudo gitlab-rails console or sudo gitlab-rake rails console

user = User.find_by(email: ‘[email protected]’) or user = User.find(1)

user.password = ‘secret_pass’ followed by user.password_confirmation = ‘secret_pass’ then user.save


Configure Push and Pull on Server Repositories:

…….
gitlab_workhorse[‘enable’] = true
gitlab_workhorse[‘listen_network’] = “tcp”
gitlab_workhorse[‘listen_addr’] = “localhost:8282”
…….

sudo gitlab-ctl reconfigure

……
RewriteEngine On
RewriteRule /[-\/\w\.]+\.git\/ http://127.0.0.1:8282%{REQUEST_URI} [P,QSA,L]
…….

sudo service apache2 restart