1. Knowledge Base
  2. >
  3. Results
  4. >
  5. Perl and Python Scripts

Perl and Python Scripts

 

Python and Perl are interpreter-based, high-level, and general-purpose scripting languages. Both are used to set a system and its interfaces together. 

Perl and Python, what are their differences?

While Perl was initially created to simplify the process of making reports, Python is used to simplify the code writing process using logical and simple code. Both Perl and Python are used for small- and large-scale applications and projects.

What are the file extensions for Perl and Python?

Perl

.pl

Python

.py

Both of these scripts must have 755 permissions.

Perl and Python scripts examples

Disclaimer: Please note that the scripts below are only examples, and we cannot guarantee that these scripts will work, nor can we assist with custom configurations of such scripts.

Perl Script

#!/usr/bin/perl -w   

print "Content-type: text/html\n\n";   

print "<html><head>"; 

print "<title>CGI Test</title>";   

print "</head><body>";   

print "<p>Test page using Perl</p>";   

print "</body></html>"; 

Python Script

#!/usr/bin/python   

print "Content-type: text/html\n\n";   

print "<html><head>"; 

print "<title>CGI Test</title>";   

print "</head><body>"; 

print "<p>Test page using Python</p>";   

print "</body></html>";
The following steps are only applicable to VPS/Dedicated hosting customers that have configured in the Compiler group for the server. If a user wants to use python 3.x on a Shared server, they will be limited to the use of 3.5 and will need to use the SCL method to enable it.

Downloading Python

Download and extract the latest Python version (3.10.5) to your server by running the command below.

mkdir ~/python   

cd ~/python   

wget https://www.python.org/ftp/python/3.10.5/Python-3.10.5.tgz

tar zxfv Python-3.10.5.tgz   

find ~/python -type d | xargs chmod 0755   

cd Python-3.10.5

Installing Python

Run the following commands to configure and install Python once Python has been extracted to your server.

./configure --prefix=$HOME/python   

make   

make install   

Activating Python

Please note that you have to add a line in the .htaccess file to use Python.

The recommended directive is:

Addhandler cgi-script .py .pl .cgi 

(This directive covers Perl, Python, and CGI files.)

Modifying the .bashrc

In order for Python's local version to load, add the following codes to the .bashrc file:

vim ~/.bashrc

Press i.

Enter:

export PATH=$HOME/python/Python-3.9.2/:$PATH   

Write the changes by pressing ESC and then close the vim:

:wq 

Press Enter.

source ~/.bashrc
Note: For the environment to update, you need to log out. To check the version of python installed, enter python -V.

Getting a 500 Internal Server error?

If you are getting a 500 Internal Server Error, it is most likely caused by the lack of executable permissions. Check to make sure your Perl or Python script file has permissions of 755.