this has been a problem for me for days and I haven't been able to solve it.
I'm working on fedora 14 and using Apache/2.2.17 (Unix)
the document root is /var/www and it is well configured in my httpd.conf
I have several folders inside /var/www that have perl files that require CGI to be run and instead, sometimes the perl file is offered as download and sometimes an error 500 appears
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
the cgi_module is being loaded and even if I use ScriptAlias, and the directory tag, the file is still not being ran a script.
I even tried to create a virtual host and it doesnt work.
For instance, if I want a directory called "pyl" located inside the apache root (/var/www) what would the lines for httpd.conf be?
Indeed, check the error log (/var/log/apache2/error.log ?), check your file and dir permissions.
Also make sure your ScriptAlias directive is updated correctly.
So, have a look in your site config file (i.e. sites-available/default) and change this:
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
.. to this:
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
<Directory "/var/www/cgi-bin">
.. and reload apache2.
This solution applies to Apache2.4.51 version or may others. The directory structure can change with versions.
Make a change the default CGI config file below:
nano /etc/apache2/conf-available/serve-cgi-bin.conf
Change:
ScriptAlias /cgi/ /home/user/your-folder
<Directory "/home/user/your-folder">
Move your *.cgi, *.py, *.sh, etc files to your folder
Apply chmod 755 to your folder:
chmod 755 /your-folder
Restart apache2:
systemctl restart apache2
Sample pyhton code that you can run:
nano /home/user/your-folder/pythonapp.py
Code:
#!/usr/bin/python3
print("Content-type:text/html")
print()
print("""
<!doctype html>
<html><head></head><title>CGI-Python</title>
<body> Python App </body>
</html>
""")
Save and run your url:
server-ip-or-host/cgi/pythonapp.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With