如何在我的本地Apache服务器中显示我的Wt应用程序?

时间:2017-06-18 20:17:24

标签: c++ apache wt

我对Wt和cgi很新。我想要做的是用C ++编写一个Web应用程序。这可以归功于Wt库:

https://www.webtoolkit.eu/wt

显然有两种模式:http和fastcgi。前者很容易使用:我编译我的代码并运行bin。这启动了某种类型的Web服务器(我的词汇表可能不太准确,因为我是这个域中的一个大菜鸟)并输出服务器的地址和端口。在我最喜欢的浏览器中键入所有内容会导致显示我用C ++编写的网页。

后者存在很大问题,这非常烦人,因为这是在托管远程服务器上部署软件的唯一方法。

为了部署测试Web服务器,我在Wt库中找到了hello示例,并通过定义cmake变量EXAMPLES_CONNECTOR = wtfcgi将其与wtfcgi链接。

之后,我安装了apache2并进行了设置。我做了以下事情:

我安装了以下Ubuntu软件包:

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

然后,

  1. 使用a2enmod
  2. 为Apache启用mod_fastcgi
  3. 像这样修改配置文件fastcgi.conf:
  4. <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. 为wt应用程序创建一个新的站点配置文件,/ etc / apache2 / sites -available / wt.conf:
    2. <Directory /var/www/wt/> Allow from all Options +ExecCGI </Directory>

      1. 将我的Wt示例代码复制到文件夹/var/www/wt/hello.wt

      2. 启用网站并重新加载apache

      3. a2ensite wt service apache2 reload

        然后,在那之后,/ var / log / apache2 / error.log给了我

        [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"
        

        之后,我按照本网页提供的建议:

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

        例如,我自己创建了/ var / run / wt并将其所有者更改为www-data。然后我得到了这个日志:

        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"
        

        然后看起来很好。但是,当我现在在我的firefox浏览器上显示地址127.0.1.1时,我仍然看到默认的apache2网页。为什么我没有看到你好的例子?我该如何解决?我是否必须编写一个调用hello.wt的特殊html页面?这有什么作用?

        似乎某些事情已经开始,但并没有继续运行。我在哪里可以找到它的日志?

        提前致谢!

1 个答案:

答案 0 :(得分:1)

我设法通过以下方式使其发挥作用:

  1. 确保文件夹/ var / www / html存在并将我的wt应用程序复制到那里

  2. 像这样修改配置文件fastcgi.conf:

  3. <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. 删除wt应用程序的站点配置文件:

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

    2. 因为它对过程没有影响

      1. 重新加载apache

        service apache2 reload

      2. 现在,当我输入地址

        localhost/hello.wt
        

        在我的浏览器中,我可以看到显示的示例,假设

        /var/run/wt
        

        可以由www-data用户创建。