首先宝塔面板应用商店里面是没有perl组件的,我们需要在运行后台终端里面自行下载安装
我以Centos nginx为例
yum -y install fcgi-devel spawn-fcgi
yum -y install fcgiwrap spawn-fcgi
首先安装必要的组件
下载 fcgiwrap
git clone https://github.com/gnosek/fcgiwrap.git
cd fcgiwrap
autoconf -i
./configure
make
make install
等待编译完成
启动fastcgi-wrapper。可以任意选择一个空闲的端口,需要在宝塔面板放开端口。注意根据实际情况更改fcgiwrap的路径。
| spawn-fcgi -f /usr/local/sbin/fcgiwrap -p 8050 |
在宝塔面板里面找到你要配置的网站,参考下图

location ~ .*\.cgi$ {
fastcgi_pass 127.0.0.1:8050;
include fastcgi.conf;
}
fastcgi-wrapper开机自启动
fcgiwrap一定要处于开启状态。为了保证服务器重启之后cgi还能正常访问,需要添加开机自启动。这里选择使用systemd来完成。新增文件/lib/systemd/system/fcgi.service,并在文件写入以下内容,保存退出。
vi /lib/systemd/system/fcgi.service
[Unit]
Description=fastcgi-wrapper
After=network.target
Conflicts=shutdown.target
[Service]
Type=forking
User=root
Group=root
Restart=always
RestartSec=1
ExecStart=/usr/bin/spawn-fcgi -f /usr/local/sbin/fcgiwrap -p 8050
[Install]
WantedBy=multi-user.target
wq!保存退出
然后就可以使用systemctl来管理fcgi服务了。
# 开机自启动
systemctl enable fcgi
# 手动启动
systemctl start fcgi
# 停止服务
systemctl stop fcgi
# 查看服务状态
systemctl status fcgi
宝塔面板安装Perl,支持cgi pl 程序运行:等您坐沙发呢!