Python + Django

alias python=python3

This should work. Else try the code below as well.

sudo nano ~/.bash_aliases
alias python=/usr/bin/python3
update-alternatives --remove python /usr/bin/python2
update-alternatives --install /usr/bin/python python /usr/bin/python3

Install Django

sudo apt-get install python3-pip
which pip3
ln -s /usr/bin/pip3 /usr/bin/pip

pip3 install --upgrade pip

pip install django==1.10 
pip3 install django==1.10

import django

Install MYSQL for Python

sudo apt-get install python3-pymysql

Virtual Host configuration in Ubuntu 14.04

sudo apt-get update sudo apt-get install apache2

Step 1 – Create the directory structure

sudo mkdir -p /var/www/

Step 2 – Grant Permissions

sudo chown -R $USER:$USER /var/www/
sudo chmod -R 755 /var/www

Step 3 – Create new virtual host files.

cd /etc/apache2/sites-available
sudo cp 000-default.conf
sudo nano /etc/apache2/sites-available/
<VirtualHost *:80>
    DocumentRoot /var/www/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined


Step 4 – Enable the new virtual host file

sudo a2ensite
sudo service apache2 restart

Step 5 – Set up local hosts file

sudo nano /etc/hosts

Step 6 – Test your results

Slim a micro framework for PHP


  • Instal composer
php -r "copy('', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '92102166af5abdb03f49ce52a40591073a7b859a86e8ff13338cf7db58a19f7844fbc0bb79b2773bf30791e935dbd938') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"


Install Slim

  • Create you project folder and create these folders inside.
├── project
│   └── src
│       └── public
  • Go into the /src folder in your project directory and execute this command.
composer require slim/slim "^3.0"
  • Install composer.phar
curl -sS | php
  • To install dependencies, execute he composer.phar
php composer.phar require slim/slim
  • git ignore the vendor folder
    • Create .gitignore folder inside src/ and add this single line.
  • Create the application
    • create src/public.index.php file and add this code.
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

require '../vendor/autoload.php';

$app = new \Slim\App;
$app->get('/hello/{name}', function (Request $request, Response $response) {
    $name = $request->getAttribute('name');
    $response->getBody()->write("Hello, $name");

    return $response;


  • Run this command from src/public
php -S localhost:8080
  • Then go to http://localhost:8080/
    • This will show you an error. DO NOT WORRY. Use http://localhost:8080/hello/sugith

Run your application with Apache

  • Set the virtual host configuration.
  • Set the public folder as the Document Root
  • Add .htaccess file into src/public directory.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]


 Install dependencies

composer require slim/twig-view
composer require monolog/monolog