Wednesday, March 9, 2011

From webhosting to VPS

Hi all,

I have started a migration of our startup-ish project from a basic webhosting at to a linode 512 account over at today, which is a VPS with root access and all the related perks. The project is Django based and uses MySQL as well as some C++.
I was really afraid of the configuration, but so far it is turning out quite easy, although I am a COMPLETE noob. The steps I took so far:

  • Use the one click StackScript - this installs essential components of your application stack, which is Apache with mod_wsgi, MySQL (other databases available too) and some other stuff
  • For database interface install phpmyadmin, which is immediately accessible when you point your browser to IP_of_your_linode/phpmyadmin
    sudo apt-get install phpmyadmin
    • Note here, that the DB itself is configured by the StackScript, so in the install pick the option that doesn't reinstall the database
  • Added some helpful aliases to ~/.bash_aliases (this gets automatically loaded on relog, or by typing bash, also you may need to change paths):
    alias memhttpd="ps -u $LOGNAME -o pid,rss,command | grep httpd | grep -v -e mpm | awk 'BEGIN {sum=0} {sum=sum+\$2} END {printf(\"%f MB\n\",sum/1024)}'"
    alias memtotal="ps -u $LOGNAME h -o rss | grep -e mpm -v | (tr '\n' +; echo 0) | bc"
    alias memtot="~/webapps/misc/mem/check_mem_console"
    alias memcheck="ps -u $LOGNAME -o pid,etime,rss,command | grep -v -e mpm"
    alias memcheckhttpd="ps -u $LOGNAME -o pid,etime,rss,command | grep httpd | grep -v -e mpm"
    alias apache_restart="/etc/init.d/apache2 restart"
    • Configure your virtualhosts. It is generally known that you should not serve static content with Django, so you should pick a directory outside of the Django folder and create a virtualhost record for it in:
      • Check generalsubdomains, ...
      • Don't forget to restart Apache to see the changes in configuration. You can do so by using the apache_restart alias we registered one step above
    • I have started adding some more StackScripts, which allow me to simplify some tasks (like starting a django project). To keep things clean, I created a folder ~/stackscripts, where I just copy them. Then for each, I add a line to the end of my .bashrc:
      . ~/stackscripts/scriptname
      which includes them in. Just type bash in the command line and enjoy. Especially neat feature is that bash auto-completes functions defined in .bashrc and you can tab over them. Nice!
    • Now this is no longer chronological, but next tip is that if you install a library like OpenCV, that you intend to use with python, you will need to put the OpenCV/lib folder in the python path (sys.path). For this, I found that the easiest thing to do is to put a .pth file in a folder that already is in the python path and list folders you want to add each on a separate line. Then upon execution of python, these folders get added to sys.path by
    • ... to be continue

    No comments:

    Post a Comment