Whether the web server (eg Apache) runs on Linux or Windows, these scripts will be executed if they are in the cgi-bin directory.
The language used to write these scripts is Perl and they are executed with the Perl interpreter (in Windows: perl.exe). A Perl script has the .pl (or .cgi) extension, and the first line of code will point the path to the interpreter.
- For Linux:
- For Windows:
Perl (Practical Extraction and Reporting Language) is a programming language created in 1987, especially used for word processing, but it is now used in web applications and can interact with other programming languages.
Perl is a high-level language, meaning easy to understand by users, but hard to understand PCs. Using the interpreter, which is a program that converts high-level language, into a low-level language that the PC recognizes and can execute its instructions.
The major advantage is that Perl is extremely portable. It can run on any operating system that has the Perl interpreter installed.
If the Linux distribution does not have Perl preinstalled, open the Terminal and type:
sudo apt-get install perl
and the path to the interpreter, which will be the first instruction in any perl program, will be:
Perl can also be downloaded and installed in Windows:
But the easiest way to write and run Perl scripts is to use Xampp, which has the Apache (and other servers) web server installed and has already set up the Perl interpreter.
Xampp has a control panel from where to manage servers.
All we have to do is write a perl script, put it in the directory: cgi-bin and start the Apache server. Then we access it with the browser, the script is executed and the result will be displayed in the browser.
Let's test the simplest hello script. We write this script in a text editor, save it as: hello.pl and put it in the directory: cgi-bin.
To run it, we open the web browser and type:
The result in the browser will be:
Visit my websites:https://www.jwebsaints.com