How to install fcgiwrap for Nginx on Ubuntu 20.04
Fcgiwrap is a simple server used to run CGI applications via FastCGI. We can use it to provide clean CGI support for nginx webserver. Here's how to install fcgiwrap on Ubuntu 20.04.
Fcgiwrap is a simple server used to run CGI applications via FastCGI. We can use it to provide clean CGI support for nginx webserver. It is a lightweight server with zero configuration options, allowing to use the same group to run different websites. Here's how to install fcgiwrap on Ubuntu 20.04.
CGI (Common Gateway Interface) is the original method for creating dynamic websites. The instructions below assume that you have installed and configured the Nginx server on Ubuntu Linux 20.04 LTS.
Install fcgiwrap on Ubuntu 20.04
Open a terminal and enter the following commands to update security installed packages on Ubuntu 20.04:
$ sudo apt update $ sudo apt upgrade
To install fcgiwrap packages for Nginx, run the following command as root user with the help of [nixmcd name = 'apt']:
$ sudo apt install fcgiwrap
Enable fcgiwrap service on Ubuntu 20.04
Use the systemctl command as follows:
$ sudo systemctl enable fcgiwrap $ sudo systemctl start fcgiwrap $ sudo systemctl status fcgiwrap
Configure fcgiwrap for Nginx
Now we have fcgiwrap installed, followed by creating a new configuration for the FastCGI file:
sudo nano /etc/nginx/fcgiwrap.conf
Connect the following configurations:
location /cgi-bin/ { # Disable gzip (it makes scripts feel slower since they have to complete # before getting gzipped) gzip off; # Set the root to /usr/lib (inside this location this means that we are # giving access to the files under /usr/lib/cgi-bin) root /usr/lib; # Fastcgi socket fastcgi_pass unix:/var/run/fcgiwrap.socket; # Fastcgi parameters, include the standard ones include /etc/nginx/fastcgi_params; # Adjust non standard parameters (SCRIPT_FILENAME) fastcgi_param SCRIPT_FILENAME /usr/lib$fastcgi_script_name; }
Edit nginx.conf or virtual domain file. For example:
sudo nano /etc/nginx/nginx.conf ## OR ## sudo nano /etc/nginx/sites-enabled/default
Next, locate the server and add the following directive:
## Trun on /cgi-bin/ support to run CGI apps ## include /etc/nginx/fcgiwrap.conf;
Save and close the file. Reload or restart the Nginx server:
$ sudo nginx -t $ sudo nginx -s reload
Writing basic CGI scripts
Writing a basic CGI script using FastCGI is quite simple. First, we have to create a cgi-bin directory in / usr / lib / using the mkdir command:
$ sudo mkdir -vp /usr/lib/cgi-bin/ mkdir: created directory '/usr/lib/cgi-bin/'
Hello World CGI Script in Bash
Hello World - CGI appOpen a text editor and create the following file:
sudo vi /usr/lib/cgi-bin/hello.cgi
Append the following bash code:
#!/usr/bin/env bash echo "Content-type: text/html" echo "" now="06/07/2020" echo 'Hello World - CGI app' echo '' echo '
Hello World!
' echo "Computer name : $HOSTNAME
" echo "The current date and time : ${now}
" echo '' echo ''
Set execution rights on /usr/lib/cgi-bin/hello.cgi with chmod and chown:
$ sudo chmod +x -v /usr/lib/cgi-bin/hello.cgi mode of '/usr/lib/cgi-bin/hello.cgi' changed from 0644 (rw-r--r--) to 0755 (rwxr-xr-x)
Check by opening the web browser and entering the url:
https://your-domain-here/cgi-bin/hello.cgi ## For instance ## https://www.cyberciti.biz/cgi-bin/hello.cgi
You can write CGI applications or scripts in any programming language. CGI for applications / scripts can appear simple and easy, but to write those applications is not simple.
You should read it
- Compare the most popular Linux distributions today
- How to install Solus Linux
- 12 best Linux server operating systems
- Distinguish Ubuntu and Linux Mint
- 3 Linux mobile operating systems you can install today
- 10 reasons to switch to Linux right in 2012
- How to Install Ubuntu Linux
- Pop! _OS What is it? Is it like Ubuntu?
- Tips and tricks after installing Ubuntu
- How to create dual boot Linux and Windows 10 on Linux
- 10 things to keep in mind when switching to Linux mobile operating system
- How to Install Ubuntu Linux
Maybe you are interested
Tone E20, smartphone with AI integration to prevent nude photography The use of the Split tool separates the Excel data table MS Word - Lesson 7: Styles MS Word - Lesson 5: Format the text With only 36 questions, you can 'cut' anyone who even married after meeting 6 months 8 differences of successful people in the world