Share on Social Media

In this guide, you will learn how to configure FastCGI Server on CentOS 7 by using Nginx web server. #centlinux #linux #nginx

What is Perl? :

Perl is a famous scripting language. It is mostly used to write scripts for Linux operating systems. Usually, Perl is not used for web development, however, there are situations in which, we have to host Perl scripts on a web server. Although Apache HTTP server has good native support for Perl language with straight forward configurations. But, we are using Nginx web server in this tutorial with Perl-FastCGI.

What is Nginx? :

Nginx web server does not has native support for Perl language. Therefore, we have to use a Perl-FastCGI process manager to add the Perl language support in our Nginx web server.

In this article, we will configure FastCGI Server on CentOS 7 by using Nginx web server and the add Perl-FastCGI support using spawn-fcgi package.

Reading Advise:

Environment Specification:

We have provisioned a CentOS 7 minimal install virtual machine with following specifications.

  • CPU – 3.4 Ghz (2 Cores)
  • Memory – 2 GB
  • Storage – 20 GB
  • Operating System – CentOS 7.6
  • Hostname –
  • IP Address – /24

Install Nginx on CentOS 7:

Connect with using ssh as root user.

Nginx is not available in standard yum repositories, therefore, we are installing EPEL (Extra Packages for Enterprise Linux) yum repository.

# yum install -y epel-release

Build cache for EPEL yum repository.

# yum makecache fast
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                     | 6.9 kB     00:00
 * base:
 * epel:
 * extras:
 * updates:
base                                                     | 3.6 kB     00:00
epel                                                     | 5.4 kB     00:00
extras                                                   | 3.4 kB     00:00
updates                                                  | 3.4 kB     00:00
(1/3): epel/x86_64/group_gz                                |  88 kB   00:03
(2/3): epel/x86_64/updateinfo                              | 998 kB   00:07
(3/3): epel/x86_64/primary_db                              | 6.8 MB   01:07
Metadata Cache Created

Install Nginx web server using yum command.

# yum install -y nginx

Enable and start nginx service.

# systemctl enable --now nginx.service
Created symlink from /etc/systemd/system/ to /usr/lib/systemd/system/nginx.service.

Configure Linux Firewall:

Allow HTTP service in Linux firewall.

# firewall-cmd --permanent --add-service=http
# firewall-cmd --reload

Browse URL using a client’s browser.

Nginx Default Homepage

Nginx web server has been installed on CentOS 7.

Configure FastCGI Server on CentOS 7:

Unlike Apache HTTP Server, Nginx do not spawn FastCGI processes. Therefore, we required to install spawn-fcgi to process Perl scripts.

# yum install -y spawn-fcgi

Now install fcgiwrap package using yum command.

# yum install -y fcgiwrap

Edit spawn-fcgi configuration file.

# vi /etc/sysconfig/spawn-fcgi

and add following line therein.

OPTIONS="-u nginx -g nginx -a -p 9001 -P /var/run/ -- /usr/sbin/fcgiwrap"

Enable and start spawn-fcgi service.

# systemctl enable --now spawn-fcgi
spawn-fcgi.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig spawn-fcgi on

Create a directory as Nginx document root.

# mkdir /var/www

Create a sample Perl script in Nginx document root directory.

# vi /usr/share/nginx/html/index.cgi

and add following lines of code.


print "Content-type: text/htmlnn";
print "<html><body><h1>Hello World!";
print "</h1></body></html>n";

Adjust file permissions for index.cgi.

# chmod +x /usr/share/nginx/html/index.cgi

Add our Nginx server configuration file as follows.

# vi /etc/nginx/default.d/default.conf

and add following directive therein.

index index.cgi;

location ~* .(pl|cgi)$ {
  gzip off;
  include /etc/nginx/fastcgi_params;
  fastcgi_index  index.cgi;

Restart nginx service.

# systemctl restart nginx

Set SELinux boolean, so the Nginx can communicate to spawn-fcgi.

# setsebool -P httpd_can_network_connect on

Browse URL in a client’s browser.

Nginx Hello World Page

Our Perl script has been executed successfully. We have successfully configure FastCGI Server using Nginx on CentOS 7.


In this guide, you have learned, how to configure FastCGI Server on CentOS 7 by using Nginx.

Leave a Reply

Your email address will not be published. Required fields are marked *