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 
OR 
pip3 install django==1.10

python
import django
print(django.get_version())

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/example.com/public_html

Step 2 – Grant Permissions

sudo chown -R $USER:$USER /var/www/example.com/public_html
sudo chmod -R 755 /var/www

Step 3 – Create new virtual host files.

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

 

Step 4 – Enable the new virtual host file

sudo a2ensite example.com.conf
sudo service apache2 restart

Step 5 – Set up local hosts file

sudo nano /etc/hosts
111.111.111.111 example.com

Step 6 – Test your results

http://example.com

Slim a micro framework for PHP

Installation

  • Instal composer
php -r "copy('https://getcomposer.org/installer', '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 https://getcomposer.org/installer | 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.
vendor/*
  • Create the application
    • create src/public.index.php file and add this code.
<?php
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;
});
$app->run();

 

  • 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