What is a Perl script?
Perl is a programming language. A Perl script is a text file with Perl instructions. On a website, scripts usually end in .pl or .cgi. CGI means the web server runs the script and sends back what it prints, like a cook who follows a recipe and hands you the dish.
The most common error you will see is "500 Internal Server Error". It is a general message that means "something went wrong inside the script". It does not tell you what. So you need to look for clues.
Steps
- Check the first line of the script. It must point to Perl, for example
#!/usr/bin/perl. This line is called the shebang. It tells the server which program should run the file. The correct path for your server is in your welcome email, or you can ask Hostvento support. - Make sure the script prints a header before any other output. Add this line before everything else you print:
This line tells the browser what kind of data is coming. Without it you get a 500 error.print "Content-type: text/html\n\n"; - Check the file permissions. A permission is a rule about who may read or run a file. Most scripts need the value
755. Use your File Manager or an FTP program, right-click the file and choose the permissions option. - Check the line endings. If you wrote the file on Windows and uploaded it in the wrong mode, the server may not read the first line. Upload the file again in ASCII mode (text mode) in your FTP program.
- Test the script for syntax mistakes. Syntax means the spelling and grammar of code. If you have SSH access (a safe way to type commands on the server), run:
This only checks the script. It does not run it. It prints "syntax OK" or tells you the line with the mistake.perl -c yourscript.pl - Run the script by hand to see its real output:
Any error message appears right on the screen.perl yourscript.pl - Look at the error log. A log is a diary that the server keeps. Look for a file named
error_login the folder of your script, or use the Errors or Metrics section of your control panel if it has one. - Add the strict and warnings lines near the top of the script:
They make Perl point out careless mistakes, such as a misspelled variable name.use strict; use warnings; - Check that every module the script uses is installed. A module is an add-on that gives Perl extra skills. If the log says "Can't locate" and a module name, ask Hostvento support whether it can be installed on your plan.
Tip: Change one thing at a time and test after each change. Then you will know which change fixed the problem.
Quick recap
- A 500 error only says something is wrong. Look at the logs for the reason.
- Check the shebang line, the Content-type header, and permissions of 755.
- Use
perl -cto test syntax anduse strict; use warnings;to catch mistakes. - Upload scripts in ASCII mode.
- If a module is missing, ask Hostvento support.