FastDo是一个强大的C++跨平台开发库,能助您快速的开发服务端程序,Web应用及网页。
让FastDo作为Web开发工具安装,您需要做的是让系统找到FastDo的库文件和程序文件,并且配置WebServer软件以FastCGI的方式与FastDo常驻程序通信 ,然后启动FastDo常驻程序,最后从浏览器运行网页。
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、配置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.*$ {
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.do;
fastcgi_split_path_info ^(.+\.do)(/.*)$;
set $path_info $fastcgi_script_name$fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
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
CentOS 6:
sudo service nginx stop sudo service nginx start
在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.*$ {
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.do;
fastcgi_split_path_info ^(.+\.do)(/.*)$;
set $path_info $fastcgi_script_name$fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
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、安装fastdo为Linux服务,并启动它。或者手动运行spawn-fcgi启动fcgiserv进程。
A. 把/fastdo/bin/fastdo.service文件复制到/lib/systemd/system之中。
sudo cp /fastdo/bin/fastdo.service /lib/systemd/system
下面两条命令启用或者禁用fastdo.service:
启用:sudo systemctl enable fastdo.service
禁用:sudo systemctl disable fastdo.service
B. 执行启用服务的命令。
sudo systemctl enable fastdo.service
一旦启用了服务,那服务将在开机时自启动,但是我们这里不重启系统,所以需要手动启动。
下面两条命令启动或者停止fastdo服务:
启动:sudo systemctl start fastdo.service
停止:sudo systemctl stop fastdo.service
C. 执行启动服务的命令。
sudo systemctl start fastdo.service
您可以查看服务运行的状态:
sudo systemctl status fastdo.service
您可以查看所有安装的服务:
sudo systemctl list-unit-files
A. 把/fastdo/bin/fastdo文件复制到/etc/init.d之中,并让chkconfig程序管理它。
sudo cp /fastdo/bin/fastdo /etc/init.d sudo chkconfig --add fastdo
下面两条命令启用或者禁用fastdo:
启用:sudo chkconfig --level 2345 fastdo on
禁用:sudo chkconfig --level 2345 fastdo off
B. 执行启用服务的命令。
sudo chkconfig --level 2345 fastdo on
一旦启用了服务,那服务将在开机时自启动,但是我们这里不重启系统,所以需要手动启动。
下面两条命令启动或者停止fastdo服务:
启动:sudo service fastdo start
停止:sudo service fastdo stop
C. 执行启动服务的命令。
sudo service fastdo start
您可以查看所有安装的服务,已经启用状态:
sudo chkconfig --list
没有热心用户提供
直接运行spawn-fcgi启动fcgiserv:
/fastdo/bin/spawn-fcgi -a 127.0.0.1 -p 9001 -F 4 -f /fastdo/bin/fcgiserv
-a是监听的IP地址,-p是端口号,-F是子进程数,-f指示FCGI程序路径。
如果您要停止程序:
/fastdo/bin/spawn-manager exit 9001
exit表示退出spawn-fcgi以及全部的fcgiserv子进程。9001是spawn-fcgi启动时的端口号,用来指定操作的是哪一个spawn-fcgi进程群。
8、您应该可以从浏览器运行*.do文件了。
A. 在您的网站根目录新建一个hello.ecp,内容如下:
<?cpp
RSP.setCharset("utf-8");
cout << "Hello world!";
B. 执行ecpc编译它。
ecpc hello.ecp
执行成功会产生hello.do文件,在浏览器地址栏中输入它的URL,回车。会输出Hello world!。