Support #735
Updated by Daniel Curtis almost 9 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> * Create the osm web app directory: <pre> mkdir -p /usr/local/www/osm chown -R osm:osm /usr/local/www/osm </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: <pre> 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; </pre> #* Exit from the postgres user <pre> \q exit </pre> * Enter into the psql prompt for the *openstreetmap* database: <pre> psql -d openstreetmap </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> cd /usr/local/www/osm 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 /usr/local/www/osm/rails/db/functions /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 '/usr/local/www/osm/rails/db/functions/libpgosm.so', '/home/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', '/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. Install Phusion Passenger * Install Passenger <pre> portmaster www/rubygem-passenger </pre> #* *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: <pre> find /usr/ports/ -name "rubygem-*" </pre> * Reinstall nginx with passenger support: <pre> cd /usr/ports/www/nginx make config portmaster www/nginx </pre> #* *NOTE*: Make sure to enable *@[X]PASSENGER@* while configuring _nginx_ * Edit the main nginx config file: <pre> vi /usr/local/etc/nginx/nginx.conf </pre> #* And add the Passenger config parameters: <pre> #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; } </pre> * Restart nginx to load passenger: <pre> service nginx restart </pre> * Add a *osm.example.com server block*: <pre> vi /usr/local/etc/nginx/conf.d/osm.example.com.conf </pre> #* Add the following: <pre> 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; } </pre> * Restart nginx to load the website config: <pre> service nginx restart </pre> h2. Import Latest Planet File * Fetch the latest planet file: <pre> fetch http://planet.openstreetmap.org/planet/planet-latest.osm.bz2 </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/