Project

General

Profile

Support #735

Install an OpenStreetMap Server on FreeBSD

Added by Daniel Curtis over 4 years ago. Updated over 3 years ago.

Status:
Suspended
Priority:
Normal
Assignee:
Category:
Global Positioning Server
Target version:
Start date:
01/25/2016
Due date:
% Done:

80%

Estimated time:
2.00 h
Spent time:

Description

This is a guide on installing a local OpenStreetMap server on FreeBSD 9.

Prepare the Environment

  • Make sure the system is up to date:
    pkg update && pkg upgrade
    
  • Install a few dependencies:
    pkg install git ruby ruby21-gems rubygem-bundler rubygem-rake ImageMagick-nox11 python2 gmake node npm
    
  • Create an osm user
    pw add user -n osm -m -s /bin/sh -c "OpenStreetMap" 
    
  • Install svgo:
    npm install -g svgo
    
  • Create the osm web app directory:
    mkdir -p /usr/local/www/osm
    chown -R osm:osm /usr/local/www/osm
    

Install PostgreSQL 9.4

  • Install PostgreSQL:
    pkg install postgresql94-{server,client,contrib}
    
  • Enable PostgreSQL at boot:
    echo 'postgresql_enable="YES"' >> /etc/rc.conf
    echo 'postgresql_flags="-w -s -m fast"' >> /etc/rc.conf
    echo 'postgresql_initdb_flags="--encoding=utf-8 --lc-collate=C"' >> /etc/rc.conf
    
  • Edit the login.conf file:
    vi /usr/local/etc/login.conf
    
    • And add the following to the end of the file:
      postgres:\
              :lang=en_US.UTF-8:\
              :setenv=LC_COLLATE=C:\
              :tc=default:
      
  • Then run to apply the changes:
    cap_mkdb login.conf
    
  • Initialize the database:
    service postgresql initdb
    
  • Start PostgreSQL:
    service postgresql start
    
  • Edit the postgres config file:
    vi /usr/local/pgsql/data/postgresql.conf
    
    • And modify the following:
      listen_addresses = '*'
      
  • Edit the pg_hba config file:
    vi /usr/local/etc/pgsql/data/pg_hba.conf
    
    • And modify the following:
      # TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD only
      
      # Local connections
      local   all         all                               trust
      
      # IPv4 local connections:
      host    all         all         127.0.0.1/32          trust
      
      # IPv6 local connections:
      host    all         all         ::1/128               trust
      
      # IPv4 connections:
      host    all         all         192.168.10.0/24       md5
      
  • Restart postgresql:
    service postgresql restart
    

Create a new user and database

  • Switch to the pgsql user and enter into the psql prompt:
    su - pgsql
    psql -d template1
    
    • Create the osmuser user and osm, osm_test, and openstreetmap databases:
      CREATE USER osmuser WITH PASSWORD 'SuperSecretPassword';
      
      ALTER USER osmuser CREATEDB;
      
      CREATE DATABASE openstreetmap OWNER osmuser ENCODING 'UTF8';
      CREATE DATABASE osm OWNER osmuser ENCODING 'UTF8';
      CREATE DATABASE osm_test OWNER osmuser ENCODING 'UTF8';
      
      GRANT ALL PRIVILEGES ON DATABASE "openstreetmap" to osmuser;
      GRANT ALL PRIVILEGES ON DATABASE "osm" to osmuser;
      GRANT ALL PRIVILEGES ON DATABASE "osm_test" to osmuser;
      
    • Exit from the postgres user
      \q
      exit
      
  • Enter into the psql prompt for the openstreetmap database:
    psql -d openstreetmap
    
    • Create the btree_gist postgresql extension:
      CREATE EXTENSION btree_gist;
      
    • Exit from the postgres user
      \q
      exit
      
  • Enter into the psql prompt for the osm database:
    psql -d osm
    
    • Create the btree_gist postgresql extension:
      CREATE EXTENSION btree_gist;
      
    • Exit from the postgres user
      \q
      exit
      
  • Enter into the psql prompt for the osm_test database:
    psql -d osm_test
    
    • Create the btree_gist postgresql extension:
      CREATE EXTENSION btree_gist;
      
    • Exit from the postgres user
      \q
      exit
      

Install OpenStreetMap

  • Switch to the osm user:
    su - osm
    
  • Get the current OpenStreetMap code:
    cd /usr/local/www/osm
    git clone git://git.openstreetmap.org/rails.git
    
  • Copy and edit the configuration files
    cd rails
    cp config/example.application.yml config/application.yml
    cp config/example.database.yml config/database.yml
    
  • Edit the database.yml file:
    vi config/database.yml
    
    • And change the following parameters:
      # Using a recent release (9.1 or higher) of PostgreSQL (http://postgresql.org/) is recommended.
      # See https://github.com/openstreetmap/openstreetmap-website/blob/master/INSTALL.md#database-setup for detailed setup instructions.
      #
      development:
        adapter: postgresql
        database: openstreetmap
        username: osmuser
        password: SuperSecretPassword
        host: localhost
        encoding: utf8
      
      # Warning: The database defined as 'test' will be erased and
      # re-generated from your development database when you run 'rake'.
      # Do not set this db to the same as development or production.
      test:
        adapter: postgresql
        database: osm_test
        username: osmuser
        password: SuperSecretPassword
        host: localhost
        encoding: utf8
      
      production:
        adapter: postgresql
        database: osm
        username: osmuser
        password: SuperSecretPassword
        host: localhost
        encoding: utf8
      
  • Install the gems:
    bundle install --path vendor/bundle
    
  • Exit from the osm user, back into the root user:
    exit
    
  • Build and configure the libpgosm module
    cd /usr/local/www/osm/rails/db/functions
    gmake
    chown -R osm:osm .
    
  • Switch to the pgsql user and enter into the psql prompt:
    su - pgsql
    psql -d openstreetmap
    
    • Configure the libpgosm:
      CREATE FUNCTION maptile_for_point(int8, int8, int4) RETURNS int4 AS '/usr/local/www/osm/rails/db/functions/libpgosm.so', 'maptile_for_point' LANGUAGE C STRICT;
      CREATE FUNCTION tile_for_point(int4, int4) RETURNS int8 AS '/usr/local/www/osm/rails/db/functions/libpgosm.so', 'tile_for_point' LANGUAGE C STRICT;
      
    • Exit from the postgres user
      \q
      exit
      
  • Populating the database structure and test it:
    su - osm
    cd rails
    bundle exec rake db:migrate
    env RAILS_ENV=production bundle exec rake db:migrate
    env RAILS_ENV=test bundle exec rake db:migrate
    env RAILS_ENV=test bundle exec rake test
    
  • Generate a secret key for the production environment:
    RAILS_ENV=production rake secret >> /usr/local/www/osm/rails/config/secrets.yml
    
    • Edit the secrets.yml file and adjust the production key parameter, removing the <%= ENV["SECRET_KEY_BASE"] %> string:
      vi /usr/local/www/osm/rails/config/secrets.yml
      
    • Adjust the production secret similar to the following:
        secret_key_base: 56d21b623f317d434f223dac278fb919d098b4c7e6a62f0142560564037faed44d747016c07b09a5ea1202e45843ef5863aa91ef7ea4e018ae4a8abef3fb1889
      
  • Precompile the production assets:
    env RAILS_ENV=production bundle exec rake assets:precompile
    

Install Phusion Passenger

  • Install Passenger
    portmaster www/rubygem-passenger
    
    • NOTE: Make sure to enable [X]NGINX while configuring rubygem-passenger
    • NOTE: Enabling [X]SYMLINK makes upgrading passenger easier later on.
    • NOTE: Ruby capabilities can be further extended by using rubygem packages, to search for more packages run:
      find /usr/ports/ -name "rubygem-*" 
      
  • Install nginx with passenger support:
    cd /usr/ports/www/nginx
    make config
    portmaster www/nginx
    
    • NOTE: Make sure to enable [X]PASSENGER while configuring nginx
  • Start and enable nginx at boot:
    echo 'nginx_enable="YES"' >> /etc/rc.conf
    service nginx start
    
  • Create a configuration directory to make managing individual server blocks easier
    mkdir /usr/local/etc/nginx/conf.d
    
  • Edit the main nginx config file:
    vi /usr/local/etc/nginx/nginx.conf
    
    • And add the Passenger config parameters:
      #user  nobody;
      worker_processes  1;
      error_log  /var/log/nginx-error.log;
      
      events {
          worker_connections  1024;
      }
      
      http {
          include       mime.types;
          default_type  application/octet-stream;
      
          sendfile        on;
          #tcp_nopush     on;
      
          #keepalive_timeout  0;
          keepalive_timeout  65;
      
          #gzip  on;
      
          # Load Phusion Passenger module globally
          passenger_root /usr/local/lib/ruby/gems/2.1/gems/passenger;
          passenger_ruby /usr/local/bin/ruby21;
          passenger_max_pool_size 15;
          passenger_pool_idle_time 300;
      
          # Load config files from the /etc/nginx/conf.d directory
          include /usr/local/etc/nginx/conf.d/*.conf;
      }
      
  • Restart nginx to load passenger:
    service nginx restart
    
  • Add a osm.example.com server block:
    vi /usr/local/etc/nginx/conf.d/osm.example.com.conf
    
    • Add the following:
      server {
          listen       80;
          server_name  osm.example.com;
          root         /usr/local/www/osm/rails/public;
          access_log   /var/log/osm.example.com-access.log;
          error_log    /var/log/osm.example.com-error.log;
      
          passenger_enabled on;
          passenger_user    osm;
          passenger_group   osm;
      }
      
  • Restart nginx to load the website config:
    service nginx restart
    

Import Latest Planet File

  • Fetch the latest planet file:
    fetch http://planet.openstreetmap.org/planet/planet-latest.osm.bz2
    

Resources

History

#1 Updated by Daniel Curtis over 4 years ago

  • Description updated (diff)
  • Status changed from New to In Progress
  • % Done changed from 0 to 30

#2 Updated by Daniel Curtis over 4 years ago

  • Description updated (diff)
  • % Done changed from 30 to 60

#3 Updated by Daniel Curtis over 4 years ago

  • Description updated (diff)

#4 Updated by Daniel Curtis over 4 years ago

  • % Done changed from 60 to 80
  • Description updated (diff)

#5 Updated by Daniel Curtis over 3 years ago

  • Status changed from In Progress to Suspended

Also available in: Atom PDF