Still using CGI? Really? Wow... I can't even... 🤯
Just kidding, Opalstack has you covered! ✨
Here's how to get your ancient-but-beloved CGI scripts running on Opalstack:
I'm using Python in my examples here but all of this should work for Perl, bash, or whatever you're using for your CGI script.
- Create a new Apache/PHP-FPM app via your Opalstack dashboard and hook it up to whatever site.
- Upload your CGI scripts into the app directory.
- Edit or create the
.htaccess file in your app directory to add the extensions that your CGI scripts use, eg
.py or whatever like so:
AddHandler cgi-script .py
- Make your scripts executable with the following command (adjust as necessary for your files):
chmod 700 ~/apps/appname/*.py
That's pretty much it, at that point your scripts should execute as CGI (as the app's shell user) when requested via your site.
If it doesn't work:
- Check the permissions - the scripts must be set to 700, which is read/write/execute for your shell user, and no permissions for anybody else.
- Check the "shebang", ie the first line of your scripts. They must point to a valid path for whatever interpreter will run the script, eg:
- If the script is running Python from a virtual environment, then be sure to use the full path to Python for that environment, eg:
Give it a try, let me know what problems you run into, and let's make this work together! 🙂