|
|
|
|
||||||
| alt.apache.configuration Apache web server configuration issues. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I am new to apache but I am learning quickly but recently I have been
trying to learn database interaction. I developed a simple python script but I keep getting an error message (internal server error 500) when I load the web page. The apache error log file shows the following information and my permissions on the file appear to be okay. I think I have a configuration problem in apache but I don't know what to do ... any thoughts: -------------------------------------------------------------------- [Thu Feb 07 15:49:50 2008] [error] [client 127.0.0.1] (2)No such file or directory: exec of '/var/www/cgi-bin/fig17_27.py' failed [Thu Feb 07 15:49:50 2008] [error] [client 127.0.0.1] Premature end of script headers: fig17_27.py -------------------------------------------------------------------- brxxxxsh@ubuntu:/var/www/cgi-bin$ ls -al fig17_27.py -rwxr-xr-x 1 root root 3488 2008-02-07 15:49 fig17_27.py -------------------------------------------------------------------- Contents of file: fig17_27.py (this executes fine from the command line using the command: "python fig17_27.py" and I see data from the database, so I am assuming the program/script is okay. Also, this is a example/tutorial from a Deitel text book ... #!/usr/local/bin/python # Fig. 17.27: fig17_27.py # Displays contents of the Authors table, # ordered by a specified field. import MySQLdb import cgi import sys def printHeader( title ): print """Content-type: text/html <?xml version = "1.0" encoding = "UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "en" lang = "en"> <head><title>%s</title></head> <body>""" % title # obtain user query specifications form = cgi.FieldStorage() # get "sortBy" value if form.has_key( "sortBy" ): sortBy = form[ "sortBy" ].value else: sortBy = "firstName" # get "sortOrder" value if form.has_key( "sortOrder" ): sortOrder = form[ "sortOrder" ].value else: sortOrder = "ASC" printHeader( "Authors table from Books" ) # connect to database and retrieve a cursor try: connection = MySQLdb.connect( db = "Books", user = "root" ) # error connecting to database except MySQLdb.OperationalError, error: print "Error:", error sys.exit( 1 ) # retrieve cursor else: cursor = connection.cursor() # query all records from Authors table cursor.execute( "SELECT * FROM Authors ORDER BY %s %s" % ( sortBy, sortOrder ) ) allFields = cursor.description # get field names allRecords = cursor.fetchall() # get records # close cursor and connection cursor.close() connection.close() # output results in a table print """\n<table border = "1" cellpadding = "3" > <tr bgcolor = "silver" >""" # create table header for field in allFields: print "<td>%s</td>" % field[ 0 ] print "</tr>" # display each record as a row for author in allRecords: print "<tr>" for item in author: print "<td>%s</td>" % item print "</tr>" print "</table>" # obtain sorting method from user print """ \n<form method = "post" action = "/cgi-bin/fig17_27.py"> Sort By:<br />""" # display sorting options for field in allFields: print """<input type = "radio" name = "sortBy" value = "%s" />""" % field[ 0 ] print field[ 0 ] print "<br />" print """<br />\nSort Order:<br /> <input type = "radio" name = "sortOrder" value = "ASC" checked = "checked" /> Ascending <input type = "radio" name = "sortOrder" value = "DESC" /> Descending <br /><br />\n<input type = "submit" value = "SORT" /> </form>\n\n</body>\n</html>""" |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1 pythonbrian wrote: > I am new to apache but I am learning quickly but recently I have been > trying to learn database interaction. I developed a simple python > script but I keep getting an error message (internal server error 500) > when I load the web page. The apache error log file shows the > following information and my permissions on the file appear to be > okay. I think I have a configuration problem in apache but I don't > know what to do ... any thoughts: > > -------------------------------------------------------------------- > > [Thu Feb 07 15:49:50 2008] [error] [client 127.0.0.1] (2)No such file > or directory: exec of '/var/www/cgi-bin/fig17_27.py' failed > [Thu Feb 07 15:49:50 2008] [error] [client 127.0.0.1] Premature end of > script headers: fig17_27.py > > -------------------------------------------------------------------- > > brxxxxsh@ubuntu:/var/www/cgi-bin$ ls -al fig17_27.py > -rwxr-xr-x 1 root root 3488 2008-02-07 15:49 fig17_27.py > > -------------------------------------------------------------------- > > Contents of file: fig17_27.py (this executes fine from the command > line using the command: "python fig17_27.py" and I see data from the > database, so I am assuming the program/script is okay. > Also, this is a example/tutorial from a Deitel text book ... > > #!/usr/local/bin/python Sorry I'm too sleepy to read the whole of the post. Can you do two thinngs? 1. Don't leave the file owned as root:root. That's just *ASKING* for trouble. 2. Check that you're not using windows line breaks. With CGI scripts the webserver will fork()/execv() the shell on the first line of the script (#!/usr/local/bin/python). However, with windows line breaks the character before the LF is a \r (0x0d). Take a look at the script using the 'od' program with the arguments -xc to get hex/character output). My guess is that's what's going wrong, so the script can't be executes because the shebang line is wrong. If you're using vim, keep 'set fileformat=unix' in your ~/.vimrc. - -- The CAT5 to the Ultra 5 is down because of Brian Bird. AOL is charging the omega 13 device. :: http://www.s5h.net/ :: http://www.s5h.net/gpg.html -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFHq6zd4dyr7s6PRYgRAjLeAJ9gyVioDUE8DeQFhjWPCS sf7zOGZQCghkBL TwVg53Qif6Jm6x3QhmWgrTk= =es+e -----END PGP SIGNATURE----- |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On 2008-02-08, pythonbrian <brianmarsh@yahoo.com> wrote:
> [Thu Feb 07 15:49:50 2008] [error] [client 127.0.0.1] (2)No such file > or directory: exec of '/var/www/cgi-bin/fig17_27.py' failed > [Thu Feb 07 15:49:50 2008] [error] [client 127.0.0.1] Premature end of > script headers: fig17_27.py It seems that your script doesn't return a correct web page when called, if you call the script by hand (at the command-line), do you get a full web page (with all the Content-Type bits before the html) ? > Also, this is a example/tutorial from a Deitel text book ... That doesn't mean that it's correct... I've saw enough broken example in my life... Another thing is, you sure that Apache can execute the script? Does he know where to find Python? Is python in your path and so on? Do you have execute permissions on the directory? Davide -- This fortune does not require Microsoft Windows. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
"ed" <ed@example.test> wrote in message
news:k%Nqj.5191$NL3.1903@newsfe2-gui.ntli.net... >> [Thu Feb 07 15:49:50 2008] [error] [client 127.0.0.1] (2)No such file >> or directory: exec of '/var/www/cgi-bin/fig17_27.py' failed >> [Thu Feb 07 15:49:50 2008] [error] [client 127.0.0.1] Premature end of >> script headers: fig17_27.py >> >> -------------------------------------------------------------------- >> >> brxxxxsh@ubuntu:/var/www/cgi-bin$ ls -al fig17_27.py >> -rwxr-xr-x 1 root root 3488 2008-02-07 15:49 fig17_27.py >> >> -------------------------------------------------------------------- >> >> Contents of file: fig17_27.py (this executes fine from the command >> line using the command: "python fig17_27.py" and I see data from the >> database, so I am assuming the program/script is okay. >> Also, this is a example/tutorial from a Deitel text book ... >> >> #!/usr/local/bin/python > > Sorry I'm too sleepy to read the whole of the post. > > Can you do two thinngs? > > 1. > > Don't leave the file owned as root:root. That's just *ASKING* for trouble. > Why? leaving the file owned as root prevents any other user on that box from altering it. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1 phantom wrote: >> >> 1. >> >> Don't leave the file owned as root:root. That's just *ASKING* for trouble. >> > > Why? leaving the file owned as root prevents any other user on that box from > altering it. Uhh. It also means that if suexec wants to execute it with the OWNER UID, then that's a bad thing... really bad. This should never happen, but lets not tempt it. In some caes, suPHP will REFUSE to execute with a UID lower than 100. You should follow it's advice. - -- The Ether to Redback1 is screaming like Bryan Bird because of Some newbie fatfingering their password. The Script Kiddy is smoking crack. :: http://www.s5h.net/ :: http://www.s5h.net/gpg.html -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFHrFEj4dyr7s6PRYgRAnmoAJ9DQ4GPg/sbrxqWVNXa/i1+s6NbZQCgjmvV OWEEcUy4F8BfY62Vq1d8FBk= =0W+R -----END PGP SIGNATURE----- |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
"ed" <ed@example.test> wrote in message
news:bgYqj.5257$NL3.24@newsfe2-gui.ntli.net... > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > phantom wrote: > >>> >>> 1. >>> >>> Don't leave the file owned as root:root. That's just *ASKING* for >>> trouble. >>> >> >> Why? leaving the file owned as root prevents any other user on that box >> from >> altering it. > > Uhh. > > It also means that if suexec wants to execute it with the OWNER UID, > then that's a bad thing... really bad. > The ownership of the file doesn't stop root executing it - If you manage to configure your server so that suEXEC can run programs as root then root will be able to run the script. You don't appear to understand how suEXEC actually works. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1 phantom wrote: > "ed" <ed@example.test> wrote in message > news:bgYqj.5257$NL3.24@newsfe2-gui.ntli.net... >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> >> phantom wrote: >> >>>> 1. >>>> >>>> Don't leave the file owned as root:root. That's just *ASKING* for >>>> trouble. >>>> >>> Why? leaving the file owned as root prevents any other user on that box >>> from >>> altering it. >> Uhh. >> >> It also means that if suexec wants to execute it with the OWNER UID, >> then that's a bad thing... really bad. >> > > The ownership of the file doesn't stop root executing it - > If you manage to configure your server so that suEXEC can run programs as > root then root will be able to run the script. > > You don't appear to understand how suEXEC actually works. Why would you want to stop root executing it? The idea is to stop the web server executing a script which will run as root. Attempting to stop an administrator of a host from getting to files is just stupid. - -- The HSSI to the mcu is screwed because of BobaFett. The Empire is practising the jedi mind trick. :: http://www.s5h.net/ :: http://www.s5h.net/gpg.html -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFHrG504dyr7s6PRYgRAsBNAJ9qMozWABpwQvejxb4OXl X959IC7ACePaXw cfTMkznRL3P93+xzLl8n5yo= =pJvy -----END PGP SIGNATURE----- |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
"ed" <ed@example.test> wrote in message
news:96_qj.733$875.92@newsfe4-gui.ntli.net... > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > phantom wrote: >> "ed" <ed@example.test> wrote in message >> news:bgYqj.5257$NL3.24@newsfe2-gui.ntli.net... >>> -----BEGIN PGP SIGNED MESSAGE----- >>> Hash: SHA1 >>> >>> phantom wrote: >>> >>>>> 1. >>>>> >>>>> Don't leave the file owned as root:root. That's just *ASKING* for >>>>> trouble. >>>>> >>>> Why? leaving the file owned as root prevents any other user on that box >>>> from >>>> altering it. >>> Uhh. >>> >>> It also means that if suexec wants to execute it with the OWNER UID, >>> then that's a bad thing... really bad. >>> >> >> The ownership of the file doesn't stop root executing it - >> If you manage to configure your server so that suEXEC can run programs as >> root then root will be able to run the script. >> >> You don't appear to understand how suEXEC actually works. > > Why would you want to stop root executing it? The idea is to stop the > web server executing a script which will run as root. > This is my point, If the web server *can* execute something as root it DOES NOT MAKE ANY DIFFERENCE if the file being executed is owned by root or not. Please learn the difference between file ownership and who is executing the file. |
|
![]() |
| Outils de la discussion | |
|
|