Run bash on the web
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 "<Directory \"/srv/http/cgi-bin\">" >> /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 "</Directory>" >> /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 "<meta charset='utf-8'>"
/permissions
# Make the script executable chmod +x /srv/http/cgi-bin/myscript.sh # Test the script works /srv/http/cgi-bin/myscript.sh