How to run a Django Project on a Personal Run Server - python

I've been wanting to run my own server for a while and I figured that running one for my django website would be a good start. What do you recommend I use for this? I've been trying to use a Ubuntu Virtual Machine to run it on one of my old laptops that I don't really use anymore until I can buy a dedicated server.
Should I run it from a Virtual Machine? If so, would Ubuntu be best? That appears to be the case, but I want to be sure before I invest in anything. I want to be able to access the website from other computers, just like any other website. Am I going about this wrong? If so, what can you suggest me?

Yes, you will need a static IP address.
If this is your first experiment, my advice would be:
1) Use an old, dedicated PC with no other stuff on it. Unless you do it just right, you should presume hackers could get anything on the disk...
2) Why make life complex with layer after layer of software? Install Ubuntu and run a standard server under a Unix OS
3) Be very careful about the rest of your attached network. Even if the PC is dedicated, unless you properly managed port forwarding, etc., ALL of your computers could be susceptible to attack.
An old friend of mine discovered, back in the Napster peer-to-peer days, that he could basically go and read EVERYTHING on the hard drives of most people who had set up Napster on their computer.

It really depends on your requirements. Will you be accessing the website externally (making it public) or locally? Running Django from your laptop can work but if you are planning to make it public, you will need an external IP to point your domain to. Unless you have a business account, ISPs usually don't give static IPs to individual customers. Ubuntu would be a wise choice and you can run conda or virtualenv easily.
VPS are quite cheap these days. You can look into AWS free tier that provides you with 500 hours/month on a micro server.
If you are planning to access your website internally then you don't need anything other than your laptop or perhaps raspberry pi. If you are trying to make it available for everyone on the external network, VPS would be the best bet.

Currently, and this changes often, I like to either setup a local development environment using virtualenv (to install dependencies) and Ngrok (to expose machine to an external address) or C9.io. If you want further info about setup, I'm happy to provide.

As already stated Ubantu is a good choice but there is also Debian. I use Debian because I started off working with a colleague who was already using it and I find it very good. I began with an old, disused desktop PC which I nuked and turned into a proper linux server. For development I didn't need a very high spec machine. (Think it has 1 GB ram) I have it set up in my flat and my domestic internet connection is fine for most of my needs. Note: It isn't necessary to have a static IP address for development, although it is preferable if you already have one. As an alternative you can use a service such as dnydns.org where you can set up virtual domain names that point to your domestic dynamic IP address. Most routers these days have facilities within them for updating services like dyndns.org with your new dynamic IP address or you can install a plug-in to your server that will do this for you. All my projects have their own virtualenvs and I have VNCServer installed so I can access my server and work from anywhere where I have an internet connection. I've been running this way for the past three years with some household name clients and haven't had any issues at all.
When it comes to production you can simply use any of the many VPS services that are out there. Amazon has already been mentioned. Someone recommended creating a droplet at DigitalOcean.com as I was wanting to host django applications and I find them to be very good and cost effective. Anyway just my 2 cents worth...hope it helps

Related

How to make a website work with Django development server?

I understand that this is never to be done. But I have a situation where I need to get something done real quick. I have to do a website where may be 200 people would register for an event. I need to present a simple registration form. Very basic functionality, register and view list of registrants. Very few hits. It would be live for about a month or so.
I know a little bit of Django which can allow me to put together this thing quickly. However, I have only worked with the Django development server.
My problem is setting up Apache to work with Django. I understand that, for Django, I need mod_wsgi installed. I have a VPS but mod_wsgi is not installed. I have asked my hosting provider to install it for me. Even if I can get mod_wsgi installed, it appears that it may take me some time to configure it and it may take a while.
I have the following questions.
Can I run this website on the Django development server? Will it hold up for very light traffic?
If I do, how do I get traffic to go from port 80 to the development server port. From the landing page, I can have the port number added to all the subsequent URLs.
I would also appreciate some guidance on getting Django to work with mod_wsgi.
Thanks
I use cloud9 for development. It is essentially a cloud ubuntu 14 virtual box, so it gives you a real url when django server is running (on port 80). Another use case of cloud 9 is for university classes, which is similar to your event use case. You can go there and setup your django project for free and people can find the page normally. But there are some restarts in your workspace that prevents it to be real server. If you pay 20 bucks per month they give you 2 premium workspaces that they assure that this does not happen ever. But I'm not sure if this is a good idea. I could not even imagine what kind of errors would you get if all 200 people chose to login at the same time, for example.
Another way to go is making a free amazon AWS account (or digital ocean) and doing your deploy there. AWS have 1 year free trial if you run only one microinstance with a particular setup which is plenty of time for your use case. I open the instance on AWS and SSH into it with cloud 9, so it feels like developing even in production. I'm far from a devops expert but I could deploy Nginx, gunicorn, django in AWS following this tutorial. You can do it too for sure, but is a lot of work.
Left my prefered choice for your use case to the end: pythonanywhere. It has free trial and it's really easy to setup. You follow some very basic steps (doing stuff with mod_wsgi that I still dont understand) and make it work in minutes. It's a whole business dedicated to serve python programs.
Hope this helps

Can Python server code be read?

I am working on a Python WebSocket server. I initiate it by running the python server.py command in Terminal. After this, the server runs fine and actually pretty well for what I'm using it for. The server runs on port 8000.
My question is, if I keep the server.py file outside of my localhost directory or any sub-directory, can the Python file be read and the code viewed by anyone else?
Thanks.
It is hard to give a definite yes or no answer, because there are a million ways in which your server may expose the .py file. The crucial point is though, that your server needs to actively expose the file to the outside world. A computer with no network-enabled services running does not expose anything on the network, period. Only physical access to the computer would allow you access to the file.
From this absolute point, it's a slow erosion of security with every additional service that offers a network component. Your Python server itself (presumably) doesn't expose its own source code; it only offers the services it's programmed to offer. However, you may have other servers running on the machine which actively do offer the file for download, or perhaps can be tricked into doing so. That's where an absolute "No" is hard to give, because one would need to run a full audit of your machine to be able to give a definitive answer.
Suffice it to say that a properly configured server without gaping security holes will not enable users to download the underlying source code through the network.

Host python bottle framework webpage

I'm developing an aplication built on the python Bottle framework. It's amazing and i want to host it somewhere, but of course i need a service where i can run the server.
What are the best options available (on costs too)?
Thanks!
I work for PythonAnywhere, a Python hosting company, so obviously I think we have a great Bottle hosting solution -- check it out :-)
Some of our competitors -- ones where we feel proud if a customer leaves them to move to us, or where we don't feel too depressed if they leave us to go to them, are Webfaction, Heroku, and (if you don't mind doing OS maintenance yourself and setting up your own front-end webserver) Digital Ocean and Amazon Web Services.
There are definitely other good hosts, but those are the ones that spring to mind.
The easiest way to host is use Ngrok ,its an open source tool where use get a temporary link where you can access your local host server on any machine through that link .you can download it from here https://ngrok.com/

Creating and deploying a python chat application using Twisted

I have created a chat server application using the Twisted framework. I am running it on my local machine and now I want to go global. The application is similar to omegle.com.
How can I develop on a third party commercial server so that it runs continuously?
Do I need to get a dedicated server for it?
As per this SO answer,
You can deploy Twisted on any hosting
provider who gives you a shell prompt
and doesn't limit your long-running
processes.
Some examples that I've used include:
Tummy ltd. and Slicehost.
The hosting server need not be dedicated, in other words, as long as those conditions are met (and of course as long as you have enough quota of RAM, disk, bandwidth, etc, for your purposes).
Take a look at Python friendly hosts to get an idea of what is available and what it will cost you. Typically, you could get away with a shared hosting package as long as you have a shell. However, if your program begins serving tons of clients, you might need to move it to a dedicated host.

For Python support, what company would be best to get hosting from?

I want to be able to run WSGI apps but my current hosting restricts it. Does anybody know a company that can accommodate my requirements?
My automatic response would be WebFaction.
I haven't personally hosted with them, but they are primarily Python-oriented (founded by the guy who wrote CherryPy, for example, and as far as I know they were the first to roll out Python 3.0 support).
I am a big fan of Slicehost -- you get root access to a virtual server that takes about 2 minutes to install from stock OS images. The 256m slice, which has been enough for me, is US$20/mo -- it is cheaper than keeping an old box plugged in, and easy to back up. Very easy to recommend.
Plug plug for PythonAnywhere, our own modest offering in this space.
We offer free hosting for basic web apps, with 1-click config for popular frameworks like Django, Flask, Web2py etc. MySql is included, and you also get full suite of browser-based development tools like an editor and a console...
I have been using WebFaction for years and very happy with the service. They are not only python oriented. You should be able to run anything within the limitations of shared hosting (unless of course you have a dedicated server).
They are probably not the cheapest hosting service though. I don't know the prices. But I can still remember very well my previous hosting provider was unreachable for a week (not their servers, I mean the people).
I've been pretty happy with Dreamhost, and of course Google AppEngine.
Google App engine and OpenHosting.com
Have virtual server by OpenHosting, they are ultra fast with support and have very high uptime.
Check out http://pythonplugged.com/
They are trying to collect information on Python hosting providers using variuos technologies (CGI, FCGI, mod_python, mod_wsgi, etc)
I advise you to have a look at http://www.python-cloud.com
This PaaS platform can automatically scale up and down your application regarding your traffic. You can also finely customize if you want vertical, horizontal or both types of scalability. The consequence of this scaling is that you pay as you go : you only pay for your real consumption and not the potential one.
Deployment via git.
Non AWS, hosted in tier-4+ datacenters.
Free trial ;)
I use AWS micro server, 1 year free and after that you can get a 3 year reserved which works out to about $75/yr :) The micro server has only 20MB/sec throughput, ~600MB of ram, and a slower CPU. I run a few Mezzanine sites on mine and it seems fine.

Categories

Resources