To use Phoenix and React, you need to install a few things on your computer. There are a surprising number of things that can go wrong with the installation, usually involving the installation of PostgreSQL.
The first thing you should get is Homebrew. Homebrew allows you to run the command brew to install just about anything on your Mac. Run the following command if you do not already have Homebrew installed. It might require you to install xcode or some extra software. If it prompts you to do so, install that too:
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"You should check to make sure the installation ran properly by running the command brew help, which should pop up with some helper text. If you get an error, something went wrong and you should do some Googling to figure out what went wrong.
Now that you have Homebrew, it's pretty easy to install everything else. You will need Node to run your JavaScript server and to have access to the Node Package Manager (NPM), which you will use to install a variety of assets, including React and Redux.
Run the following command to install Node:
$ brew install nodeThen, for good measure, check to make sure the installation was successful by running node -v, which will return the version of Node you are using. You should also check to make sure that NPM was installed by running npm -v.
We are assuming you're using a Mac, so the instructions below will be for a Mac installation. If you have a different machine, follow this link to find instructions.
If you're on a Mac, run:
$ brew install elixirAnd you're done. To ensure the installation went smoothly, run iex to see if the interactive Elixir shell worked.
If it did, and this is your first installation of Elixir, you will need to install the Hex package manager (the Elixir equivalent to NPM). You can install it by running mix local.hex
Now it's time to install Phoenix. Run the following command to install:
$ mix archive.install https://github.com/phoenixframework/archives/raw/master/phoenix_new.ezWe will use PostgreSQL (often referred to as "Postgres") as our default database. A lot of things can go wrong here, so you might have to do some debugging to make sure you can get Posgres to work on your machine.
Install Postgres by running the command:
$ brew install postgresqlPostgres is now installed on your machine, but it is not running. You'll want to start Postgres at login, so run the following two commands to both set Postgres to launch at login and launch now:
$ ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plistTo make sure everything installed properly, run the command which psql, which should return /usr/local/bin/psql. If it does not, something went wrong and you're in for some debugging.
Now you need to create a default database, which should be the same as your username. If you do not know your username, you can find it by running the command whoami. Create the database with the following command, with your username in place of <username>:
$ createdb `<username>`Then run psql to make sure the database was created properly. If you enter the Postgres shell, you're in business!
If you already have a previous version of Postgres installed, you will probably run into some problems.
$ pg_ctl -D /usr/local/var/postgres -l logfile startAnother potential problem that comes up regularly is the lack of a "role". If you get the following error, you will need to configure a role:
** (Mix) The database for Firestorm.Repo couldnt be created, reason given: psql: FATAL: role "postgres" does not existYou can configure a role by entering the psql shell and creating the role. Run the following command:
$ psql postgresThis will bring up a new shell that gives you the ability to run commands. You should enter the following to create the new role (note that postgres=# is the prompt and should not be entered):
postgres=# CREATE ROLE postgres LOGIN CREATEDB;You should receive CREATE ROLE as the response. Then exit the shell with \q and you should be in business!
If you're still having issues, try restarting Postgres with the following commands.
$ pg_ctl -D /usr/local/var/postgres stop -s -m fast$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log startAnd if you still can't get it working, try Stackoverflow or a Google search.
You will also need a text editor of some sort. You can use Sublime Text 3, Atom, or any other text editor you'd like (or if you're a ninja, you can use vim). Some people also prefer an IDE (integrated development environment) such as Webstorm. At the end of the day, this is all a matter of preference and will make little difference.
Previous: IntroductionNext: Directory Structure