Wednesday, November 25, 2015

VirtualBox Guest: Ubuntu 15.10 Python Development Server

I am now using Ubuntu 15.10 and Python 3 as a professional developer. The development environment is located in a VirtualBox running Ubuntu 15.10 Server almost bare-bones, ONLY pre-installed with OpenSSH server.

Let's prepare the development environment with the latest Django 1.9 using Python 3.5, GIT and VirtualEnvWrapper. I recommend using MobaXtexm to login into your Vbox using SSH keys.

Update Ubuntu to the latest patches and security updates and improvements:
sudo apt-get update; sudo apt-get upgrade
sudo apt-get install build-essential python2.7 python2.7-dev python3.4 python3.4-dev python3.5 python3.5-dev
sudo apt-get install mysql-server mysql-client
sudo systemctl status mysql
sudo apt-get install apache2
sudo systemctl status apache2
sudo apt-get install python2.7-mysqldb python3.4-mysqldb python3.5-mysqldb libmysqlclient-dev
sudo apt-get install sqlite3 libsqlite3-dev libreadline6-dev libgdbm-dev
sudo apt-get install zip zlib1g-dev libbz2-dev
sudo apt-get install python-pip python3-pip
sudo apt-get install git virtualenv virtualenvwrapper
Add python alternatives for more flexibility:
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 10
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.4 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
Make sure all is in it's place:
sudo apt-get update; sudo apt-get upgrade
Modify file .bashrc for VirtualEnv use:
vim ~/.bashrc
if [ -f /usr/local/bin/ ]; then
    export WORKON_HOME=$HOME/.virtualenvs
    source /usr/local/bin/
source ~/.bashrc
Now let's create the working environment:
mkvirtualenv some-project-name
pip3 install Django==1.9
Make sure we are running the intended version, start a python 3.5 session, import django and check the version:
>>> import django
>>> print(django.get_version())
Prepare to create the initial Django setup:
mkdir src; cd src
django-admin startproject some-project-name
cd some-project-name
python3.5 migrate
python runserver
We point out browser to the needed site to check (Virtual Box was previously setup for port forwarding):
Finally we setup a basic Git repo:
cd some-project-name
git init
git config --global 'Your Name'
git config --global your.address@your.provider

No comments: