Skip to content

Instantly share code, notes, and snippets.

@sachaarbonel
Last active October 12, 2016 13:39
Show Gist options
  • Save sachaarbonel/7235a1212a00ed9641fad9a45f889d71 to your computer and use it in GitHub Desktop.
Save sachaarbonel/7235a1212a00ed9641fad9a45f889d71 to your computer and use it in GitHub Desktop.

Installation

warning

CartoDB is guaranteed to run without any issue in Ubuntu 12.04 x64. This documentation describes the process to install CartoDB in this specific OS version.

However this doesn’t mean that it won’t work with other Operating Systems or other Ubuntu. There are also many successful installations on Amazon EC2, Linode, dedicated instances and development machines running OS X and Ubuntu 12.04+.

System requirements

Besides the OS version mentioned in the introduction, there are some system requirements needed before starting with the installation of the stack. Also this process assumes that you have enough permissions in the system to run successfully most part of the commands of this doc.

System locales

Installations assume you use UTF8. You can set the locale by doing this:

sudo locale-gen en_US.UTF-8
sudo update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8

Build essentials

Although we try to maintain packaged versions of almost every part of the stack, there are some parts like gems or npm packages that need some development tools in the system in order to compile. You can install all the needed build tools by doing this:

sudo apt-get install autoconf binutils-doc bison build-essential flex

GIT

You will need git commands in order to handle some repositories and install some dependencies:

sudo apt-get install git

APT tools

In order to easily install some packages repositories sources is suggested to install this tool:

sudo apt-get install python-software-properties 

PostgreSQL

  • Add PPA repository

    sudo add-apt-repository ppa:cartodb/postgresql-9.3 && sudo apt-get update
    
  • Install client packages

    sudo apt-get install libpq5 \
                         libpq-dev \
                         postgresql-client-9.3 \
                         postgresql-client-common
    
    • Install server packages
    sudo apt-get install postgresql-9.3 \ 
                         postgresql-contrib-9.3 \
                         postgresql-server-dev-9.3 \
                         postgresql-plpython-9.3
    

PostgreSQL access authorization is managed through pg_hba.conf configuration file, which is normally in /etc/postgresql/9.3/main/pg_hba.conf. Here it’s defined how the users created in postgresql cluster can access the server. This involves several aspects like type of authentication (md5, no password, etc..) or source IP of the connection. In order to simplify the process of the installation we are going to allow connections with postgres user from localhost without authentication. Of course this can be configured in a different way at any moment but changes here should imply changes in database access configuration of CartoDB apps.

This is the pg_hba.conf with the no password access from localhost:

local   all             postgres                                trust
local   all             all                                     trust
host    all             all             127.0.0.1/32            trust

For these changes to take effect, you’ll need to restart postgres:

sudo service postgresql restart
  • Create some users in PostgreSQL. These users are used by some CartoDB apps internally

    sudo createuser publicuser --no-createrole --no-createdb --no-superuser -U postgres
    sudo createuser tileuser --no-createrole --no-createdb --no-superuser -U postgres
    
  • Install CartoDB postgresql extension. This extension contains functions that are used by different parts of the CartoDB platform, included the Editor and the SQL and Maps API.

    git clone https://github.com/CartoDB/cartodb-postgresql.git
    cd cartodb-postgresql
    git checkout <LATEST cartodb-postgresql tag>
    sudo make all install
    

GIS dependencies

  • Add GIS PPA

    sudo add-apt-repository ppa:cartodb/gis && sudo apt-get update
    
  • Install Proj

    sudo apt-get install proj proj-bin proj-data libproj-dev 
    
  • Install JSON

    sudo apt-get install libjson0 libjson0-dev python-simplejson
    
  • Install GEOS

    sudo apt-get install libgeos-c1v5 libgeos-dev
    
  • Install GDAL

    sudo apt-get install gdal-bin libgdal1-dev libgdal-dev
    sudo apt-get install gdal2.1-static-bin
    

    PostGIS =======

  • Install PostGIS

    sudo apt-get install libxml2-dev
    sudo apt-get install liblwgeom-2.1.8 postgis postgresql-9.3-postgis-2.2 postgresql-9.3-postgis-scripts
    
  • Initialize template postgis database. We create a template database in postgresql that will contain the postgis extension. This way, every time CartoDB creates a new user database it just clones this template database

    sudo createdb -T template0 -O postgres -U postgres -E UTF8 template_postgis
    sudo createlang plpgsql -U postgres -d template_postgis
    psql -U postgres template_postgis -c 'CREATE EXTENSION postgis;CREATE EXTENSION postgis_topology;'
    sudo ldconfig
    
  • Run an installcheck to verify the database has been installed properly

    sudo PGUSER=postgres make installcheck # to run tests
    

    Check https://github.com/cartodb/cartodb-postgresql for further reference

  • Restart PostgreSQL after all this process

    sudo service postgresql restart
    

Redis

Redis 3+ is needed.

  • Add redis PPA

    sudo add-apt-repository ppa:cartodb/redis && sudo apt-get update
    
  • Install redis

    sudo apt-get install redis-server
    

warning

By default redis server is configured to not have any type of disk persistence. If stopped or restarted everything stored in redis will be lost. In CartoDB redis is not just a simple cache storage. It stores information that need to be persisted.

Make sure to have proper values of save, appendonly and appendfsync config attributes. For more information check http://redis.io/topics/persistence

NodeJS

NodeJS is required by different parts of the stack. The more significant are the Maps and SQL APIs. It’s also used to install and execute some dependencies of the editor.

  • Add the PPA

    sudo add-apt-repository ppa:cartodb/nodejs-010 && sudo apt-get update
    
  • Install NodeJS

    sudo apt-get install nodejs 
    

    Note this should install both NodeJS 0.10.26 and npm 2.14.16. You can verify the installation went as expected with:

    nodejs -v
    npm -v
    

    SQL API =======

  • Download API

    git clone git://github.com/CartoDB/CartoDB-SQL-API.git
    cd CartoDB-SQL-API
    git checkout master
    
  • Install npm dependencies

    npm install
    
  • Create configuration. The name of the filename of the configuration must be the same than the environment you are going to use to start the service. Let’s assume it’s development.

    cp config/environments/development.js.example config/environments/development.js
    
  • Start the service. The second parameter is always the environment if the service. Remember to use the same you used in the configuration.

    node app.js development
    

MAPS API

  • Download API

    git clone git://github.com/CartoDB/Windshaft-cartodb.git
    cd Windshaft-cartodb
    git checkout master
    
  • Install npm dependencies

    npm install
    

warning

If this fails due to package cairo not found in the pkg-config search path, you can install it like this

$  sudo apt-get install libpango1.0-dev

After this change, re-run npm install, and it should be OK.

  • Create configuration. The name of the filename of the configuration must be the same than the environment you are going to use to start the service. Let’s assume it’s development.

    cp config/environments/development.js.example config/environments/development.js
    
  • Start the service. The second parameter is always the environment of the service. Remember to use the same you used in the configuration.

    node app.js development
    

    Ruby ====

  • Download ruby-install. Ruby-install is a script that makes ruby install easier. It’s not needed to get ruby installed but it helps in the process.

    wget -O ruby-install-0.5.0.tar.gz https://github.com/postmodern/ruby-install/archive/v0.5.0.tar.gz
    tar -xzvf ruby-install-0.5.0.tar.gz
    cd ruby-install-0.5.0/
    sudo make install
    
  • Install some ruby dependencies

    sudo apt-get install libreadline6-dev openssl
    
  • Install ruby 2.2.3. CartoDB has been deeply tested with Ruby 2.2.

    sudo ruby-install ruby 2.2.3
    
  • Ruby-install will leave everything in /opt/rubies/ruby-2.2.3/bin. To be able to run ruby and gem later on, you’ll need to add the Ruby 2.2.3 bin folder to your PATH variable. It’s also a good idea to include this line in your bashrc so that it gets loaded on restart

    export PATH=$PATH:/opt/rubies/ruby-2.2.3/bin
    
  • Install bundler. Bundler is an app used to manage ruby dependencies. It is needed by CartoDB’s editor

    sudo gem install bundler
    
  • Install compass. It will be needed later on by CartoDB’s editor

    sudo gem install compass
    

    Editor ======

  • Download the editor code

    git clone --recursive https://github.com/CartoDB/cartodb.git
    cd cartodb
    
  • Install pip

    sudo wget  -O /tmp/get-pip.py https://bootstrap.pypa.io/get-pip.py
    sudo python /tmp/get-pip.py
    
  • Install a necessary package for python dependencies

    sudo apt-get install python-all-dev
    
  • Install dependencies

    sudo apt-get install imagemagick unp zip
    RAILS_ENV=development bundle install
    npm install
    sudo pip install --no-use-wheel -r python_requirements.txt
    

warning

If this fails due to the installation of the gdal package not finding Python.h or any other header file, you’ll need to do this:

export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal
export PATH=$PATH:/usr/include/gdal

After this, re-run the pip install command. Variables can be passed to sudo if exporting them and re-running pip install doesn’t work:

sudo CPLUS_INCLUDE_PATH=/usr/include/gdal C_INCLUDE_PATH=/usr/include/gdal PATH=$PATH:/usr/include/gdal pip install --no-use-wheel -r python_requirements.txt

If gdal keeps failing, see more information here: http://gis.stackexchange.com/questions/28966/python-gdal-package-missing-header-file-when-installing-via-pip

  • Add the grunt command to the PATH

    export PATH=$PATH:$PWD/node_modules/grunt-cli/bin
    
  • Install all necesary gems

    bundle install
    
  • Precompile assets. Note that the last parameter is the environment used to run the application. It must be the same used in the Maps and SQL APIs

    bundle exec grunt --environment development
    
  • Create configuration files

    cp config/app_config.yml.sample config/app_config.yml
    cp config/database.yml.sample config/database.yml
    
  • Initialize the metadata database

    RAILS_ENV=development bundle exec rake db:create
    RAILS_ENV=development bundle exec rake db:migrate
    
  • Start the redis-server that allows access to the SQL and Maps APIs:

    redis-server &
    
  • Start the editor HTTP server

    RAILS_ENV=development bundle exec rails server
    
  • In a different process/console start the resque process

    RAILS_ENV=development bundle exec ./script/resque
    

Running CartoDB

First run, setting up an user

First run, setting up first time to run your development version of CartoDB. Let’s suppose that we are going to create a development env and that our user/subdomain is going to be ‘development’

cd cartodb
export SUBDOMAIN=development

# Add entries to /etc/hosts needed in development
echo "127.0.0.1 ${SUBDOMAIN}.localhost.lan" | sudo tee -a /etc/hosts

# Create a development user
sh script/create_dev_user ${SUBDOMAIN}

Running all the processes

Start the resque daemon (needed for import jobs):

bundle exec script/resque

Finally, start the CartoDB development server on port 3000:

bundle exec thin start --threaded -p 3000 --threadpool-size 5

Node apps

cd cartodb-sql-api && node app.js
cd windshaft-cartodb && node app.js

You should now be able to access http://<mysubdomain>.localhost.lan:3000 in your browser and login with the password specified above.

Enjoy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment