The fact that the webserver works only after uploading a few times and not from the first time is strange behavior. Why don’t you try using Node .js? Node.js is easy to use in network applications. http://nodejs.org/ . You can also try doing the example in that website. Node.js is included in the SD card Linux image found in https://communities.intel.com/docs/DOC-22226 . You can also try doing your code in Python script, it has many libraries included and the webserver example is likely to work.
I will look into that, thanks for the suggestions.