This weekend I had to reinstall Linux on my laptop (and took the occasion to migrate from Ubuntu 16.04 Mate to Elementary OS Loki, based on Ubuntu 16.04)
Therefore I had to go through the safecast setup all over again (I did struggle with the setup the first time few weeks ago).
Here is how I manage to have it work:
rvm install 2.1.10
sudo apt-get install postgis
I already had postgres installed (I use it in my everyday life dev setup). I can add a quick how-to install for beginners.
Finally check postgis
createdb postgis_test
psql postgis_test
> CREATE EXTENSION postgis;
> SELECT PostGIS_Version();
> \q
And create a safecast user
createuser -s safecast
(you might need to log into postgresql super user to create this new "safecast" user. if so, run sudo -u postgres -i
)
Until this point, it follows almost the same setup as the OSX setup.
But, after that, you have to make 2 important modifications to have it work:
In the file : /etc/postgresql/9.5/main/pg_hba.conf
you need to add two lines, to allow the safecast
user (created few lines above) to connect to the database without password (as there is no password written in the database.yml
in the safecast rails project)
Your pg_hba.conf
should look like this:
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
You'll need to add the following lines:
Add this line:
local all safecast trust
below the line: # "local" is for Unix domain socket connections only
And add this line:
host all safecast 127.0.0.1/32 trust
below the line: # IPv4 local connections:
At the end, it should look like this:
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all safecast trust
local all all peer
# IPv4 local connections:
host all safecast 127.0.0.1/32 trust
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
Save and close the file.
For some reasons, the postgis path isn't the same on Mac and Linux. Therefore, you have to change the database.yml file inside the rails project.
Inside the database.yml, you'll see three main configation: development, test, and production. Here, we are just concerned with development and test.
You need to change this line
script_dir: /usr/local/share/postgis
into this one:
script_dir: /usr/share/postgresql/9.5/contrib/postgis-2.2/
(be sure to adapt your postgresql version number and postgis version number - mine are 9.5 and 2.2)
You have to change this line for both the development and test config (line 19 and 48)
After these changes, you can go back to the rest of the configuration as explained in the mac os x guide.
bundle exec rake db:create db:structure:load
bundle exec rake db:bootstrap
RAILS_ENV=test bundle exec rake db:structure:load
And then run the test
bundle exec rspec spec
and you can finally launch the rails server
bundle exec rails server