Site Sponsors:
Whose STILL better @Python? 
Apologies for previous posts on political topics - I hate to care so much about non-technical issues - but I do.

Maybe you do, too?

Getting back to what we all know and love, surely the best way to push a post BACK, be to push something onto the stack, BEFORE it?

With such a laudable goal placed FIRMLY in mind, allow me to note that - even though Python 2.7 is decidedly deprecated - how, even at this late stage in the game - Ubuntu has the hands-down BEST Python 3 support for Apache2.

I cannot understand how tenured veterans are yet in denial over the ultimate demise of the 2.x standard... over the epoch, that pattern of deprivation has taken place over, and over, over, and over .. and over (!) again?

Indeed, Python 3 "just works" so well out-of-the-box (*) that I recently gave up at even trying to get the LAMP2 (Python3 + PHP) 'stack to work under CentOS 7. --At the day's ending, turn-key is ever so much to be preferred, 'oer toss-and-turn!


LAMP-Py?


... we are even running Ubuntu 16.04 - even as so decidedly dated - upon our clouds ... to absolutely great effect!

GO - DADDY, GO! (That pun ... intended!)

8-)

Note: Following the previous ('how to' link, below) we yet (P2) had to:
apt search php7
apt search libapache2-mod-php7
-then, with respect to our option set, and in as much as php -v was a dud:
apt-get install php
apt-get install libapache2-mod-php7.0

To be followed by the requisite:
systemctl restart apache2

(*) (how to)


[ view entry ] ( 954 views )   |  permalink  |  related link
Stand-up a Basic Web Server ... in 1 Line of Code? 
There I was, starting to spin-up my AWS Server when it occurred to me: Once having resolved to use Python 3 on the back-end, why pay for the spindle-time?!

(Apache NOT Required!)

Indeed, even with a Doctor Quote front-end (written in C/C++, with a new for-discussion strawman written in Java) the basic GET / POST ops provided by Python's http.server are more than adequate for this man's B.E.S.T efforts.

Three Easy Steps


The pathway to one-line server 'nerdvanna be to:

(1) Install Python 3

(2) Create a folder to serve as the "staging area" for your web server effort, complete with a `cgi-bin` sub-directory therein. (Python uses FAST-CGI, so there are no worries there!)

(3) Open a command-line prompt, navigate to said folder, and execute the following:
python3 -m http.server 9000 --cgi --bind 127.0.0.1
(We use port 9000 for obvious reasons)

Once completed, your basic one-line server will be accepting requests at http://127.0.1:9000 on your computer. To view the same, simply open your browser & navigate to the URL.

Next Steps


The next step would be to create an index.html in the folder, refresh that browser view ... and start developing your very own 'pythonic web application.


Sharing is caring!

--Randall


p.s. We should note that PHP can also do a similar:
$ cd MyWebFolder
$ php -S 127.0.0.1:9000
You can CLICK HERE for more info.

[ view entry ] ( 761 views )   |  permalink  |  related link
Server Side Python3: Simple CGI Dump 
This Holiday's project saw us hacking the AWS so as to serve-up some hot & spicy LAMPy.

Submitted for your approval, here is a little something you might also need to know:

#!/usr/bin/python3
import os
from urllib import parse
import cgitb

cgitb.enable()
print("Content-Type: text/html;charset=utf-8")
print()

values = {
"DOCUMENT_ROOT" : "Server's Root Directory",
"HTTPS" : "'on' if using HTTPS",
"HTTP_COOKIE" : "Visitor cooky, if set",
"HTTP_HOST" : "Host Origin / URL",
"HTTP_REFERER" : "URL of calling page",
"HTTP_USER_AGENT" : "Visitors Browser Type",
"PATH" : "Server System Path",
"QUERY_STRING" : "HTTP / GET Query String",
"REMOTE_ADDR" : "TVisitor IP Address",
"REMOTE_HOST" : "Visitor Host Name / IP Address",
"REMOTE_PORT" : "Visitor Web Server Port",
"REMOTE_USER" : "Visitor's username (for .htaccess-protected pages)",
"REQUEST_METHOD" : "Determine GET or POST operation",
"REQUEST_URI" : "The requested pathname (relative to the document root)",
"SCRIPT_FILENAME" : "The full CGI pathname",
"SCRIPT_NAME" : "The parsed pathname of the current CGI (document root-relative)",
"SERVER_ADMIN" : "The server's webmaster's email address",
"SERVER_NAME" : "The server's fully qualified domain name (e.g. www.soft9000.com)",
"SERVER_PORT" : "The port number for request",
"SERVER_SOFTWARE" : "Server & Software (e.g. Apache/2.4.18 (Ubuntu))"
}


for ref in values:
try:
print(ref, ": ", end='')
print(os.environ[ref])
except:
print(" undefined")

Designed to show-off the complete set of CGI variables used to bind just about everything into the server environment, here is what the above yielded on my AWS cloud today:
SERVER_NAME : ec2-00-00-00-00.compute-1.amazonaws.com
SCRIPT_NAME : /CgiValues.py
REMOTE_USER : undefined
PATH : /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
REQUEST_URI : /CgiValues.py?foo=bar&ned=pooyl
HTTP_COOKIE : undefined
HTTP_HOST : ec2-00-00-00-00.compute-1.amazonaws.com
SERVER_SOFTWARE : Apache/2.4.18 (Ubuntu)
HTTP_USER_AGENT : Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0
REMOTE_ADDR : 65.00.00.00
HTTPS : undefined
SERVER_ADMIN : webmaster@localhost
DOCUMENT_ROOT : /var/www/html
HTTP_REFERER : undefined
REMOTE_HOST : undefined
QUERY_STRING : foo=bar&ned=pooyl
SERVER_PORT : 80
REQUEST_METHOD : GET
SCRIPT_FILENAME : /var/www/html/CgiValues.py
REMOTE_PORT : 59860

I (obviously) changed the IP address to mostly 00's to keep it free from the planet's denial-of-service, self-accursed, nut-cases.


Cheers,

-Rn




[ view entry ] ( 987 views )   |  permalink

| 1 | 2 | 3 | 4 | 5 | Next> Last>>