Apache/httpd /var/www/html/ .cgi scripts throw 500 internal server error
I just solved reinstalling the server and doing all over again, disabled selinux and iptables, because I have already an external firewall.
Thanks to anyone who helped me out ;)
500 internal Server error when configuring python cgi
Your CGI script must also output header information.
The minimum required is the Content-type
header -- which in this case should be set to text/html
.
Add this to the start of your CGI script (before you print anything else).
print 'Content-type: text/html\n'
Take note of the extra trailing newline -- its necessary to leave at least one blank line between the header(s) and the content itself.
Update:
For further troubleshooting, do the following:
- Make sure your CGI script has the correct permissions set:
chmod 0755 hello.py
just to be sure. - Your script appears to be
.py
whereas your apache config appears to only specify.cgi
files. YourAddHandler
should beAddHandler cgi-script .cgi .py
. - You should symlink your
/etc/apache2/conf-available/crunchworld.conf
file in/etc/apache2/conf-enabled
if you haven't already done so. Do so by running the following:cd /etc/apache2/conf-enabled; sudo ln -s ../conf-available/crunchworld.conf
. - Always remember to restart apache if you make any changes to your apache config: e.g.
sudo service apache2 restart
. - Check that your hashbang line is correct. Does
/usr/bin/python2.7
exist? You can try setting instead to#!/usr/bin/env python
or#!/usr/bin/env python2
. (Or better yet, switch topython3
if possible on your system). - Check the apache error logs once again. E.g.
tail -20 /var/log/apache2/error.log
(or wherever your logs are). - You can attempt further debugging with the
cgitb
module (see https://docs.python.org/3/library/cgitb.html).
CGI script not running, Internal Server Error (500) Error
Try running:
perl -c /var/www/cgi-bin/upload.cgi
Quote from perldoc perlrun:
-c causes Perl to check the syntax of the program and then exit
without executing it. Actually, it will execute "BEGIN",
"UNITCHECK", "CHECK", and "use" blocks, because these are
considered as occurring outside the execution of your program.
"INIT" and "END" blocks, however, will be skipped.
Python CGI getting 500 Internal Server Error
Every thing was fine except cgi-bin
directory's permission.
Change the permission (chmod) of cgi-bin to 755 from 777.
internal server error (500) in simple cgi script
You might need a #!/usr/bin/python
at the top of your script to tell Apache to use Python to execute it. At least, I did that and it worked for me :-) .
Related Topics
Add Timestamp to Cat Output from Shell Script
Detect If Interface Is in Promiscuous Mode with C
Creating an Alias in Ubuntu, in .Profile
How to Create a File in Assembly with a Dynamically Specified File Path
How to Distribute C++11 Shared Library on Centos6
Environment Variables in Symbolic Links
How to Get CPU Serial Under Linux Without Root Permissions
What Is a Shell Command to Find The Longest Common Substring of Two Strings in Unix
Installing Mailutils Using Apt-Get Without User Intervention
Where Is The Linux Socket Implementation
Elf File Tls and Load Program Sections
Replace Strings with Evaluated String Based on Matched Group (Elegant Way, Not Using for .. In)
Correct Way to Export Multiple Ld_Library_Paths
Where The Structure "Struct Page" Is Stored on The Linux Kernel
Tail Logback Log Files with Log Level Coloring in Linux Server
Copying Files with Wildcard (*) to a Folder in a Bash Script - Why Isn't It Working