Skip to content

Instantly share code, notes, and snippets.

@jniltinho
Last active January 3, 2018 10:51
Show Gist options
  • Save jniltinho/cb0743ed1ddc1544f644c223d1a0578e to your computer and use it in GitHub Desktop.
Save jniltinho/cb0743ed1ddc1544f644c223d1a0578e to your computer and use it in GitHub Desktop.
Install Redmine on Debian 8.7 64Bits + Nginx
#!/bin/bash
## Install Redmine + Nginx
## Tested on Debian 8.7 64Bits
## Author: Nilton OS -- www.linuxpro.com.br
## Version: 0.1
# Check if user has root privileges
if [[ $EUID -ne 0 ]]; then
echo "You must run the script as root or using sudo"
exit 1
fi
echo -e "Set Server Name Ex: redmine.domain.com : \c "
read SERVER_FQDN
echo -e "Set Server IP (commonly 127.0.0.1 works): \c "
read SERVER_IP
echo "" >>/etc/hosts
echo "$SERVER_IP $SERVER_FQDN" >>/etc/hosts
echo "$SERVER_FQDN" >/etc/hostname
apt-get update
apt-get -y install postfix mariadb-client mariadb-server nginx
apt-get -y install build-essential zlib1g zlib1g-dev zlibc libssl-dev
apt-get -y install libyaml-dev libcurl4-openssl-dev libxslt1-dev libxml2-dev
apt-get -y install ruby ruby-dev ruby-zip libmysqlclient-dev libmagickwand-dev imagemagick
## To secure the MariaDB installation and to disable the test database, run this command:
sed -i 's|bind-address|#bind-address|' /etc/mysql/my.cnf
mysql_secure_installation
service mysql restart
gem install unicorn bundler rake
### Or Create Database/User in admin ISPConfig
echo "CREATE DATABASE redmine CHARACTER SET utf8;
CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'RedminePasswd';
GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'localhost';" > /tmp/mysql_redmine.sql
echo "***INPUT ROOT PASSWORD MYSQL/MARIADB for Create REDMINE DB ....***"
mysql -p < /tmp/mysql_redmine.sql
adduser --disabled-login --gecos 'Redmine' redmine
cd /home/redmine/
wget http://www.redmine.org/releases/redmine-3.3.2.tar.gz
tar -xvf redmine-3.3.2.tar.gz && rm -f redmine-3.3.2.tar.gz
mv redmine-3.3.2 redmine
cd /home/redmine/redmine
echo "gem 'unicorn'" >> /home/redmine/redmine/Gemfile
### Configure Unicorn for Redmine
FILE_UNICORN=/home/redmine/redmine/config/unicorn.rb
wget https://raw.github.com/defunkt/unicorn/master/examples/unicorn.conf.rb -O $FILE_UNICORN
sed -i 's|listen 8080|#listen 8080|' $FILE_UNICORN
sed -i 's|/path/to/app/current|/home/redmine/redmine|' $FILE_UNICORN
sed -i 's|/path/to/.unicorn.sock|/home/redmine/redmine/tmp/sockets/redmine.socket|' $FILE_UNICORN
sed -i 's|/path/to/app/shared/pids/unicorn.pid|/home/redmine/redmine/tmp/pids/unicorn.pid|' $FILE_UNICORN
sed -i 's|/path/to/app/shared/log/unicorn.stderr.log|/home/redmine/redmine/log/unicorn.stderr.log|' $FILE_UNICORN
sed -i 's|/path/to/app/shared/log/unicorn.stdout.log|/home/redmine/redmine/log/unicorn.stdout.log|' $FILE_UNICORN
cp config/database.yml.example config/database.yml
sed -i 's|username: root|username: redmine|' /home/redmine/redmine/config/database.yml
sed -i 's|password: ""|password: RedminePasswd|' /home/redmine/redmine/config/database.yml
bundle install --without development test
bundle exec rake generate_secret_token
RAILS_ENV=production bundle exec rake db:migrate
RAILS_ENV=production REDMINE_LANG=pt-BR bundle exec rake redmine:load_default_data
mkdir -p /home/redmine/redmine/tmp/pids
chown -R redmine:redmine /home/redmine
echo '[Unit]
Description=Redmine Unicorn Server
Wants=mysql.service
After=mysql.service
[Service]
User=redmine
WorkingDirectory=/home/redmine/redmine
Environment=RAILS_ENV=production
SyslogIdentifier=redmine-unicorn
PIDFile=/home/redmine/redmine/tmp/pids/unicorn.pid
ExecStart=/usr/local/bin/bundle exec "unicorn_rails -D -c /home/redmine/redmine/config/unicorn.rb -E production"
[Install]
WantedBy=multi-user.target' > /etc/systemd/system/redmine.service
systemctl daemon-reload
systemctl start redmine
systemctl enable redmine
echo 'upstream redmine {
server unix:/home/redmine/redmine/tmp/sockets/redmine.socket fail_timeout=0;
}
## Normal HTTP host
server {
listen YOUR_SERVER_IP:80;
server_name YOUR_SERVER_FQDN;
server_tokens off;
root /home/redmine/redmine/public;
client_max_body_size 300m;
access_log /var/log/nginx/redmine_access.log;
error_log /var/log/nginx/redmine_error.log;
location / {
try_files $uri $uri/index.html $uri.html @redmine;
}
location /files/ {
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_pass http://redmine;
}
location @redmine {
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_pass http://redmine;
}
error_page 502 /502.html;
}' > /etc/nginx/sites-available/redmine.conf
ln -s /etc/nginx/sites-available/redmine.conf /etc/nginx/sites-enabled/redmine.conf
sed -i "s/YOUR_SERVER_IP/$SERVER_IP/" /etc/nginx/sites-available/redmine.conf
sed -i "s/YOUR_SERVER_FQDN/$SERVER_FQDN/" /etc/nginx/sites-available/redmine.conf
service nginx restart
echo ""
echo "Access http://$SERVER_FQDN"
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment