#!/usr/bin/python
import cgi
print("Content-Type: text/html\n\n")
print("Hello World!")
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"
</IfModule>
<Directory "/usr/local/apache/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
<VirtualHost xx.xx.xx.xx:80>
ServerName somename.domain.com
ServerAlias www.somename.com www.somename.domain.com somename.com
DocumentRoot /home/domain/public_html/somename
ServerAdmin webmaster@somename.domain.com
UseCanonicalName Off
CustomLog /usr/local/apache/domlogs/somename.domain.com combined
CustomLog /usr/local/apache/domlogs/somename.domain.com-bytes_log "%{%s}t %I .\n%{%s}t %O ."
## User domain # Needed for Cpanel::ApacheConf
UserDir enabled domain
<IfModule mod_suphp.c>
suPHP_UserGroup domain domain
</IfModule>
<IfModule !mod_disable_suexec.c>
<IfModule !mod_ruid2.c>
SuexecUserGroup domain domain
</IfModule>
</IfModule>
<IfModule mod_ruid2.c>
RUidGid domain domain
</IfModule>
ScriptAlias /cgi-bin/ /home/domain/public_html/somename/cgi-bin/
</VirtualHost>
ls -lsd / /home/ /home/domain/ /home/domain/public_html/ /home/domain/public_html/somename/ /home/domain/public_html/somename/cgi-bin/
ls -ld /home/domain/public_html/somename/cgi-bin/a.*
or however your cgi-script python and shell scripts are called.
I assume, that you have the proof, that this virtrualhost section is really used, because you can access the non-cgi contents without problems, right?
# ls -lsd / /home/ /home/domain/ /home/domain/public_html/ /home/domain/public_html/somename/ /home/domain/public_html/somename/cgi-bin/
4 dr-xr-xr-x. 31 root root 4096 May 9 17:21 /
4 drwx--x--x. 14 root root 4096 May 7 01:32 /home/
4 drwx--x--x 21 domain nobody 4096 May 13 01:02 /home/domain/
4 drwxr-xr-x 14 domain domain 4096 May 12 18:29 /home/domain/public_html/
4 drwxr-xr-x 17 someotheruser someotheruser 4096 May 8 23:02 /home/domain/public_html/somename/
4 drwxr-xr-x 2 someotheruser someotheruser 4096 May 9 16:50 /home/domain/public_html/somename/cgi-bin/
# ls -ld /home/domain/public_html/somename/cgi-bin/*.*
-rwxr-xr-x 1 root root 62 May 9 15:47 /home/domain/public_html/somename/cgi-bin/a_sh.cgi
-rwxr-xr-x 1 someotheruser someotheruser 34819 May 8 22:25 /home/domain/public_html/somename/cgi-bin/cgi.py
-rw-r--r-- 1 root root 34967 May 8 22:30 /home/domain/public_html/somename/cgi-bin/cgi.pyc
-rwxr-xr-x 1 someotheruser someotheruser 123 May 8 22:30 /home/domain/public_html/somename/cgi-bin/a.py
#
chmod a+rx /home /home/domain
ScriptAlias /cgi-bin/ /home/domain/public_html/somename_cgi-bin/
and to mv /home/domain/public_html/somename/cgi-bin/ /home/domain/public_html/somename_cgi-bin/
<Directory "/home/domain/public_html/somename_cgi-bin/">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
4 drwx--x--x. 14 root root 4096 May 7 01:32 /home/
chmod go-r /home /home/domain
will undo the effect of m suggested chmod a+rx /home /home/domain
which could have been in the current context just achmod go+r /home /home/domain
chmod a+rx /home /home/domain
was the correct one to get the permissions back the way they were.<Directory "/">
Options ExecCGI IncludesNOEXEC Indexes SymLinksIfOwnerMatch
AllowOverride All
</Directory>
<Directory "/usr/local/apache/htdocs">
Options Includes Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Files ~ "^error_log$">
Order allow,deny
Deny from all
Satisfy All
</Files>
<FilesMatch "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog "logs/access_log" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"
</IfModule>
<Directory "/usr/local/apache/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
<IfModule mod_log_config.c>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
CustomLog logs/access_log common
</IfModule>
<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
</IfModule>
It's quite trick to know without further info.
So I'll ask you some questions a little blindly.
Q1.) What web server is being used?
- Do you have any other cgi script written in an other language, that is working? like for example:
Open in new window
Q2.) Do you have access to the webserver's logs? (This would definitely simplify the debugging)
Q3.) I assume you execute the script on the same machine on which the server is run. Am I right?
Q4.) How do you call the script via ssh? (let's assume you called your cgi-script mycgiscript.py)
with
python ./mycgiscript.py
or just with
./mycgiscript.py
Q5.) What's the output of following command?
which python
Q6.) what's the output of following command?
python -m cgi > /dev/null && echo $?