Site Sponsors:
Python3 and Apache - Whose there yet? 
If you are a Python 2.7 developer whom is putting off learning Python 3, you are not alone. While a gentle enough learning curve, there are enough internationalization & conventional code changes so as to send allot of code back into the R&D queue...

Surprisingly, when it came to discovering whom - at the time of this telling - had already bitten that hard-to-swallow conversion bullet, I was surprised to discover that Ubuntu's Server currently has absolutely THE BEST & total default support for Python 3 out-of-the box! (Made the mistake of un-installing Python 3 on a 16.04 Desktop a few months back & almost ruined my weekend. =)

LAMP-Py?


Unlike a Pythonic update however, there shall probably never be a need to install mod-python - by default - on any Apache Server.



Yet - while ever ready to use the classical L.A.M.PHP stack, updating Apache2 to favor the use of the L.A.M.Python (LAMPPy = "Lamp-eye"?) stack on Ubuntu 'aint all that tough.

Enabling Python


Since Python3 is installed on Ubuntu Server (16.04 remains the LTS vogue for 2017), we only need do the following:

(1) A multi-threaded MPM shalt require:

sudo a2enmod cgi


(2) Creating a cgi-bin for the default site will require:

mkdir /var/www/cgi-bin


(3) Updates to the /etc/apache2/apache2.conf shalt require:

<Directory /var/www/cgi-bin>
Options ExecCGI
SetHandler cgi-script
</Directory>


(4) Updates to the each .py folder definition in the apache2.conf shalt require:

<Directory /var/www/html>
Options +ExecCGI
AddHandler cgi-script .py
</Directory>


(5) After saving the above to apache2's apache2.conf, your first CGI Python (/var/www/html/index.py?) program should look something like:

    #!/usr/bin/python3
import cgitb
cgitb.enable()
print("Content-Type: text/html;charset=utf-8")
print() # Yes Veronica - an empty newline IS required! =)
print("Hello Web-World!")
... and don't forget the chmod...

(6) Since we are talking R&D here, just reboot the locus to get your R&D things going again. (When we are the only user & the IP endpoint is glued down, a reboot seldom hurts ;)

Failing the jous of having the luxury of ye olde R&D mode, then:

sudo service apache2 restart


(7) After Apache2 has re-started, browsing to the server's http://IP-address/index.py will show off your "Hello" in relatively short order.

(*) BTW - We should note that Ubuntu Server is also supported on AWS ... am renting my latest R&D site for under $10 / month. -Yours could be free for a year...

Unlike the official distro, if you are planning on using AWS, note also that while Python 3 is en pester, that Apache2 is not installed. --All save Port 22 shalt also tightly locked down be... so 'ya can't even Ping your server until one updates the associated, inbound, AWS security profile =)


Sharing is Caring!

-Rn


(p.s. If you get stuck, the default location for your error.log shalt be in /var/log/apache2.)


[ add comment ] ( 272 views )   |  permalink  |  related link

<<First <Back | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Next> Last>>