Skip to content

Instantly share code, notes, and snippets.

@paridin
Last active February 6, 2016 13:13
Show Gist options
  • Save paridin/ae9c692e33036a3fa460 to your computer and use it in GitHub Desktop.
Save paridin/ae9c692e33036a3fa460 to your computer and use it in GitHub Desktop.
Install on AWS Nginx 1.8 + Passenger 5.0 + Postgresql 9.4 + Python 3.4.3 + Django 1.8.4 + Redmine 3.1

AWS Nginx 1.8 + Passenger 5.0 + Postgresql 9.4 + Python 3.4.3 + Django 1.8.4 + Redmine 3.1

In our aws instance we follow the next steps

$ sudo yum update
$ sudo yum -y groupinstall "Development Tools"
$ sudo yum  -y install memcached memcached-devel ImageMagick ImageMagick-devel openssl openssl-devel libcurl-devel nginx
$ sudo yum -y erase nginx # for fix an error of 403 forbbiden it ocurrs after but doing it all works fine

Postgresql 9.4

$ wget http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-ami201503-94-9.4-1.noarch.rpm
$ sudo rpm -ivh pgdg-ami201503-94-9.4-1.noarch.rpm
$ sudo yum -y install postgresql94 postgresql94-devel postgresql94-server
$ sudo chkconfig postgresql94 on
$ sudo service postgresql94 initdb
$ sudo service postgresql94 start
$ sudo su - postgres

$ psql -U postgres
> alter user postgres with password 'my_password';
> create user myuser with password 'another_password';
> create database mydb;
> grant all privileges on database mydb to myuser;

vi ~/.bash_profile
# change /var/lib/pgsql93/data to /var/lib/pgsql94/data
# save file

vi data/pg_hba.conf
# Change the METHOD to md5 as shown below
# local   all             all                                     md5  # example
# add another rule for allow from everywhere
local   all             all                 0.0.0.0/0                    md5  

$ vi data/postgresql.conf 
# add a new line with listen_addresses = ‘*’ 

$ pg_ctl reload
$ exit
$ sudo service postgresql94 restart

test connection

psql -U <user> 
password  

Python 3.4

We need install python 3.4 so i created a fast script for solve this task source.

$ wget http://bit.ly/install_py3_4_3 -O install_py3.4.sh
$ bash install_py3.4.sh
source ~/.bash_profile

Now we install rvm more info

$ curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
$ curl -sSL https://get.rvm.io | bash -s stable --ruby 
$ source $HOME/.rvm/scripts/rvm # at the end of the instalation says: To start using RVM you need to run `source /path/.rvm/scripts/rvm`
$ rvm install 2.2.1
$ sudo chmod o+x "/home/ec2-user"
# in a free aws tier, we only have 512 mb so we create a swap on out disk
$ sudo dd if=/dev/zero of=/swap bs=1M count=1024
$ sudo mkswap /swap
$ sudo chmod 600 /swap
$ sudo swapon /swap
$ gem install passenger 
$ passenger-install-nginx-module
Welcome to the Phusion Passenger Nginx module installer, v5.0.16.
  1. This installer will compile and install Nginx with Passenger support.
Which languages are you interested in?

You must choose the option you want in my case ruby and python are ok

 ⬢ Ruby
 ⬢ Python

Automatically download and install Nginx?

  1. Yes: download, compile and install Nginx for me. (recommended) Where do you want to install Nginx to?
Where do you want to install Nginx to?

Please specify a prefix directory [/opt/nginx]: /opt/nginx

Second part, we'll configure our nginx, to server our apps

vi $HOME/.local/nginx/conf/nginx.conf

We need to modify the nginx.conf file, so my refer is like next configuration

user nginx; # 

http {
    # Enable below if you have more than 128 hostnames on the server.
    # server_names_hash_bucket_size 128;
    # Enable below if your hostnames are longer than 100 characters.
    # server_names_hash_max_size 100;
    passenger_max_pool_size 200;
    #passenger_max_instances_per_app 7;
    rails_app_spawner_idle_time 600;
    passenger_pool_idle_time 300;
    passenger_debug_log_file /opt/nginx/logs/passenger-error.log;
    passenger_log_level 2;
    # ... save file and continue editing the server {
    # your ob params, is not necesary remove if you are no expert now.
    # if you choice you can remove the examples server uncommented and commentend 
    }
    include sites-enabled/*.conf;  # if you need serve multiples projects uncomment this and create your custom.conf in this path
    # Be sure you have the before directory, in my case I created with mkdir /opt/nginx/conf/sites-enabled
}

redmine.conf

server { # redmine 3.1 server
    listen 8080;
    rails_env production;
    server_name  localhost;
        
    access_log  logs/projects.access.log;
    error_log  logs/projects.error.log;
        
    location / {
        root "/home/ec2-user/redmine-3.1/public"; # Note its my public dir from redmine $HOME/redmine-3.1
        passenger_enabled on;
    }
    # allow load statics 
    location ~* ^favicon.ico|(?:(?:plugin_assets/|themes/).+/)(?:.+\.html|javascripts/.+\.js|stylesheets/.+\.css|images/.+\.(?:jpe?g|gif|ico|png))$ {
        expires max;
        passenger_enabled on;
    }
}

django-project.conf

NOTE: mkdir -p /home/ec2-user/Devel/python/project/public

server {
    listen 80;
    server_name ...us-west-2.compute.amazonaws.com; # your public dns

    # Tell Nginx and Passenger where your app's 'public' directory is
    root /home/ec2-user/Devel/python/project/public; # your public dir

    # Turn on Passenger
    passenger_enabled on;
    passenger_python /home/ec2-user/.virtualenvs/project/bin/python; # your virtualenv project
}

Config in file passenger_wsgi.py

#!/home/ec2-user/.virtualenvs/project/bin/python 
# change the before path for your virtualenv project

# Set up the virtual environment:
import os, sys
os.environ.setdefault('PATH', '/home/ec2-user/.local/bin:/usr/bin')
os.environ['PATH'] = '/home/ec2-user/.virtualenvs/project/bin:' + os.environ['PATH']
os.environ['VIRTUAL_ENV'] = '/home/ec2-user/.virtualenvs/project/bin'
os.environ['PYTHON_EGG_CACHE'] = '/home/ec2-user/.virtualenvs/project/bin'
os.chdir('/home/ec2-user/Devel/python/project')

# Add a custom Python path.
sys.path.insert(0, "/home/ec2-user/Devel/python/project")

os.environ['DJANGO_SETTINGS_MODULE'] = 'config.settings.production' # your dotted path for your settings file

# only for Django >= 1.7 
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Redmine 3.1

$ svn co https://svn.redmine.org/redmine/branches/3.1-stable redmine-3.1
$ gem install bundler
$ bundle install --without development test

DAEMON nginx

$ sudo wget -O /etc/init.d/nginx http://bit.ly/nginx_daemon
$ sudo chmod +x /etc/init.d/nginx
$ sudo chkconfig nginx on
$ sudo service nginx restart

NOTES

If we got this message
* WARNING: You have '~/.profile' file, you might want to load it,
    to do that add the following line to '/home/ec2-user/.bash_profile':

      source ~/.profile
# solve adding the load in our bash profile
echo "source ~/.profile" >> ~/.bash_profile

I added the ec2-user to nginx group

sudo usermod -G nginx ec2-user
Created by paridin software
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment