This is my old website presence for back date links compatability. Please click here to go to our new look. Or, you will be redirected in a minute.

Environment used

Ubuntu 18.04.5 LTS  GNOME 3.28.2   OS type 64bit

So, before I begin you should mainly have apache installed of above said version on your pc.

I assume here following:
1. the root folder of apache web server is /var/www/html/
2. the apache configuration folder is /etc/apache2
3. YOURUSERNAME is to be replaced by username of your ubuntu installation.
4. You know how to create/edit a file in text editor on linux
5. You know how to create a link on linux
6. You have prior experience of installing programs in linux via command line.
7. You can access your webserver via browser with
8. You know how to restart apache server on linux pc.

Step 1 :  Install python

         sudo apt-get install python

Step 2 :  Install mod_wsgi

        sudo apt-get install apache2-utils ssl-cert libapache2-mod-wsgi 

Now restart apache

Step 3 :  Configure the apache to run python scripts with mod_wsgi Module
Open terminal and move to apache server root folder and run  
        sudo mkdir pythonscripts
        sudo chmod -R 755 /var/www/html/pythonscripts/
        sudo chown -R YOURUSERNAME:www-data /var/www/html/pythonscripts/

Now go to  conf-available folder of apache configuration
and create file pythonscripts.conf

Add following lines in the file and save.

WSGISocketPrefix /var/run/wsgi
WSGIDaemonProcess pythonscripts user=YOURUSERNAME threads=15
WSGIProcessGroup pythonscripts
WSGIApplicationGroup %{GLOBAL}
AddType text/html .py

<Directory /var/www/html/pythonscripts/>
    Order deny,allow
    Allow from all

Now create a link with same filename in conf-enabled folder of apache configuration

Now edit 000-default.conf in sites-available folder of apache configuration

and add following lines

    WSGIScriptAlias /pythonscripts /var/www/html/pythonscripts/
    Alias /pythonscripts/static /var/www/html/pythonscripts/static/

Now restart apache

Step 4 :  Create your first python web page

Now go to pythonscripts folder of web server root

Create a file and add following lines of code and save.

def application(environ, start_response):
    status = '200 OK'
    output = b'Hello World!\n'
    response_headers = [('Content-type', 'text/plain'),
                  ('Content-Length', str(len(output)))]
    start_response(status, response_headers)
    return [output]

Once again run
        sudo chmod -R 755 /var/www/html/pythonscripts/
        sudo chown -R YOURUSERNAME:www-data /var/www/html/pythonscripts/

Navigate to in your browser.

You will see Hello World!

This is very basic of python and your first web page in python. But python is vast language. It is used on different plans. For more info please look into the following videos.

You may be thinking that why I am not giving complete details about above commands. This is because this article is for developers who are working on apache with some scripting language like php, etc. Audience of that level will understand these commands with not much effort.

Ok Readers! Bye for now. More will come but please help me to keep me out of shackles of poverty. For this please pay a small amount of money of your choice on my payment page. I will keep putting articles here. --- Dheeraj



Learning Path For Python Web Development | Python Tutorials For Absolute Beginners In Hindi #97

Views: 85852
Learning Path For Python Web Development | Python Tutorials For Absolute Beginners In Hindi #97

Views: 0