Subject: pgAdmin 4 as Web application

From: Albe Laurenz <[email-masked]>
Date: Mon, 8 Aug 2016 15:07:25 +0000

I'm trying to follow
https://www.pgadmin.org/docs4/dev/server_deployment.html
to install pgAdmin 4 as web application on RHEL 6, but I didn't get very far:

There is no file "pgAdmin4.wsgi" available for download.
Did I miss something obvious?

So I tried to build from source, and failed immediately with

laurenz:~/rpmbuild/pgadmin4-1.0-beta3/runtime> qmake-qt4
Project MESSAGE: Building for QT4...
Project MESSAGE: Building for Linux/Mac...
Project MESSAGE: Using /usr/bin/python-config
Project MESSAGE: Python2 detected.

laurenz:~/rpmbuild/pgadmin4-1.0-beta3/runtime> make
g++ -c -m64 -pipe -I/usr/include/python2.6 -I/usr/include/python2.6 -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wall -W -D_REENTRANT -DPYTHON2 -DQT_NO_DEBUG -DQT_WEBKIT_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I/usr/lib64/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/QtCore -I/usr/include/QtNetwork -I/usr/include/QtGui -I/usr/include/QtWebKit -I/usr/include -I. -I. -o pgAdmin4.o pgAdmin4.cpp
In file included from TabWindow.h:16,
                 from BrowserWindow.h:16,
                 from pgAdmin4.cpp:28:
WebViewWindow.h:20:20: error: QWebView: No such file or directory
In file included from TabWindow.h:16,
                 from BrowserWindow.h:16,
                 from pgAdmin4.cpp:28:
WebViewWindow.h:24: error: expected class-name before ‘{’ token
make: *** [pgAdmin4.o] Error 1

I searched the web, but could not find any answers how to install
Qt Webkit on RHEL 6.

Can you help?

Yours,
Laurenz Albe

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

---

From: Neel Patel <[email-masked]>
Date: Mon, 8 Aug 2016 21:32:01 +0530

Hi,

---

From: Dave Page <[email-masked]>
Date: Mon, 8 Aug 2016 17:10:10 +0100

> Did I miss something obvious?

Hmm, no - looks like we did. I know people have been testing in web
mode, so I wonder how this got missed!

I don't have time to test right now, but I believe something like the
following one liner should suffice as your wsgi file:

from pgAdmin4 import app as application

Make sure that's in the same directory as pgAdmin4.py (the web/
directory in the source tree), then point your Apache config to it.

If you need any further quick hints (I'm going offline for the rest of
the day in a minute), this may help:
http://flask.pocoo.org/docs/0.11/deploying/mod_wsgi/ - but do pay
close attention to the comments on threads/prcesses in the pgAdmin
docs.

Please let me know if it works.

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

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

---

From: Albe Laurenz <[email-masked]>
Date: Tue, 9 Aug 2016 12:39:40 +0000

> From the logs, it looks like - Qt webkit component is missing in Qt4 installation.
> Are you building Qt from source, If yes then there will be option in configure script to build Qt4
> with webkit.
> If you are not using source code, try installing webkit with yum (e.g. yum install libqt4-webkit).

I found an appropriate RPM somewhere, now I have a different problem.

I am building with Qt 4.6.2 from RHEL 6, which should be OK according to the README,
but I am failing with

g++ -c -m64 -pipe -I/usr/include/python2.6 -I/usr/include/python2.6 -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wall -W -D_REENTRANT -DPYTHON2 -DQT_NO_DEBUG -DQT_WEBKIT_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I/usr/lib64/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/QtCore -I/usr/include/QtNetwork -I/usr/include/QtGui -I/usr/include/QtWebKit -I/usr/include -I. -I. -o BrowserWindow.o BrowserWindow.cpp
BrowserWindow.cpp: In member function ‘void BrowserWindow::unsupportedContent(QNetworkReply*)’:
BrowserWindow.cpp:446: error: ‘QUrlQuery’ was not declared in this scope
BrowserWindow.cpp:446: error: expected ‘;’ before ‘query_data’
BrowserWindow.cpp:447: error: ‘query_data’ was not declared in this scope
BrowserWindow.cpp: In member function ‘bool BrowserWindow::checkClientDownload(const QUrl&, const QNetworkRequest&)’:
BrowserWindow.cpp:681: error: ‘QUrlQuery’ was not declared in this scope
BrowserWindow.cpp:681: error: expected ‘;’ before ‘downloadData’
BrowserWindow.cpp:683: error: ‘downloadData’ was not declared in this scope
make: *** [BrowserWindow.o] Error 1

The code uses QUrlQuery, but according to http://doc.qt.io/qt-5/qurlquery.html
this class has existed only since 5.0.

Seems to be either a documentation bug (Qt 5 required) or a code bug.
Can you help?

Yours,
Laurenz Albe

---

From: Neel Patel <[email-masked]>
Date: Tue, 9 Aug 2016 18:35:44 +0530

Hi,

We already have condition for QUrlQuery class as below. It will be used
only if Qt version is >= 5.0.

#if QT_VERSION >= 0x050000
    // Extract filename and query from encoded URL
    QUrlQuery query_data(reply->url());
    QString file_name = query_data.queryItemValue("filename");
    QString query = query_data.queryItemValue("query");
#else
    QUrl url(reply->url());
    QString file_name = url.queryItemValue("filename");
    QString query = url.queryItemValue("query");
#endif

In your case, it may possible that during qmake - Qt version is detected as
5 but you are compiling against Qt 4 so application is not able to find the
QUrlQuery class.

Can you please share console log and Makefile when you run the qmake
command with project file ?

Thanks,
Neel Patel

On Tue, Aug 9, 2016 at 6:09 PM, Albe Laurenz <[email-masked]>
wrote:

> g++ -c -m64 -pipe -I/usr/include/python2.6 -I/usr/include/python2.6 -O2 -g
> -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector
> --param=ssp-buffer-size=4 -m64 -mtune=generic -Wall -W -D_REENTRANT
> -DPYTHON2 -DQT_NO_DEBUG -DQT_WEBKIT_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB
> -DQT_CORE_LIB -I/usr/lib64/qt4/mkspecs/linux-g++-64 -I.
> -I/usr/include/QtCore -I/usr/include/QtNetwork -I/usr/include/QtGui
> -I/usr/include/QtWebKit -I/usr/include -I. -I. -o BrowserWindow.o
> BrowserWindow.cpp

---

From: Albe Laurenz <[email-masked]>
Date: Tue, 9 Aug 2016 13:51:14 +0000

Neel Patel wrote:
> We already have condition for QUrlQuery class as below. It will be used only if Qt version is >= 5.0.
> 

Oh, I see now, thank you for the help.
I was missing commit dcf5bfc495bea1d5b28c389335cbd89e73468aaa (I downloaded
the pgadmin4-1.0-beta3 source).

After editing the file, I can build it, but when starting "pgadmin4" I get

Full Python path:  ""
User Python path:  ""
Webapp path:  "/MYSQL/mysqldata/fs1/rpmbuild/pgadmin4-1.0-beta3/web/pgAdmin4.py"
Traceback (most recent call last):
  File "/MYSQL/mysqldata/fs1/rpmbuild/pgadmin4-1.0-beta3/web/pgAdmin4.py", line 24, in <module>
    from pgadmin import create_app
  File "/MYSQL/mysqldata/fs1/rpmbuild/pgadmin4-1.0-beta3/web/pgadmin/__init__.py", line 281
    arch_keys = {0}
                  ^
SyntaxError: invalid syntax

The same happens when I try to start it as web application.

My system has
Python 2.6.6
Qt 4.6.2
Apache httpd 2.2.15

What could be the problem?

Yours,
Laurenz Albe

---

From: Albe Laurenz <[email-masked]>
Date: Wed, 10 Aug 2016 07:28:00 +0000

> Please let me know if it works.

Thanks, that was very helpful indeed.

I had to put more stuff into the wsgi file, probably because my installation
is in some nonstandard location:

   import sys
   sys.path.insert(0, '/home/laurenz/rpmbuild/pgadmin4-1.0-beta3/web')
   from pgAdmin4 import app as application

Now I'm getting to the same error as with the standalone version, see
https://www.postgresql.org/message-id/A737B7A37273E048B164557ADEF4A58B5388C035%40ntex2010i.host.magwien.gv.at

It would be good to improve the documentation for "Server deployment".
It should be mentioned that you don't need the binaries for that, and that
the "web" subdirectory contains all you need.

---

From: Ashesh Vashi <[email-masked]>
Date: Wed, 10 Aug 2016 13:20:46 +0530

On Wed, Aug 10, 2016 at 12:58 PM, Albe Laurenz <[email-masked]>
wrote:

> https://www.postgresql.org/message-id/A737B7A37273E048B164557ADEF4A5
> 8B5388C035%40ntex2010i.host.magwien.gv.at

Looks like the Python 2.6 compatibility has been broken.

For now - can you use Python 2.7/3?

--

Thanks & Regards,

Ashesh Vashi
EnterpriseDB INDIA: Enterprise PostgreSQL Company
<http://www.enterprisedb.com/>

*http://www.linkedin.com/in/asheshvashi*
<http://www.linkedin.com/in/asheshvashi>

---

From: Albe Laurenz <[email-masked]>
Date: Fri, 2 Sep 2016 12:45:24 +0000

Ashesh Vashi wrote:
>> https://www.postgresql.org/message-

> For now - can you use Python 2.7/3?

I tried again on a RHEL 7 machine with Python 2.7.5 and the
latest development version of pgAdmin4.

Now I get the following error:

mod_wsgi (pid=20880): Target WSGI script '/opt/pgadmin4/pgAdmin4.wsgi' cannot be loaded as Python module.
mod_wsgi (pid=20880): Exception occurred processing WSGI script '/opt/pgadmin4/pgAdmin4.wsgi'.
Traceback (most recent call last):
  File "/opt/pgadmin4/pgAdmin4.wsgi", line 8, in <module>
    from pgAdmin4 import app as application
  File "/opt/pgadmin4/pgAdmin4.py", line 58, in <module>
    app = create_app()
  File "/opt/pgadmin4/pgadmin/__init__.py", line 204, in create_app
    import pgadmin.utils.paths as paths
AttributeError: 'module' object has no attribute 'paths'

Indeed there is no pgadmin/utils/paths directory with a __init__.py in it.

Yours,
Laurenz Albe

---

From: Dave Page <[email-masked]>
Date: Fri, 2 Sep 2016 15:15:27 +0100

> Indeed there is no pgadmin/utils/paths directory with a __init__.py in it.

No, but there should be a pgadmin/utils/paths.py file. Is that there?

FYI, I'm running a test server on CentOS 7 - my Apache config looks like this:

    WSGIDaemonProcess pgadmin processes=1 threads=25
    WSGIScriptAlias /pgadmin4 /opt/pgAdmin4/web/pgAdmin4.wsgi

    <Directory /opt/pgAdmin4/web>
        WSGIProcessGroup pgadmin
        WSGIApplicationGroup %{GLOBAL}
        Require all granted
    </Directory>

That's working with the pgAdmin4.wsgi file unmodified from git.

---

From: Albe Laurenz <[email-masked]>
Date: Mon, 5 Sep 2016 07:08:35 +0000

> No, but there should be a pgadmin/utils/paths.py file. Is that there?

Yes, there is, and it is readable to everyone.

I don't know much about Python - could it be that version 2.7 handles this
line differently from 3?

I'll see what I can find out with strace.

> That's working with the pgAdmin4.wsgi file unmodified from git.

Mine looks the same (except for the paths and a ServerName directive).

I think it's a Python problem rather than a web server problem.

Thanks for your help!
I really want to get it running so I and my co-workers can test.

Yours,
Laurenz Albe

---

From: Dave Page <[email-masked]>
Date: Mon, 5 Sep 2016 09:30:05 +0100

> I don't know much about Python - could it be that version 2.7 handles this

No - I do all my development on 2.7 and it works fine (as do most of
the other devs I believe). 3.x is definitely less well tested, and 2.6
is behind that.

Ashesh, any ideas what could be causing this?

> I'll see what I can find out with strace.

Thanks.

---

From: Albe Laurenz <[email-masked]>
Date: Mon, 5 Sep 2016 14:45:34 +0000

> Ashesh, any ideas what could be causing this?

Must have been something weird; a web server restart fixed the problem.

Thanks for the help; it is working now.

I'm kind of surprised that pgAdmin4 is already a release candidate, I still
find lots of bugs just randomly clicking around.
I'll report them of course.

Yours,
Laurenz Albe

---

From: Ashesh Vashi <[email-masked]>
Date: Mon, 5 Sep 2016 20:31:28 +0530

On Mon, Sep 5, 2016 at 8:15 PM, Albe Laurenz <[email-masked]>
wrote:

> Dave Page wrote:
> >>>> mod_wsgi (pid=20880): Target WSGI script
> '/opt/pgadmin4/pgAdmin4.wsgi' cannot be loaded as Python module.
I can think of existing .pyc files, which can cause this kind of problems.

--

Thanks & Regards,

Ashesh Vashi