Showing posts with label Apache. Show all posts
Showing posts with label Apache. Show all posts

Wednesday, December 13, 2017

Starting Out (and pulling my hair out) with Flask

Recently I started learning the Flask web framework.  Mostly because I have been doing a bunch of Python coding and would like that to bleed over a bit into the web development arena.  The need is not really out of anything work-related, its more of a personal project need.

I can say, though, that getting apache and Flask operating together has certainly added a few grey hairs to my head, mostly in frustration.  There are plenty of resources ( if you search the Googles) for setting up Apache web server and Flask, to work together.  But I have to say that, as great as the resources that are out there, are, there are a few (pertinent) details that were left out of most of them that I will now cover.

First, working in a Virtual Environment does not have all of the same settings as not working in one.  If you look at this link, you will see (near the bottom of the document) that there are a couple of things you have to set in your .wsgi file, to specify the load paths for your virtual environment. 
NOTE: It is important to note that that link is the same root site for the Flask link above.  So they definitely have a lot of documentation on their product.

Now, while the above is important, it didn't solve my issue, which is that on a machine remote to where I am running my Flask app and web server, I was not able to go to http://:5000 (the port Flask runs on) and see the page displayed as expected.  Instead I received a typical error page stating that the page could not be loaded.  This got even more frustrating with each new thing that I tried or modified to get it working.  No matter how seemingly possible of a fix, it didn't work.  Until.....

I found a StackOverflow thread about running a Flask app under the Apache web server.  I read the person's question and went through their code (seeing all the similarities) and there it was... a setting that no other site had mentioned.  Not even the video tutorial I was going through.  It was part of my Flask app's __init__.py file and the part in question looks like this:
app.debug = True
app.run(host='0.0.0.0')
The first line is inconsequential and just turns on debug mode.  The second line was 1/2 different from mine, but crucially different.  I had the app.run() that all the tutorial's had mentioned, but I did not have the host='0.0.0.0' portion.  I put it in, started up Flask (by running the __init__.py file) and VOILA!!!  I had the output that I expected to see in my browser. 

Needless to say, it was certainly a learning experience ( as I now have plenty of notes for running a Flask app with Apache).  Now I can get on with my learning of the Framework since the tedious job of getting the web page serving is now out of the way.  Yay!



Friday, October 24, 2008

The [sometimes] trouble with updates

No, I am not referring to Windows updates. Instead, I am referring to Linux updates. There are mixed views on whether you should do updates or not on your system(s). Here is my view.... if it is a server, update it ONLY when you are absolutely needing to. This means only if there is a security hole that is fixed by a newer version. On the other hand, if it is a desktop system, if you update then it is up to you.

If you do updates though, you really need to watch out. Make sure you know what exactly is happening during the update(s) as things tend to change and also stop working.

I did an update earlier this evening after booting up my laptop. No worries, right? Wrong. When I tried to start my apache web server (which was previously installed and working fine), I discovered that it was no longer working. Strange if you ask me, but it wasn't starting up. It kept giving me the same errors:

# /etc/init.d/apache2 start
* Starting web server apache2 [Fri Oct 24 22:15:10 2008] [warn] module php5_module is already loaded, skipping
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs

I started by plugging in the different errors into Google, but kept going in directions I didn't think were the answer. Then I looked at the last error: "Unable to open logs". That was odd because I hadn't changed anything, but...... then there was the updates.

So I checked and the /var/log/apache2 directory and saw that it was owned by root and had a group of adm. I distinctly remember that being the group root the other day. So, instead of changing permissions (which is someting I was not wanting to do, I decided to add root to the adm group.

I restarted apache and VOILA!!! Problem fixed. So, the lesson.... know what updates are being applied and if something doesn't work afterwards, you will at least know why.

Reblog this post [with Zemanta]
 
Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.