oTree Forum >

Unclear installation instructions

#1 by Stefano_Mariani

Dear OTree devs,
I'm trying to follow the installation instructions provided [here](https://otree.readthedocs.io/en/latest/server/ubuntu.html#) to set up my own instance of OTree. 

I followed the instructions there up to [here](https://otree.readthedocs.io/en/latest/server/ubuntu.html#reset-the-database-on-the-server) excluded, then I jumped [here](https://www.otree.org/) (section "Getting started") as I figured out I didn't have any requirements.txt to install...(maybe consider adding this specification to the installation instructions)

From there I run the commands to create a new project (I choose to include example games), and then, before starting the devserver, I went back [here](https://otree.readthedocs.io/en/latest/server/ubuntu.html#reset-the-database-on-the-server) to install the dependencies and reset the db.

Then I got stuck: as I give command `otree resetdb` I get an exception dump (I'm on the command line on Ubuntu) that terminates with the following

`` 
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) connection to server at "localhost" (127.0.0.1), port 5432 failed: fe_sendauth: no password supplied
``

can you help me understand what is the problem? I guess I need a way to give the password to the Postgres DB as an argument to the `resetdb` script?

#2 by BonnEconLab (edited )

I assume that you have installed PostgreSQL, and it seems that you have installed psycopg2 (psycopg2-binary). As the error message indicates, you are missing a password in at least one place.

(And I agree that the installation instructions on https://otree.readthedocs.io/en/latest/server/ubuntu.html could be improved.)

Have you done the following?

(1) Change user to the postgres user, so that you can execute some commands:

sudo su - postgres

(2) Then start the PostgreSQL shell:

psql

(3) Once you’re in the PostgreSQL shell, create a database and user:

CREATE DATABASE django_db;
alter user postgres password 'password';

(Instead of 'password', you can choose something else, say 'StefanoM'.)

(4) Exit the SQL prompt:

\q

(5) Return from the postgres user to your regular command prompt:

exit

(6) Then add the following lines to your .bashrc/.profile (preferably at the end, so it is easy to locate them):

#export PATH=~/.local/bin:$PATH
export DATABASE_URL=postgres://postgres:password@localhost/django_db
# If you chose your password to be 'StefanoM' in Step 3:
# export DATABASE_URL=postgres://postgres:StefanoM@localhost/django_db
export OTREE_ADMIN_PASSWORD=Choose-a-password-of-your-liking
export OTREE_PRODUCTION=1
export OTREE_AUTH_LEVEL=STUDY
export REDIS_URL="redis://"

You can do so, for instance, via

nano ~/.bashrc

(If you use nano, hit [ctrl] + [o] for saving the changes and [ctrl] + [x] for quitting nano.)

Alternatively, you can also set some variables in your settings.py file:

AUTH_LEVEL = "STUDY"
ADMIN_PASSWORD = "Choose-a-password-of-your-liking"
DEBUG = 0

This, however, will make it more difficult to run the code without changes locally for debugging and on the server.

(7) To start oTree, cd to your project folder and enter

otree runprodserver

(Use `screen -S oTree -d -m otree prodserver` to keep oTree running in the background. Access the detached screen via `screen -r`.)

(8) You should then be able to access your oTree instance by opening http://ip-address.of.your.server:8000 in a browser.

#3 by Stefano_Mariani

Dear BonnEconLab, 
many thanks for your prompt reply. 

I think I got, after many tries, as somehow I "broke" the devserver.

Without bothering you with the technical details, it is correct that the only difference I see between devserver and prodserver, is that under the tab "Server check" the devserver uses SQLite instead of Postgre?

All other things are the same (e.g. same username and password)

I guess so (as it depends on my won configuration), but I want to check to be sure.

If you need additional details just ask.

#4 by BonnEconLab

`otree prodserver` does not use PostgreSQL automatically but only if you set it up as described above. Otherwise, `otree prodserver` will also use SQLite.

The difference between `otree devserver` and `otree prodserver`, at least on my Mac, is that with `otree devserver`, I can only access oTree via http://localhost:8000. If I want to access oTree from other computers, I have to use `otree prodserver`. Additional differences are better explained by Chris_oTree.

#5 by Stefano_Mariani

Dear @BonnEconLab many thanks for the clarification. 

Could you elaborate more on the sentence "Additional differences are better explained by Chris_oTree": where?

I'm also wondering whether I can bind the dev server and/or the prod server to a different IP address, but I'm not finding instructions about how to do it...is this the right place to ask?

Or is it better to ask in the Github repo issues sections?

#6 by BonnEconLab

@Stefano_Mariani asked:

> Could you elaborate more on the sentence "Additional differences are better explained by Chris_oTree": where?

Ah, I meant, “I can’t really explain what the additional differences are; they would be better explained by Chris_oTree.”

#7 by BonnEconLab

@Stefano_Mariani asked:

> I'm also wondering whether I can bind the dev server and/or the prod server to a different IP address, but I'm not finding instructions about how to do it...is this the right place to ask?

I don’t really understand what you mean by binding to “a different IP address.” Different from what — from the IP address of your server? Do you mean that your server can be reached via two different IP addresses?

You can set up nginx as a reverse proxy to forward any traffic that arrives at a certain port (80 for HTTP, even better 443 for HTTPS) or at a certain IP address to oTree. Let me know if this is what you intend to do, and I can share the nginx configuration of our oTree servers. (https://github.com/trr266/otree_docker/blob/main/otree5_nginx_site.conf may also help.)

#8 by Stefano_Mariani

I would like to deploy also the devserver instance not in localhost, but on the public IP address of my server, that I can access via ssh in VPN...is that possible?

#9 by BonnEconLab (edited )

Yes, sure, that is possible. If you use `otree prodserver` rather than `otree devserver`, you can access your oTree experiment via http://your.ip.address:8000.

(This, of course, requires your computer’s and/or your department’s firewall to allow the respective connection between your computers. For instance, in my office, running `otree prodserver` is all I need to do, no matter whether I run oTree on a Windows, Mac or Linux machine, as long as the computers are connected to the university’s LAN. This does not work in the WiFi.)

Again, if you want to do without including the port in the URL (:8000), then you have to configure nginx so that it forwards ports 80 and 443 to 8000 (assuming you are running oTree on port 8000, which is the default).

Write a reply

Set forum username