What is Perl?
Perl is a programming language. A programming language is a way to give a computer a list of tasks. A script is a small program saved in a text file. Perl is old, but many websites and tools still use it. It is good at handling text.
Where Perl scripts run
Many hosting accounts can run Perl scripts. These scripts often live in a folder called cgi-bin. CGI is a way for a web server to run a program and show its result on a web page. Ask Hostvento support if Perl and CGI are on your plan.
Your first script
Open a plain text editor, such as Notepad. Type this code:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello, world!";
Here is what each line does:
- The first line tells the server where Perl lives. It is called the shebang line. The path can differ by server, so check with support.
- The second line tells the browser that the answer is a web page.
- The third line prints the words "Hello, world!".
Save the file as hello.pl.
Steps to run it
- Log in to your cPanel. You can find the link in your welcome email.
- Open File Manager.
- Go to the
public_htmlfolder. Opencgi-binif it exists. If not, make it with + Folder. - Click Upload and choose
hello.pl. - Right-click the file and choose Change Permissions. Set it to
755. This number lets the server run the file. - Open your browser and visit
yourdomain.com/cgi-bin/hello.pl. Use your own domain name.
You should see "Hello, world!" on the page.
Common errors
- 500 Internal Server Error: The permissions may be wrong. Also check the shebang line.
- Script downloads instead of running: It may be in the wrong folder.
- Odd line ending problems: Upload the file in ASCII mode if you use FTP. Some editors add hidden characters.
Tip: Never give a script permission
777. That lets anyone change it.Quick recap
- Perl is a language for writing scripts.
- Scripts usually go in
cgi-bin. - The first line points to Perl.
- Set permissions to
755. - Ask Hostvento support if Perl is on your plan.