PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > alt.apache.configuration > No such file or directory .... ??? Configuration Error
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
alt.apache.configuration Apache web server configuration issues.

No such file or directory .... ??? Configuration Error

Réponse
 
LinkBack Outils de la discussion
Vieux 08/02/2008, 00h48   #1
pythonbrian
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut No such file or directory .... ??? Configuration Error

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>"""


  Réponse avec citation
Vieux 08/02/2008, 01h11   #2
ed
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: No such file or directory .... ??? Configuration Error

-----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-----
  Réponse avec citation
Vieux 08/02/2008, 07h38   #3
Davide Bianchi
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: No such file or directory .... ??? Configuration Error

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.
  Réponse avec citation
Vieux 08/02/2008, 08h48   #4
phantom
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: No such file or directory .... ??? Configuration Error

"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.


  Réponse avec citation
Vieux 08/02/2008, 12h52   #5
ed
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: No such file or directory .... ??? Configuration Error

-----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-----
  Réponse avec citation
Vieux 08/02/2008, 14h14   #6
phantom
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: No such file or directory .... ??? Configuration Error

"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.


  Réponse avec citation
Vieux 08/02/2008, 14h58   #7
ed
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: No such file or directory .... ??? Configuration Error

-----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-----
  Réponse avec citation
Vieux 08/02/2008, 15h29   #8
phantom
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: No such file or directory .... ??? Configuration Error

"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.


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h08.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,28748 seconds with 16 queries