c++apachewt

How to display my Wt application in my local apache server?


I am very new to Wt and cgi stuff. What I am trying to do is write a web application in C++. This is possible thanks to the Wt library:

https://www.webtoolkit.eu/wt

Apparently there are two modes: http and fastcgi. The former is straightforward to use: I compile my code and run the bin. This starts some kind of web server (my vocabulary is probably not exact, as I am a big noob in this domain) and outputs the server's address and port. Typing all that in my favorite browser results in displaying the web page that I coded in C++.

I have a big problem with the latter and this is very annoying because this is the only way to deploy the software on a hosted remote server.

To deploy a test web server, I took the hello example found in the Wt library and linked it against wtfcgi by defining the cmake variable EXAMPLES_CONNECTOR=wtfcgi.

After that, I installed apache2 and set it up. I did the following:

I installed the following Ubuntu packages:

libapache2-mod-fastcgi
apache2
apache2-bin
apache2-data
apache2-utils

Then,

  1. enable mod_fastcgi for Apache with a2enmod
  2. modify the configuration file fastcgi.conf like this:

<IfModule mod_fastcgi.c>; AddHandler fastcgi-script .wt FastCgiIpcDir /var/lib/apache2/fastcgi FastCgiConfig -idle-timeout 100 -maxClassProcesses 1 -initial-env WT_APP_ROOT=/tmp FastCgiServer /var/www/wt/hello.wt </IfModule>

  1. create a new site configuration file for wt applications, /etc/apache2/sites-available/wt.conf:

<Directory /var/www/wt/> Allow from all Options +ExecCGI </Directory>

  1. copy my Wt example code into the folder /var/www/wt/hello.wt

  2. enable the site and reload apache

a2ensite wt service apache2 reload

Then, after that, the /var/log/apache2/error.log gave me

[Fri Jun 16 22:52:30.176846 2017] [core:notice] [pid 1676:tid 139808785006080] AH00094: Command line: '/usr/sbin/apache2'
[Fri Jun 16 22:52:30.177041 2017] [:warn] [pid 1678:tid 139808785006080] FastCGI: server "/var/www/wt/hello.wt" started (pid 1682)
[2017-Jun-16 22:52:30.328742] 1682 - [info] "WServer/wtfcgi: initializing relay server"
[2017-Jun-16 22:52:30.332011] 1682 - [info] "config: reading Wt config file: /etc/wt/wt_config.xml (location = '/var/www/wt/hello.wt')"
[2017-Jun-16 22:52:30.334308] 1682 - [info] "wtfcgi: spawned session process: pid = 1737"
[2017-Jun-16 22:52:30.334383] 1682 - [error] "wtfcgi: fatal: cannot create run directory '/var/run/wt'"
[Fri Jun 16 22:52:30.337635 2017] [:warn] [pid 1678:tid 139808785006080] FastCGI: server "/var/www/wt/hello.wt" (pid 1682) terminated by calling exit with status '1'
[2017-Jun-16 22:52:30.375392] 1737 - [info] "config: reading Wt config file: /etc/wt/wt_config.xml (location = '/var/www/wt/hello.wt')"
[2017-Jun-16 22:52:30.375519] 1737 - [info] "WServer/wtfcgi: initializing shared wtfcgi session process"
[2017-Jun-16 22:52:30.375708] 1737 - [error] "wtfcgi: fatal: bind(): No such file or directory"

After that, I followed the advice given in this web page:

http://redmine.webtoolkit.eu/projects/wt/wiki/Fastcgi_on_apache

For instance, I created the /var/run/wt myself and changed its owner to www-data. Then I got this log:

AH00112: Warning: DocumentRoot [/var/www/html] does not exist
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
[Fri Jun 16 23:15:53.355484 2017] [:notice] [pid 1994:tid 139719627398656] FastCGI: process manager initialized (pid 1994)
[Fri Jun 16 23:15:53.355544 2017] [mpm_event:notice] [pid 1656:tid 139719627398656] AH00489: Apache/2.4.18 (Ubuntu) mod_fastcgi/mod_fastcgi-SNAP-0910052141 configured -- resuming normal operations
[Fri Jun 16 23:15:53.355554 2017] [core:notice] [pid 1656:tid 139719627398656] AH00094: Command line: '/usr/sbin/apache2'
[Fri Jun 16 23:15:53.355676 2017] [:warn] [pid 1994:tid 139719627398656] FastCGI: server "/var/www/wt/hello.wt" started (pid 1995)
[2017-Jun-16 23:15:53.365485] 1995 - [info] "WServer/wtfcgi: initializing relay server"
[2017-Jun-16 23:15:53.365675] 1995 - [info] "config: reading Wt config file: /etc/wt/wt_config.xml (location = '/var/www/wt/hello.wt')"
[2017-Jun-16 23:15:53.365878] 1995 - [info] "wtfcgi: spawned session process: pid = 2052"
[2017-Jun-16 23:15:53.365942] 1995 - [info] "wtfcgi: reading FastCGI stream from stdin"
[2017-Jun-16 23:15:53.373121] 2052 - [info] "config: reading Wt config file: /etc/wt/wt_config.xml (location = '/var/www/wt/hello.wt')"
[2017-Jun-16 23:15:53.373243] 2052 - [info] "WServer/wtfcgi: initializing shared wtfcgi session process"

which then looks fine. However, when I now display the address 127.0.1.1 on my firefox browser, I still see the default apache2 webpage. Why don't I see the hello example? How do I fix this? Do I have to write a special html page that calls the hello.wt? How does that work?

It seems like something is started but doesn't keep running. Where can I find logs of that?

Thanks in advance!


Solution

  • I managed to make it work by doing the following:

    1. make sure the folder /var/www/html exists and copy my wt application there

    2. modify the configuration file fastcgi.conf like this:

    <IfModule mod_fastcgi.c> AddHandler fastcgi-script .wt FastCgiIpcDir /var/lib/apache2/fastcgi FastCgiConfig -idle-timeout 100 -maxClassProcesses 1 -initial-env WT_APP_ROOT=/tmp FastCgiServer /var/www/html/hello.wt </IfModule>

    1. get rid of the site configuration file for wt applications:

      /etc/apache2/sites-enabled/wt.conf

    because it has no effect on the process

    1. reload apache

      service apache2 reload

    Now, when I type the address

    localhost/hello.wt
    

    in my browser, I can see the example displayed, assuming

    /var/run/wt
    

    could be created by the www-data user.