Call me a sucker, but I love a good server setup as much as the next guy, I just have a little trouble setting it up sometimes. So I thought I’d walk through my process for setting up all this Django goodness on what is basically a LAMP setup (where “P” stands for Python!) with a few extras like memcached and ufw. We’ll get to a level of general security, but not prefect security.
Also, we’ll keep this well within the 360 megabytes allotted for the cheapest Linode. Before we get underway, just create a new Linode with Ubuntu 10.04 (32-bit), set your password. Alright, let’s get going!
Initial Setup
First thing to do is log in via the standard SSH on your Linode’s IP, port 22, and with rootas your username. We’ll change the login user away from root, but for now, this will do (plus we can skip all that sudo stuff). First, let’s update and upgrade the system.
First thing to do is log in via the standard SSH on your Linode’s IP, port 22, and with rootas your username. We’ll change the login user away from root, but for now, this will do (plus we can skip all that sudo stuff). First, let’s update and upgrade the system.
Awesome, you should be 100% up-to-date. Now its time to get to the fun part, let’s installsome of the software we’ll be using! Below are the commands to install Apache, MySQL, mod_wsgi and the python MySQL bindings, as well as memcached and ufw. If you have any prompts for passwords, you know what to do! Just remember what you set them as.
Really quickly, let’s get python-memcached installed (alternatively, if you need some raw speed, look up cmemcached or python-libmemcached). This will take a few steps…
Now its time for Django! Django 1.1.1 is a lot easier to install than Django 1.2.4:
But let’s say we need Django 1.2.4: its gonna take a few more commands to make this happen. Watch out for that last command, anytime you use
rm -r
you can run into real trouble if you mistype (but we’re not production yet so no worries, right?).
Actual Configuration
Let’s work backwards, we’ll start with the easy stuff and work our way to the more complicated things. Let’s get ufw and the SSH port out of the way first. Go ahead and pick a number between 1024-8000ish for the port we will eventually; I chose 5555 but youcan should use something else.
Let’s work backwards, we’ll start with the easy stuff and work our way to the more complicated things. Let’s get ufw and the SSH port out of the way first. Go ahead and pick a number between 1024-8000ish for the port we will eventually; I chose 5555 but you
Now that you have ufw and SSH locked down, its time to move onto setting upmemcached (which is super easy). We’ll just run it as root and be done with it (you will need to repeat this command on each boot):
Alright, with that out of the way, let’s get MySQL nice and tight. The standard install of MySQL can suck up a lot of memory, so we’ll suggest a few ways to lighten the load:
Now let’s get a new user setup and leave behind this root nonsense for safety’s sake. Your username is going to be bobby for this example. Replace bobby everywhere if you want something different.
It’s time for the nitty gritty stuff: setting up Apache and mod_wsgi with Django for the domain you own called examplesite.com (creative, I know). We need to make apublic_html folder in bobby’s home folder and place a folder called examplesite.com (as well as a few more). We’ll do that first.
Right now you should place your Django project into the public_html/examplesite.comfolder. For example, if the project is housed in demoproject (eg: demoproject/manage.py, demoproject/urls.py, etc.) you’ll want it placed ALApublic_html/examplesite.com/demoproject. Time to get the Apache config files up and running. Here we go!
First, in the demoproject.wsgi file you should paste and save:
We’re so close, let’s get the other Apache files setup. Oh, and don’t worry about thatwww-data thing just yet, we’ll get to that in a second.
Place the text below in the examplesite.com config file (remember the www-data part from the last command?). You can modify the threads and processes numbers to suit your moods and load.
A few more final things:
Time to admire your handiwork.
Congrats! You’re all set up and ready to roll! Nothing can stop you now! Here’s a neat command to measure your memory usage as mine rarely gets over 160mb. This gives lots of room for growth as you can always increase the memcached size, MySQL settings, and Apache/mod_wsgi instances/threads.
Also, under Ubuntu 10.04 (Lucid), Python’s site-packages is now called dist-packages. Just a FYI.
No comments:
Post a Comment