Last active
February 9, 2022 20:08
-
-
Save pmarreck/1a0dfaad06c85e0919f8826a0da4bd53 to your computer and use it in GitHub Desktop.
How to get Erlang, Elixir, Phoenix and Postgres set up on a new blank Ubuntu cloud9.io (c9.io) project/VM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I had some issues with this and finally culled together instructions from various sites which finally worked | |
# The first thing you should do is clone your Phoenix/Elixir repo from Github to a blank Ubuntu c9.io VM | |
# The next thing we have to do is remove the stock Erlang which is erlang-base-hipe and not esl-erlang | |
# (this causes problems later on otherwise) | |
# But first we will add a new apt source | |
wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb | |
sudo dpkg -i erlang-solutions_1.0_all.deb | |
rm erlang-solutions_1.0_all.deb # shouldn't need it anymore | |
# and because the removal will error if this file is missing for some reason, we will touch it | |
sudo touch /etc/init.d/couchdb | |
sudo apt-get remove erlang-base | |
sudo apt-get remove couchdb | |
sudo apt-get update | |
sudo apt-get install esl-erlang | |
sudo apt-get install elixir | |
# Postgres 9.3 is fortunately already set up on the blank Ubuntu image, but you still have to start the service | |
sudo service postgresql start | |
# So now we set up the postgres user we expect to have in dev... i usually use postgres/postgres | |
sudo -u postgres psql # logs into postgres as the "postgres" user | |
### PSQL COMMANDS | |
\password postgres # sets the password of the current user to "postgres" | |
\q | |
### END PSQL | |
# At this point running "mix test" failed due to locale issues... en_US.utf8 was completely missing (!!) | |
# Turns out you have to set it up at the OS level first, then restart the postgres service, | |
# then modify the (sigh) template0 and template1 databases on the Postgres install | |
# which are used as templates to create any later databases | |
# So first check your list of locales: | |
locale -a | |
# You should (at this time) see absolutely no UTF8 encodings available. WTF, right? Anyway, let's fix. | |
# First you have to add en_US (these steps may need to be changed based on where you are in the world) | |
sudo locale-gen en_US | |
# Next you add the utf8 for en_US | |
sudo locale-gen en_US.UTF-8 # I forgot whether it's UTF-8 or UTF8 here. The actual nomenclature seems to change here and there FYI | |
# now check again | |
locale -a | |
# You now (sigh) have to add these lines to your ~/.bash_profile | |
export LANGUAGE="en_US.UTF-8" | |
export LANG="en_US.UTF-8" | |
export LC_ALL="en_US.UTF-8" | |
# Hopefully it's in there right now. If not, you may need to do further troubleshooting on your own | |
# Restarting postgres... | |
sudo service postgresql restart | |
# Moving on... we drop into postgres again | |
sudo -u postgres psql | |
# Now we have to convert the 2 template databases to utf8 by default | |
### PSQL COMMANDS | |
update pg_database set encoding = 6, datcollate = 'en_US.UTF8', datctype = 'en_US.UTF8' where datname = 'template0'; | |
update pg_database set encoding = 6, datcollate = 'en_US.UTF8', datctype = 'en_US.UTF8' where datname = 'template1'; | |
# If those don't work, try these: (these are the ones I actually used, but the above look simpler) | |
# I got these from https://techjourney.net/convert-postgresql-template0-template1-encoding-to-utf8-sql_ascii-incompatible/ | |
update pg_database set datallowconn = TRUE where datname = 'template0'; | |
\c template0 | |
update pg_database set datistemplate = FALSE where datname = 'template1'; | |
drop database template1; | |
create database template1 with encoding = 'UTF-8' lc_collate = 'en_US.UTF8' lc_ctype = 'en_US.UTF8' template = template0; | |
update pg_database set datistemplate = TRUE where datname = 'template1'; | |
\c template1 | |
update pg_database set datallowconn = FALSE where datname = 'template0'; | |
\q | |
# Hopefully that worked, otherwise you have to google "defaulting postgres to utf8" and look further into it. | |
\q | |
### END PSQL | |
# At this point (hopefully!), all new databases created (such as the one by your test) will default to utf8. What a pain! | |
mix test | |
# NOW I ran into an issue where "citext" was unavailable as a column type... this fixes that: | |
sudo apt-get install postgresql-contrib-9.3 | |
sudo service postgresql restart | |
mix test | |
# SUCCESS! At least on my end. Hopefully yours as well. Enjoy your new cloud Phoenix dev environment! | |
# BUT NOTE: I still have no idea how to run a server from c9.io yet that I can access locally... lol. Will update! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment