Apache Problems.


 
Thread Tools Search this Thread
Top Forums Web Development Apache Problems.
# 1  
Old 12-13-2008
Error Apache Problems.

Hello guys

I have been running a LAMP stack for awhile now but have never really explored the server side end of things. What I am trying to do is have a python script on a website run a bash command. This will accomplish a system so someone can create an account for proxy access via a webpage. I am running Ubuntu server edition 8.04.1


Here is my python script (For testing purposes) to do so:
Code:
import os

def main():
    username = "Test1"
    password = "Enter new password"
    os.system("htpasswd -b /etc/squid/passwd '%s' '%s'" % (username.replace("'"$
    return apache.OK
if __name__ == '__main__': main()

Now I read a bit on the net and from what I gathered I would need to run this as a CGI script. So I placed it in my /usr/lib/cgi-bin/ directory as a .py file.

Then when I go to my site (mysite.com/cgi-bin/program.py)

I get a 500 internal server error. So Once again I looked around and I figured out that I had bad handlers in my site configuration so I tried various different things and nothing seemed to work so I reset my site configuration to as follows:
Code:
NameVirtualHost *
<VirtualHost *>
        ServerAdmin webmaster@localhost

        DocumentRoot /home/carter/public_html
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /home/carter/public_html>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

Here is a section of my error log that pertains to this error:
Code:
[Sun Dec 07 06:33:46 2008] [notice] mod_python: Creating 8 session mutexes based on 150 max processes and 0 max threads.
[Sun Dec 07 06:33:46 2008] [notice] mod_python: using mutex_directory /tmp
[Sun Dec 07 06:33:46 2008] [notice] Apache/2.2.8 (Ubuntu) mod_python/3.3.1 Python/2.5.2 PHP/5.2.4-2ubuntu5.3 with Suhosin-Patch configured -- resuming normal operations
[Sun Dec 07 09:42:16 2008] [error] [client 222.187.220.162] script '/home/carter/public_html/prx1.php' not found or unable to stat
[Sun Dec 07 18:51:35 2008] [error] [client 137.186.97.98] File does not exist: /home/carter/public_html/favicon.ico
[Sun Dec 07 22:14:22 2008] [error] [client 192.168.1.4] File does not exist: /home/carter/public_html/mad_scientist.txt
[Sun Dec 07 22:24:23 2008] [error] [client 72.25.192.4] File does not exist: /home/carter/public_html/favicon.ico
[Sun Dec 07 23:52:00 2008] [error] [client 222.187.220.162] script '/home/carter/public_html/prx1.php' not found or unable to stat
[Mon Dec 08 17:53:46 2008] [notice] caught SIGWINCH, shutting down gracefully
[Mon Dec 08 17:53:57 2008] [notice] mod_python: Creating 8 session mutexes based on 150 max processes and 0 max threads.
[Mon Dec 08 17:53:57 2008] [notice] mod_python: using mutex_directory /tmp
[Mon Dec 08 17:53:57 2008] [notice] Apache/2.2.8 (Ubuntu) mod_python/3.3.1 Python/2.5.2 PHP/5.2.4-2ubuntu5.3 with Suhosin-Patch configured -- resuming normal operations
[Mon Dec 08 17:54:23 2008] [error] [client 192.168.1.4] (8)Exec format error: exec of '/usr/lib/cgi-bin/carternet.py' failed
[Mon Dec 08 17:54:23 2008] [error] [client 192.168.1.4] Premature end of script headers: carternet.py

Any help would be awesome. Thank you.
# 2  
Old 12-13-2008
My guess is that the webserver does not have permissions to run the htpasswd command and store the file in /etc/squid/passwd.

The other possibility, if your code as posted is what you actually used is the fact that the line running the htpasswd is syntactically incorrect ( I assume the end of the line is just missing in your post).
# 3  
Old 12-13-2008
Yeah, sorry, I didn't realize the script was cut off, although it seemed to only be cut off when I posted here (The actual script on the box is fine). I also thought it was a permissions problem but I gave my cgi-bin and the script it's self 777 permissions.

It is the premature end of headers that is causing the 500 Internal error.
# 4  
Old 12-13-2008
Never give cgi-bin 777 permissions and never give anything in cgi-bin 777 permissions.

Try running your python script as the apache user (www-data) and see if it give any errors. I think the problem is in your script, not in the headers it creates. The reason it gives the header error is that the script exits with a non-zero exit code, and I'm pretty sure it's to do with the permissions of the webserver user to write to /etc/squid/passwd.
# 5  
Old 12-14-2008
is AddHandler cgi-script py set in the apache config?

what is the first line of your script? it should be #!/usr/bin/python or whatever the path is.

also, you need to print the content-type in your script.
# 6  
Old 12-14-2008
Alright. Here is the full script that I am running:
Code:
#!/usr/bin/python
print "Content-type: text/html"
import os

def main():
    username = raw_input ("Enter new username: ")
    password = raw_input ("Enter new password: ")
    os.system("htpasswd -b /etc/squid/passwd '%s' '%s'" % (username.replace("'", ""), password.replace("'", "")))

if __name__ == '__main__': main()

I added the Addhandler in there as well. Same 500 Server error. Also I changed the /etc/squid/passwd to 777.
# 7  
Old 12-14-2008
add two new lines. to your print statement


Code:
print "Content-type: text/html\n\n"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Web Development

Apache module development on apache 2.2

Hi, I'm new to developing modules for Apache. I understand the basics now and can develop something simple which allows a 'GET' request to happen, but what I want to do is actually 'POST' information to my site. I know the basic POST Request works and I can see that it is post by looking at... (2 Replies)
Discussion started by: fishman2001
2 Replies

2. Web Development

Problems with Apache Virtual Host

I am attempting to add virtual hosts to an apache web server, which has this current configuration: <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride None ... (27 Replies)
Discussion started by: Corona688
27 Replies

3. Solaris

Problems with 2 NICS and Apache

I have a Solaris 10 box that has 2 Ethernet connections. One is 172.21.0.150, this is on the main internal LAN. The other is 172.16.0.50 this is the DMZ. I have Apache 2.0.59, I do not care which it Listens to but the main one for it is 172.16.0.50 (DMZ) which I have been explicit (Listen... (1 Reply)
Discussion started by: crowman
1 Replies

4. Web Development

Problems starting Apache 2.0.54

Hi, I just installed Apache 2.0.54 and when I try and start httpd I get mohit@mohit-desktop:/sw/pkg/apache/bin$ ./httpd -k start httpd: Could not determine the server's fully qualified domain name, using 127.0.1.1 for ServerName (13): make_sock: could not bind to address :80 no listening... (1 Reply)
Discussion started by: mojoman
1 Replies

5. Web Development

Apache upload problems.

When I upload a file 32M or larger to fails. I can see the file being uploaded into the /tmp directory but when it gets to ~32M it dissapears. This is from phpinfo: upload_max_filesize 100M 100MB post_max_size 100M 100MB enable_dl On On I dont get an error in the log saying im... (9 Replies)
Discussion started by: Ikon
9 Replies

6. Solaris

Problems starting apache 1.3 with mysql

I've been working on a project to replace one of the my group's primary NIS servers. It also runs mysql and apache, as it is the host for the our team's hardware tracking database and website. Its running apache 1.3, and for some odd reason, I can't get apache to start on system boot. The... (1 Reply)
Discussion started by: godspunk32
1 Replies

7. Solaris

problems with Apache

I have a Solaris 8 box and need to install Apache 2.0.55 on it. First thing I tried was compiling from source code. During the make phase, I got the following errors: Then I tried downloading the binaries. I tried the one available from Apache's site and the one from sunfreeware.com, with... (3 Replies)
Discussion started by: GKnight
3 Replies

8. UNIX for Dummies Questions & Answers

Problems with Apache setup

I posted a problem with the forum on 11/18/02. Unfortunately, I have been out of town. Today is the first chance I've had to try the suggestions that were made. Here is the output from the ls -l configure* command: -rw-r--r-- 1root sys 58230 May 21 2002 configure When I type " sh... (2 Replies)
Discussion started by: cstovall
2 Replies

9. UNIX for Dummies Questions & Answers

Problems with Apache setup

I downloaded Apache 1.3.27.tar.gz into my SCO u/install directory. However, to begin with, I couldn't untar the file using the " tar xvf apache-1.3.27.tar.gz" command, so I used winzip from a windows computer on our network. Winzip untarred the file and I transferred the files to the SCO... (2 Replies)
Discussion started by: cstovall
2 Replies

10. UNIX for Dummies Questions & Answers

Apache Server 1.3.20 Icons Missing and Other Problems...Please Help!!!!

Hi everyone. Okay here are a couple of my problems and hopefully you guys can help me out. Problem 1: i have 2 website that are being hosted on a webserver. The webserver is running redhat 8x and running apache 1.3.20. To make it a little clearer, lets say website A and website B. Both... (1 Reply)
Discussion started by: crazycelicagts
1 Replies
Login or Register to Ask a Question