WEB-BASH(1)marcp.xyzWEB-BASH(1)
NAME
web-bash - Running bash scripts via Apache CGI
DESCRIPTION
WARNING: Running bash scripts via CGI can be dangerous and should only be done in isolated environments.Apache
Enable the required Apache modules:
# Enable mod_cgid in the Apache config echo "LoadModule cgid_module modules/mod_cgid.so" >> /etc/httpd/conf/httpd.conf # Add CGI configuration echo "ScriptAlias /cgi-bin/ \"/srv/http/cgi-bin/\"" >> /etc/httpd/conf/httpd.conf echo "" >> /etc/httpd/conf/httpd.conf echo " AllowOverride None" >> /etc/httpd/conf/httpd.conf echo " Options +ExecCGI" >> /etc/httpd/conf/httpd.conf echo " Require all granted" >> /etc/httpd/conf/httpd.conf echo " " >> /etc/httpd/conf/httpd.conf # Restart Apache systemctl restart httpd
Directories
Create a CGI-bin folder for the scripts:
mkdir -p /srv/http/cgi-bin chown http:http /srv/http/cgi-bin chmod 755 /srv/http/cgi-bin
Template
Use this header for your CGI scripts:
#!/bin/bash echo "Content-type: text/html" echo "" echo ""
Permissions
# Make the script executable chmod +x /srv/http/cgi-bin/myscript.sh # Test the script works /srv/http/cgi-bin/myscript.sh
marcp.xyz2023-07-03WEB-BASH(1)