Thread: Setting up pgAdmin4 as a web application

Setting up pgAdmin4 as a web application

From
Derek Ealy
Date:
I've been trying to get pgAdmin4 to work as a web app for a couple of days. I've finally figured out python, pip, wsgi, apache (I think). I can see from the logs that is failing when trying to select from the version table which I assume should be in the sqlite Db as opposed to my postgres instance. 

I've located my pgadmin4.db file and can see that has zero bytes in it.

Here is the message that appears in my apache error log when I try to access the pgadmin4 website:

OperationalError: (sqlite3.OperationalError) no such table: version [SQL: u'SELECT version.name AS version_name, version.value AS version_value \\nFROM version \\nWHERE version.name = ?\\n LIMIT ? OFFSET ?'] [parameters: ('ConfigDB', 1, 0)], referer: http://dbgsdev01.nw.loc/

Any ideas how I can get this fixed?

Thanks, Derek

Re: Setting up pgAdmin4 as a web application

From
Dave Page
Date:
Hi

On Tue, Oct 18, 2016 at 6:42 PM, Derek Ealy <dealy663@gmail.com> wrote:
> I've been trying to get pgAdmin4 to work as a web app for a couple of days.
> I've finally figured out python, pip, wsgi, apache (I think). I can see from
> the logs that is failing when trying to select from the version table which
> I assume should be in the sqlite Db as opposed to my postgres instance.
>
> I've located my pgadmin4.db file and can see that has zero bytes in it.
>
> Here is the message that appears in my apache error log when I try to access
> the pgadmin4 website:
>
> OperationalError: (sqlite3.OperationalError) no such table: version [SQL:
> u'SELECT version.name AS version_name, version.value AS version_value
> \\nFROM version \\nWHERE version.name = ?\\n LIMIT ? OFFSET ?'] [parameters:
> ('ConfigDB', 1, 0)], referer: http://dbgsdev01.nw.loc/
>
> Any ideas how I can get this fixed?

I'll bet this is a permissions issue, with the webserver user account
being unable to properly write files where it needs to. On my test
system, I did something like the following:

- Stop the web server
- Set the following paths in config_local.py in the pgAdmin installation:

LOG_FILE = '/var/log/pgadmin4/pgadmin4.log'
SQLITE_PATH = '/var/lib/pgadmin4/pgadmin4.db'
SESSION_DB_PATH = '/var/lib/pgadmin4/sessions'
STORAGE_DIR = '/var/lib/pgadmin4/storage'

- My webserver is running as daemon:daemon - adjust the following to suit:

# mkdir /var/log/pgadmin4
# chown daemon:daemon /var/log/pgadmin4
# mkdir /var/lib/pgadmin4
# chown daemon:daemon /var/lib/pgadmin4

- Start the web server

That should allow the config database to be properly created in a
location that the webserver can access, and ensure the sessions,
storage and logs are similarly accessible.

--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


Re: Setting up pgAdmin4 as a web application

From
Dave Page
Date:
[Please keep the mailing list CC'd]

On Wed, Oct 19, 2016 at 3:32 PM, Derek Ealy <dealy663@gmail.com> wrote:
> I had already tried something similar and it didn't work.
>
> I moved my stuff out of /var/www/.pgadmin to the directory locations you
> suggested and set ownership to the www-data user and group. After restarting
> apache I get exactly the same error message as before. The pgadmin4.db file
> is created in /var/lib/pgadmin4 and is set to: -rw-r--r--  1 www-data
> www-data    0 Oct 19 07:25 pgadmin4.db. However the file remains at zero
> bytes. So there are enough permissions to create all of the files in the
> specified directories. But something is still preventing the actual writing
> to the DB file.
>
> Is there some way that the pgadmin python logic could be running as a
> different user than the apache http process?

Nothing in our code.

You could try the following:

1) Delete pgadmin4.db
2) Run setup.py as root
3) If that appears successful, "chown www-data:www-data pgadmin4.db"
4) See if it works

If not, please send a copy of your config files, and any logs or
screen output that may be relevant.

Thanks.

--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


Re: Setting up pgAdmin4 as a web application

From
dealy663
Date:
Ok, I'll give that a try.

I have my python setup to use a virtual environment. Could that be causing
the problems I'm having? I was able to get the venv setup with pgAdmin4
working on my workstation and thought that was the right way to set things
up on the server.



--
View this message in context:
http://postgresql.nabble.com/Setting-up-pgAdmin4-as-a-web-application-tp5926369p5926569.html
Sent from the PostgreSQL - pgadmin hackers mailing list archive at Nabble.com.


Re: Setting up pgAdmin4 as a web application

From
Dave Page
Date:
On Wed, Oct 19, 2016 at 3:43 PM, dealy663 <dealy663@gmail.com> wrote:
> Ok, I'll give that a try.
>
> I have my python setup to use a virtual environment. Could that be causing
> the problems I'm having? I was able to get the venv setup with pgAdmin4
> working on my workstation and thought that was the right way to set things
> up on the server.

I haven't tried it in a venv on a server (though my dev environment is
setup that way). It should work, but you may need to adjust the wsgi
file or Apache config to point to the virtual env.

--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


Re: Setting up pgAdmin4 as a web application

From
Murtuza Zabuawala
Date:
You can refer my config for activating virtual environment.

--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


On Wed, Oct 19, 2016 at 8:19 PM, Dave Page <dpage@pgadmin.org> wrote:
On Wed, Oct 19, 2016 at 3:43 PM, dealy663 <dealy663@gmail.com> wrote:
> Ok, I'll give that a try.
>
> I have my python setup to use a virtual environment. Could that be causing
> the problems I'm having? I was able to get the venv setup with pgAdmin4
> working on my workstation and thought that was the right way to set things
> up on the server.

I haven't tried it in a venv on a server (though my dev environment is
setup that way). It should work, but you may need to adjust the wsgi
file or Apache config to point to the virtual env.

--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


--
Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers

Re: Setting up pgAdmin4 as a web application

From
Dave Page
Date:
On Wed, Oct 19, 2016 at 4:01 PM, Murtuza Zabuawala
<murtuza.zabuawala@enterprisedb.com> wrote:
> You can refer my config for activating virtual environment.
> http://i.stack.imgur.com/8HbKw.png

That's your replacement wsgi file?

I wonder if we should source a user-editable file from our standard
WSGI file to allow the user to easily specify a virtual env to
activate. Thoughts?

--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company