Deployment On DigitalOcean for Python Flask project

>sudo apt install libapache2-mod-wsgi-py3

www>mkdir flaskapp

>cd flaskapp

>mkdir flaskapp

>sudo apt install python3-pip

>pip3 install virtualenv

>sudo virtualenv venv

>source venv/bin/activate

>pip3 install flask request pandas flask-slqalchemy

>cd /etc/apache2/sites-available

>cp 000-default.conf flaskapp.conf


>nano flaskapp.conf

Open flaskapp.conf and copy paste below code:

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.python-ds.com
ServerName python-ds.com
ServerAlias www.python-ds.com
ServerAdmin python.ds.com@gmail.com
WSGIScriptAlias / /var/www/flaskapp/flaskapp.wsgi
<Directory /var/www/flaskapp/flaskapp/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/flaskapp/flaskapp/static
<Directory /var/www/flaskapp/static/>
Order allow,deny
Allow from all
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
<Directory>

>sudo a2ensite flaskapp.conf

>service apache2 restart

>cd /var/www/flaskapp

>sudo nano flaskapp.wsgi

open flaskapp.wsgi and copy paste below code according to your need:

#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/flaskapp/")
from flaskapp import app as application
application.secret_key = '\xfd{H\xe5<\x95\xf9\xe3\x96.5\xd1\x01O<!\xd5\xa2\xa0\x9fR"\xa1\xa8'

>python3 __init__.py

>service apache2 restart

View More...

Deployment On DigitalOcean for php/html project

Step1: SSH Login for server access

$> ssh root@168.0.x.x.0

>cd home

>cd /

>adduser vishavjeet

>usermod -aG sudo vishavjeet

>ufw app list

>ufw status

>ufw allow OpenSSH

>ufw enable

>ufw status

>exit()

#login as vishavjeet

> sudo apt update

>sudo apt install apache2

>sudo ufw app list

>sudo ufw app info "Apache Full"

>sudo ufw allow in "Apache Full"

>sudo apt install mysql-server

>sudo mysql

>select user, authentication_strings, plugin, host from myqsl.user;

>exit

>sudo mysql -p

>exit

>sudo apt install php libapache2-mod-php php-mysql

#how can open default index.php

>nano /ect/apache2/mods-enables/dir.conf

<ifModule mod.dir>

Dir index.php index.cgi, ..index.html

...

>sudo service apache2 restart

>sudo apt install phpmyadmin php-mbstring php-gettext

>sudo phpenmod mbstring

>sudo service apache2 restart

>sudo mysql -p

>mysq>grant all privilleges en *.* 'vishavjeet'@'localhost' with grant option;

www>mkdir project_first

>ls -lart

>sudo chown -R $USER:$USER project_first

>ls -lart

project_first>nano index.html

>cd /etc/apache2/sites-available/

>cp 000-default.conf project_first.conf

>ls

000-default.conf project_first.conf

>sudo nano project_first.conf

<VirtualHost *:80>

ServevAdmin vishavjeet@tech-overflow.com

ServerName tech-overflow.com

ServerAlias www.tech-overflow.com

DocumentRoot /var/www/project_first

>

>sudo a2ensite project_first.conf

>sudo a2dissite 000-default.conf

>sudo service apache2 restart

>sudo apache2ctl config test

Step2:  Domain configuration in Goddady

A @ 192.241.142.132 600sec

Cname www @ h hours


View More...

How to make generator to produce N prime number?

def is_prime(num):

    for n in range(2, num):

        if num % n == 0:

            return False

    return True


# using Generator(Yield)

def generate_n_prime(num):

    i = 2

    while num:

        if is_prime(i):

           yield i

         num -= 1

      i += 1


it = generate_n_prime(10)

for i in it:

    print(i, end=' ')


#2 3 5 7 11 13 17 19 23 29

View More...

Write Python Program for N prime number?

def is_prime(num):

   for n in range(2, num):

        if num % n == 0:

           return False

    return True

def get_n_prime(num):

   i = 2

   prime_list = []

   while num:

      if is_prime(i):

         prime_list.append(i)

         num -= 1

      i += 1

   return prime_list


print(get_n_prime(10))

#[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]

View More...

List Of All Python Exception Classes

The class hierarchy for built-in exceptions is:

BaseException

 +-- SystemExit

 +-- KeyboardInterrupt

 +-- GeneratorExit

 +-- Exception( All given below Exception class are childs of Exception Class)

    +-- StopIteration

    +-- StopAsyncIteration

    +-- ArithmeticError

    |    +-- FloatingPointError  (Not currently used.)

    |    +-- OverflowError

    |    +-- ZeroDivisionError

   +-- AssertionError

   +-- AttributeError

  +-- BufferError

  +-- EOFError

  +-- ImportError

  |    +-- ModuleNotFoundError

  +-- LookupError

  |    +-- IndexError

  |    +-- KeyError

  +-- MemoryError

  +-- NameError

  |    +-- UnboundLocalError

  +-- OSError

  |    +-- BlockingIOError

  |    +-- ChildProcessError

  |    +-- ConnectionError

  |    |     +-- BrokenPipeError

  |    |     +-- ConnectionAbortedError

  |    |     +-- ConnectionRefusedError

  |    |    +-- ConnectionResetError

  |    +-- FileExistsError

  |    +-- FileNotFoundError

  |   +-- InterruptedError

  |   +-- IsADirectoryError

  |   +-- NotADirectoryError

  |   +-- PermissionError

  |   +-- ProcessLookupError

  |   +-- TimeoutError

 +-- ReferenceError

 +-- RuntimeError

 |    +-- NotImplementedError

 |    +-- RecursionError

 +-- SyntaxError

 |    +-- IndentationError

 |    +-- TabError

 +-- SystemError

 +-- TypeError

 +-- ValueError

  |    +-- UnicodeError

  |    +-- UnicodeDecodeError

  |    +-- UnicodeEncodeError

  |    +-- UnicodeTranslateError

   +-- Warning

     +-- DeprecationWarning

     +-- PendingDeprecationWarning

     +-- RuntimeWarning

     +-- SyntaxWarning

     +-- UserWarning

     +-- FutureWarning

     +-- ImportWarning

     +-- UnicodeWarning

     +-- BytesWarning

    +-- ResourceWarning

View More...

First Previous 10 11 12 13 14 Next Last