Web Tech - Wed Feb 14
Jim says: looks good - I like the writeup. Keep it up.
You are absolutely right about debugging dynamic web stuff - it can be a PITA. Python's "import cgi" can help; there's an option to have errors go to the web page. Many other frameworks have their own versions of a debug mode. The apache log files may be a help.
In my office we talked about cookies - here's a copy of the email I sent you.
You might want to check out Learn Enough Text Editor to be Dangerous .
Things We did for Jim last week:
- Followed this tutorial after registering on linode: https://linode.com/docs/web-servers/apache/apache-web-server-on-ubuntu-14-04/
- Followed these tutorials to set up the DNS on linode https://linode.com/docs/networking/dns/dns-records-an-introduction/ and https://linode.com/docs/networking/dns/dns-manager-overview/
- Had some trouble getting the hostname to match and a few other things that involved editing config and setup files, did some googling - this result was helpful: https://askubuntu.com/questions/59458/error-message-sudo-unable-to-resolve-host-user
- Spent a lot of time figuring out how to move around on our webserver and edit files
- Tried installing atom before realizing an IDE wouldn’t really work and then worked on learning vim
- To log on to our server in terminal - ssh nate@leslienate.tech when it asks for a password: Happy2222
- To get around first cd / - then type ls to see home directory files and folders
- To open a file to edit type sudo vim
- Config file is in the home directory
- Index/html files are in var/www/leslienate.tech
- Python scripts are in /usr/lib/cgi-bin
Things We did for Jim this week:
- Read a bunch of tutorials on setting up cgi
- Practiced opening documents in vim, turning on syntax highlighting and moving around effectively https://www.linux.com/learn/vim-101-beginners-guide-vim
- Set permissions for the directory /usr/lib/cgi-bin to 755 with sudo chmod 755
- Created a file in cgi-bin called test.pl (all the examples We found were in perl) and gave it proper permissions
- Tried a few different config examples but settled on ScriptAlias "/cgi-bin/" "/usr/lib/cgi-bin/“ to enable cgi
- Encountered an error loading the page and troubleshot that by enabling the cgi module with this command: sudo a2enmod cgi
- Created a python file in cgi-bin called pythontest.cgi
- Read a few examples to properly create the headers and print hello-world - had to trouble-shoot the opening header - this one worked: #!/usr/bin/env python3
- Read through this tutorial on setting up a dynamic cgi page with a form input https://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/dynamic.html
- Spent a few hours trying to figure out how to properly hook up his example form - the major error was to keep trying to execute html in a cgi folder… once we figured out that we could just include the form in index.html and link it via action=“cgi-bin/pythontest.py” everything worked out
- Interestingly including the template file being called from the python text processing the form input in the cgi-bin folder wasn’t a problem because we were just calling the template in my additionForm.py file and outputting it there, not actually executing the html - this is what got us hung up for awhile.
- Moved the html into the python cgi to make it more self-contained
- Read through this tutorial: http://jayconrod.com/posts/17/how-to-use-http-cookies-in-python and this article: http://raspberrywebserver.com/cgiscripting/using-python-to-set-retreive-and-clear-cookies.html#disqus_thread changed the syntax to python 3
- Got cookie sessions being recognized and printing the session number
- Worked to create my own form asking for a name and saying hello to whoever submits the name using the example form as a template
- Got hung up trying to set up cookies with a python 2 module - wasn’t sure what was breaking our code - eventually figured out it was just the import statement on a deprecated module - import Cookie or from Cookie import SimpleCookie
- NEED BETTER DEBUGGING TOOLS!