FastDo是一个强大的C++跨平台开发库,能助您快速的开发服务端程序,Web应用及网页。
让FastDo作为Web开发工具安装,您需要做的是让系统找到FastDo的库文件和程序文件,并且配置WebServer软件以HTTP反向代理的方式与FastDo常驻程序通信 ,然后启动FastDo常驻程序,最后从浏览器运行网页。
由于目前HTTP方式的服务端程序webx_httpserv是实验探索性质的功能,稳定性暂时无法保证。如果您需要稳定运行,请使用FastCGI形式的服务。
1、解压下载到的fastdo-<OS>-<ARCH>-<VERSION>.tar.gz到你的目录。
cd
sudo tar -zxf fastdo-OS-ARCH-VERSION.tar.gz
会在释放出fastdo文件夹,路径为/fastdo。
2、为了能让系统找到fastdo的动态库,需要修改系统的一些配置文件。
新建一个内容为
/fastdo/lib的文本文件
fastdolib.conf到/etc/ld.so.conf.d目录之中,并执行ldconfig命令。
cd /etc/ld.so.conf.d sudo vi fastdolib.conf sudo ldconfig
执行完此步之后,您Linux任何目录下的可执行文件都能找到fastdo的动态库了。
3、为了能让系统找到fastdo的程序,需要把fastdo的程序目录加入PATH环境变量。
编辑/etc/profile或~/.bashrc文件。
sudo vi /etc/profile 或 sudo vi ~/.bashrc
在文件内容末尾添加下面内容:
export PATH=$PATH:/fastdo/bin
然后执行命令source /etc/profile,或source ~/.bashrc让变量生效。重启系统也可以。
sudo source /etc/profile 或 sudo source ~/.bashrc
执行完此步之后,您在Linux任何目录下都能执行fastdo的程序了。
4、执行ecpc命令判断FastDo是否安装成功。
ecpc
如果成功,则显示如下:
Arguments not enough! Usage: ecpc $InputFile1[ $InputFile2[ $InputFile3[ ...]]] [--exe] [--help] [-c $SourceFile] [-t $SourceTpl] [-o $Output] [-p $Config] ……
还记得[作为C++库安装]里编译baidu_homepage.cpp的那一长串命令吗?
g++ --std=c++0x baidu_homepage.cpp -o baidu_homepage -lwinux -leiennet -lhttpwrapper -L/fastdo/lib
现在我们不用那么长的命令了,改为:
ecpc baidu_homepage.cpp --exe
即可。
5、安装WebServer软件。
FastDo在Linux上指定使用nginx这个WebServer软件。配置简单,并且功能也强大。
其他WebServer也不是不支持,只是具体配置方法这里就不提供了,欢迎您来提供。
下面列举一些Linux发行版安装nginx的命令:
| Linux | 命令 |
|---|---|
| CentOS RedHat系 |
sudo yum install epel-release -ysudo yum install nginx -y
|
| Ubuntu Debian系 |
sudo apt install nginx -y
|
| Manjaro Arch系 |
没有热心用户提供 |
6、以HTTP反向代理的方式使用FastDo,配置WebServer软件。
这里仅介绍通过Linux软件包管理器安装的nginx的配置方法。
您可以在/etc/nginx/找到nginx的配置文件。
在CentOS中通过yum安装完nginx后,缺省的网站配置在/etc/nginx/conf.d/default.conf。内容大致如下:
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
您可以修改default.conf,也可以在conf.d中增加一个*.conf文件。内容参考如下:
server {
listen 80;
server_name ;
charset utf-8;
access_log /var/log/nginx/example.com/access.log;
error_log /var/log/nginx/example.com/error.log warn;
root /usr/share/nginx/example.com;
location / {
index index.html index.do;
}
location ~ \.do$ {
proxy_pass http://127.0.0.1:18080;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Connection $http_connection;
}
location ~ .*\.(ecp|cpp|db|sqlite|tpl|conf)$ {
deny all;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
您可以将/usr/share/nginx更改为您觉得合适的目录,文本框内的内容也改成您自己的域名即可。
配置完毕,要确保/usr/share/nginx/example.com、/var/log/nginx/example.com等目录存在并有权限,重启nginx。
CentOS 7:
sudo systemctl stop nginx sudo systemctl start nginx
在Ubuntu中通过apt安装完nginx后,缺省的网站配置在/etc/nginx/sites-enabled/default。内容大致如下:
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
# fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
您可以修改`Default server configuration`,也可以增加一个`Virtual Host configuration`。内容参考如下:
server {
listen 80;
server_name ;
charset utf-8;
access_log /var/log/nginx/example.com/access.log;
error_log /var/log/nginx/example.com/error.log warn;
root /var/www/example.com;
location / {
index index.html index.do;
}
location ~ \.do$ {
proxy_pass http://127.0.0.1:18080;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Connection $http_connection;
}
location ~ .*\.(ecp|cpp|db|sqlite|tpl|conf)$ {
deny all;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
文本框内的内容改成您自己的域名即可。
配置完毕,要确保/var/www/example.com、/var/log/nginx/example.com等目录存在并有权限,重启nginx。
sudo systemctl stop nginx sudo systemctl start nginx
没有热心用户提供
7、启动webx_httpserv程序。
/fastdo/bin/webx_httpserv
webx_httpserv有自己的配置文件/fastdo/bin/webx_httpserv.settings,你可以修改它。(注意:文档根目录默认是工作目录,你应该修改它为你自己合适的目录。)
# $ExeDirPath是外部变量,表示程序目录路径
# $WorkDirPath是外部变量,表示工作目录路径
# 是否以产品模式运行
ProductionMode no;
# Sessions 保存路径
SessionsPath ($ExeDirPath + '/sessions');
# application/x-www-form-urlencoded 表单POST发送数据的最大大小
MaxUrlencodedPostSize 8388608;
# multipart/form-data 多部分表单POST发送数据的最大大小
MaxMultiFormPostSize 10485760;
# 上传的临时目录
UploadTmpPath ($ExeDirPath + '/upload-tmp');
# appserv输出信息用的模板路径
OutputTplPath ($ExeDirPath + '/output-tpl');
server {
# 服务器名,可留空
server_name localhost;
# 服务器IP,可留空
server_ip ;
# 服务器监听端口
server_port 18080;
# 监听积压数
listen_backlog 10;
# 线程数
thread_count 6;
# 服务器IO等待间隔时间(小数秒)
server_wait 0.02;
# verbose信息刷新间隔(小数秒)
verbose_interval 0.1;
# 显示冗长信息
verbose 0;
# 连接重试次数
retry_count 10;
# 套接字超时时间(整数秒)
sock_timeout 300;
# 影响环境变量:TZ,putenv()设置的时区
time_zone PRC-8;
}
site {
# 文档根目录
document_root ($WorkDirPath);
# 文档首页
document_index index.html index.do;
# 错误页
error_pages {
404 ($WorkDirPath + '/404.html');
}
# 静态文件缓存生命期
cache_lifetime 0;
}
8、您应该可以从浏览器运行*.do文件了。
A. 在您的网站根目录新建一个hello.ecp,内容如下:
<?cpp
RSP.setCharset("utf-8");
RSP << "Hello world!";
B. 执行ecpc编译它。
ecpc hello.ecp
执行成功会产生hello.do文件,在浏览器地址栏中输入它的URL,回车。会输出Hello world!。