OT maybe, python and apache

From: Garrett Gaston 
------------------------------------------------------

I'M trying to get the below python cgi output to load in my web browser=20
but the browser is just displaying the code it's self instead of the=20
output. My apache program is working because I just tried the phpinfo=20
function and it worked just fine. I'M getting this code from a book and=20
it's actually showing "#!/usr/bin/env python" but I decided to use what I
 got with the which command "which python3" -> /usr/bin/python3

I have one copy of the file in /var/www and another in /var/www/cgi-bin.
 I've also used grep and vi to find and edit every file in /etc/apache2=20
that contains "ExecCGI' and I've removed that # in front of it hoping to
 turn on apache's cgi function. Could someone please tell me what I've=20
done wrong here? Thanks.




#!/usr/bin/python3
print('Content-type: text/plain')
# prints an empty line=2C to end the headers
print('Testing Python CGI')
 		 	   		  =

=============================================================== From: Eric Wolf ------------------------------------------------------ Is the execute permission set so the apache user can run the script?

=============================================================== From: Dan Lyke ------------------------------------------------------ On Tue, 13 Nov 2012 10:21:38 -0600 Garrett Gaston wrote: Two problems, one of which I know what the answer to is. Let's start with the unknown one first: Your Apache isn't running your app as a CGI. I do something like: ScriptAlias /cgi-bin/ /home/danlyke/websites/flutterby.net/cgi-bin/ AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all To make http://localhost/cgi-bin/test.py run from /home/danlyke/websites/flutterby.net/cgi-bin/ The second is easy: You need a blank line between the headers and the content, so add a line here that says: print('') Dan

=============================================================== From: Garrett Gaston ------------------------------------------------------ Dan=2C on the script you just sent me back: ScriptAlias /cgi-bin/ /home/danlyke/websites/flutterby.net/cgi-bin/ AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow=2Cdeny Allow from all =20 What file did you find this in? Looking through my /etc/apache2 directory I= found several files with ScriptAlias=2C > every file in /etc/apache2 that contains "ExecCGI' and I've removed

=============================================================== From: Garrett Gaston ------------------------------------------------------ Both files have rx on both user and others=2C I think the permissions are 7= 55. I created two files=2C one under /var/www/file.cgi and another under /v= ar/www/cgi-bin/file.cgi. I had read where the file might need to be named w= ith a .cgi extension or that it might need to be placed in a sup directory = called cgi-bin. So I created two files both with .cgi extensions but one fi= le is one more level down in cgi-bin directory right under /var/www/. Date: Tue=2C 13 Nov 2012 09:27:32 -0700 From: ebwolf@gmail.com To: chugalug@chugalug.org Subject: Re: [Chugalug] OT maybe=2C python and apache Is the execute permission set so the apache user can run the script? On Nov 13=2C 2012 9:22 AM=2C "Garrett Gaston" wrote= : I'M trying to get the below python cgi output to load in my web browser=20 but the browser is just displaying the code it's self instead of the=20 output. My apache program is working because I just tried the phpinfo=20 function and it worked just fine. I'M getting this code from a book and=20 it's actually showing "#!/usr/bin/env python" but I decided to use what I got with the which command "which python3" -> /usr/bin/python3 I have one copy of the file in /var/www and another in /var/www/cgi-bin. I've also used grep and vi to find and edit every file in /etc/apache2=20 that contains "ExecCGI' and I've removed that # in front of it hoping to turn on apache's cgi function. Could someone please tell me what I've=20 done wrong here? Thanks. #!/usr/bin/python3 print('Content-type: text/plain') # prints an empty line=2C to end the headers print('Testing Python CGI') =20

=============================================================== From: Dan Lyke ------------------------------------------------------ On Tue, 13 Nov 2012 10:51:28 -0600 Garrett Gaston wrote: On Ubuntu, I put that segment in /etc/apache2/sites-enabled/000-default On some bastardized abomination like SL6... Uh... I mean, on my work machine, that'd be in /etc/httpd/conf/httpd.conf unless you set up something else (which I would). So I actually just muck around with Apache stuff 'til it works, and then never touch it again, but... I believe that "ScriptAlias x /y/z/w" says "for every request that looks like http:/blabla/x/, look on the local filesystem in the folder /y/z/w". Then the "" tag says "Within this directory on the file system, use these options". If you use the "" tag instead, you're saying "Within this path on the HTTP request". I think. I *think* that this setup basically says "Assume everything there is a CGI script", which means that: simple1.cgi should work just fine. As should simple1.py. Dan

=============================================================== From: Dan Lyke ------------------------------------------------------ On Tue, 13 Nov 2012 10:21:38 -0600 Garrett Gaston wrote: I'm assuming that you've got this working now, but I wanted to note: It used to be that we specified which interpreter we wanted with #!/usr/bin/python or #!/usr/local/bin/python or #!/opt/run/python or ... well ... you get the picture. The problem was that when you tried to share a script file with someone they'd say "Hey, I don't have "/opt/run/python" on my computer, what'sup?" This got even worse when you had dueling source control checkins. I make it point to my favorite Python interpreter, check it in, you check out the latest software, it breaks your build, you fix it to your interpreter, check it in, after two or three rounds of that we're on to passive-aggressive solutions like poisoning your lunch, or fouling up your romantic entanglements, or kneecapping the starters in your favorite sports leagues. Finally, someone said "Hey, let's make /usr/bin/env find and run the appropriate interpreter from the path, and if people want to run /yargh/really/my/funky/build/python then they can change that in their own personal environment and not inflict it on the rest of us." Hope this helps explain things a bit. Dan

=============================================================== From: Garrett Gaston ------------------------------------------------------ Thanks. I've never understood why there are seemingly so many paths to prog= rams in Linux. Coming from windows everything is C:\Program Files\NameOfPro= gram\program.exe So are you saying that I should use #!/usr/bin/enc python3 or am I misunder= standing you? I'M going to give it a try=2C and no I actually hadn't got th= is working yet. ck to

=============================================================== From: wes ------------------------------------------------------ he was just explaining a bit about why it is the way it is. you should use whatever works for you. once it works, don't mess with it! without making backups that is. this is a good time to extol the virtues of good backups. when you screw something up, as we all inevitably do, they suddenly become PRICELESS! in the early stages, it would be great to get into the habit of copying any files you're about to modify. I put a date on anything that's only mine (on my own system) and on a shared system, I include my name. cp .bashrc .bashrc.2012-11-17 vi .bashrc actually, the example I randomly chose above reminds me to raise another point that I hope you never have to struggle with. when modifying login related things, KEEP YOUR CURRENT SESSION GOING. immediately after saving, start a new SSH session or virtual terminal on the host and make sure you can still get in. if not, you can always switch back to the session you still have open and fix it. don't learn the hard way! I did. and it sucked. -wes

=============================================================== From: Eric Wolf ------------------------------------------------------ Garrett, Not to sound snotty, but on my Windows 7 box, Python is in C:\Python26\bin, C:\ArcGIS\Python25\bin, C:\Python27\bin (and probably a few other places)... Not a single copy of Python is in C:\Program Files\Python\python.exe... I also seem to have quite a number of programs in C:\Windows, C:\Windows\System, C:\Windows\System32, C:\Windows\SysWOW64. I know that in older versions of Windows, there was no System32 or SysWOW64. Linux is no different. Stuff moves around. That's where things like 'locate' come in handy. -Eric -=--=---=----=----=---=--=-=--=---=----=---=--=-=- Eric B. Wolf 720-334-7734