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
- Log in to cPanel.
- Go to File Manager.
- Upload your Perl script (e.g.,
script.plorscript.cgi) to thepublic_html/cgi-bin/directory.- If
cgi-bindoes not exist, create it insidepublic_html.
- If
3. Set Correct Permissions
After uploading:
- Right-click the Perl script in File Manager > Permissions.
- 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_loginside thecgi-binfolder 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