How to run perl scripts on cPanel Shared Hosting

To run Perl scripts on cPanel shared hosting, follow these steps:


1. Ensure Perl is Supported

Most cPanel-based shared hosting environments do support Perl, but it’s good to confirm with your host or check cPanel’s Software section for “Perl Modules”.


2. Upload Your Perl Script

  1. Log in to cPanel.
  2. Go to File Manager.
  3. Upload your Perl script (e.g., script.pl or script.cgi) to the public_html/cgi-bin/ directory.
    • If cgi-bin does not exist, create it inside public_html.

3. Set Correct Permissions

After uploading:

  1. Right-click the Perl script in File Manager > Permissions.
  2. Set permissions to 755 (rwxr-xr-x) so it can execute.

4. Add Shebang Line

Ensure your Perl script starts with the correct shebang line. Most shared servers use:

#!/usr/bin/perl

Put this on the first line of your script.


5. Test in Browser

Access your script in the browser:

https://yourdomain.com/cgi-bin/script.pl

If it’s working, you should see the script’s output.


6. Use CGI Headers

Perl scripts that produce output for the browser need to send proper headers. For example:

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<html><body><h1>Hello from Perl!</h1></body></html>";

7. Check Errors

If it doesn’t work:

  • Check error_log inside the cgi-bin folder or global Apache error logs via cPanel > Metrics > Errors.
  • Common issues:
    • Wrong shebang line
    • File not executable (permissions)
    • Missing required Perl modules

8. Install Perl Modules (if needed)

Use cPanel > Perl Modules to search for and install required modules if your script needs any.


 

Was this article helpful?
YesNo