Project

General

Profile

Support #735

Updated by Daniel Curtis over 8 years ago

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

 h2. Prepare the Environment 

 * Make sure the system is up to date: 
 <pre> 
 pkg update && pkg upgrade 
 </pre> 

 * Install a few dependencies: 
 <pre> 
 pkg install git ruby ruby21-gems rubygem-bundler rubygem-rake ImageMagick-nox11 python2 gmake node npm 
 </pre> 

 * Create an osm user 
 <pre> 
 pw add user -n osm -m -s /bin/sh -c "OpenStreetMap" 
 </pre>  

 * Install svgo: 
 <pre> 
 npm install -g svgo 
 </pre> 

 h2. Install PostgreSQL 9.4 

 * Install PostgreSQL: 
 <pre> 
 pkg install postgresql94-{server,client,contrib} 
 </pre> 

 * Enable PostgreSQL at boot: 
 <pre> 
 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 
 </pre> 

 * Edit the @login.conf@ file: 
 <pre> 
 vi /usr/local/etc/login.conf 
 </pre> 
 #* And add the following to the end of the file: 
 <pre> 
 postgres:\ 
         :lang=en_US.UTF-8:\ 
         :setenv=LC_COLLATE=C:\ 
         :tc=default: 
 </pre> 

 * Then run to apply the changes: 
 <pre> 
 cap_mkdb login.conf 
 </pre> 

 * Initialize the database: 
 <pre> 
 service postgresql initdb 
 </pre> 

 * Start PostgreSQL: 
 <pre> 
 service postgresql start 
 </pre> 

 * Edit the postgres config file: 
 <pre> 
 vi /usr/local/pgsql/data/postgresql.conf 
 </pre> 
 #* And modify the following: 
 <pre> 
 listen_addresses = '*' 
 </pre> 

 * Edit the pg_hba config file: 
 <pre> 
 vi /usr/local/etc/pgsql/data/pg_hba.conf 
 </pre> 
 #* And modify the following: 
 <pre> 
 # 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 
 </pre> 

 * Restart postgresql: 
 <pre> 
 service postgresql restart 
 </pre> 

 h2. Create a new user and database 

 * Switch to the pgsql user and enter into the psql prompt: 
 <pre> 
 su - pgsql 
 psql -d template1 
 </pre> 
 #* Create the *osmuser* user and *osm*, *osm_test*, and *openstreetmap* databases: *osmdb* database: 
 <pre> 
 CREATE USER osmuser WITH PASSWORD 'SuperSecretPassword'; 

 ALTER USER osmuser CREATEDB; 

 CREATE DATABASE openstreetmap openstreemap 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" "osmdb" to osmuser; 
 GRANT ALL PRIVILEGES ON DATABASE "osm" to osmuser; 
 GRANT ALL PRIVILEGES ON DATABASE "osm_test" to osmuser; 
 </pre> 
 #* Exit from the postgres user 
 <pre> 
 \q 
 exit 
 </pre> 

 * Enter into Import the psql prompt for the *openstreetmap* database: btree_gist.sql file: 
 <pre> 
 psql -d openstreetmap < /usr/local/share/postgresql/extension/btree_gist--1.0.sql 
 </pre> 
 #* Create the btree_gist postgresql extension: 
 <pre> 
 CREATE EXTENSION btree_gist; 
 </pre> 
 #* Exit from the postgres user 
 <pre> 
 \q 
 exit 
 </pre> 

 * Enter into the psql prompt for the *osm* database: 
 <pre> 
 psql -d osm 
 </pre> 
 #* Create the btree_gist postgresql extension: 
 <pre> 
 CREATE EXTENSION btree_gist; 
 </pre> 
 #* Exit from the postgres user 
 <pre> 
 \q 
 exit 
 </pre> 

 * Enter into the psql prompt for the *osm_test* database: 
 <pre> 
 psql -d osm_test 
 </pre> 
 #* Create the btree_gist postgresql extension: 
 <pre> 
 CREATE EXTENSION btree_gist; 
 </pre> 
 #* Exit from the postgres user 
 <pre> 
 \q 
 exit 
 </pre> 

 h2. Install OpenStreetMap 

 * Switch to the osm user: 
 <pre> 
 su - osm 
 </pre> 

 * Get the current OpenStreetMap code: 
 <pre> 
 git clone git://git.openstreetmap.org/rails.git 
 </pre> 

 * Copy and edit the configuration files 
 <pre> 
 cd rails 
 cp config/example.application.yml config/application.yml 
 cp config/example.database.yml config/database.yml 
 </pre>  

 * Edit the database.yml file: 
 <pre> 
 vi config/database.yml 
 </pre> 
 #* And change the following parameters: 
 <pre> 
 # 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 
 </pre> 

 * Install the gems: 
 <pre> 
 bundle install --path vendor/bundle 
 </pre> 

 * Exit from the osm user, back into the root user: 
 <pre> 
 exit 
 </pre> 

 * Build and configure the libpgosm module 
 <pre> 
 cd /home/osm/rails/db/functions 
 gmake 
 chown -R osm:osm . 
 </pre> 

 * Switch to the pgsql user and enter into the psql prompt: 
 <pre> 
 su - pgsql 
 psql -d openstreetmap 
 </pre> 
 #* Configure the libpgosm: 
 <pre> 
 CREATE FUNCTION maptile_for_point(int8, int8, int4) RETURNS int4 AS '/home/osm/rails/db/functions/libpgosm.so', 'maptile_for_point' LANGUAGE C STRICT; 
 CREATE FUNCTION tile_for_point(int4, int4) RETURNS int8 AS '/home/osm/rails/db/functions/libpgosm.so', 'tile_for_point' LANGUAGE C STRICT; 
 </pre> 
 #* Exit from the postgres user 
 <pre> 
 \q 
 exit 
 </pre> 

 * Populating the database structure and test it: 
 <pre> 
 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 
 </pre> 

 h2. Resources 

 * http://www.openstreetmap.org/ 
 * http://wiki.openstreetmap.org/wiki/User:S-s-s_wiki/Creating_a_local_OSM_server_under_FreeBSD 
 * https://git.openstreetmap.org/rails.git/

Back