How to configure python with apache in ubuntu?

Common Gateway Interface(CGI) helps you run python application in apache webserver in ubuntu. Follow the steps which help you to configure python with apache webserver.

Step 1:

[code] sudo mkdir /var/www/python [/code]

Step 2:

[code] sudo vim /etc/apache2/sites-available/default [/code]

Step 3:

Add the following lines in “default” file and save the file.

[code]
ScriptAlias /python/ /var/www/python/
<Directory "/var/www/python">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all

[/code]

Step 4:

Restart the apache server to reflect the changes you made in apache configuration file.

[code] sudo /etc/init.d/apache2 restart [/code]

Step 5:

Now can run your python file under this directory “/var/www/python”

[code] sudo vim /var/www/python/hello.py [/code]

Add these lines in your ‘hello.py’ file to test python is configured correctly

[code]
#!/usr/bin/python
print "Content-type:text/html\r\n\r\n"
print ‘<html>’
print ‘<head>’
print ‘<title>Hello Word – First CGI Program</title>’
print ‘</head>’
print ‘<body>’
print ‘<h2>Hello Word! This is my first CGI program</h2>’
print ‘</body>’
print ‘</html>’
[/code]

Step 6:

Before running your python file under this directory, make sure you have chage mode of file using chmod 755.

[code] sudo chmod 755 hello.py [/code]

Step 7:

Now you can request the page url in browser to load the python

[code] http://localhost/python/hello.py [/code]

Permanent link to this article: https://blog.openshell.in/2013/03/how-to-configure-python-with-apache-in-ubuntu/

how to install easy_install in ubuntu?

To installing easy_install in ubuntu is very easy, just follow the instructions below.

[code]
$ sudo apt-get install python-setuptools
[/code]

And that’s it! Yes, that’s all you need to do and you will have easy_install available at the command prompt.
In case you are wondering, easy_install is a Python module which comes as a part of the Python setuptools, so installing setuptools automatically installs easy_install along with it. easy_install is used for installing and managing Python packages.

Permanent link to this article: https://blog.openshell.in/2013/03/how-to-install-easy_install-in-ubuntu/

How to use multi-line comment in python?

Python doesn’t have a multi-line comment. Most people who want to do a multi-line comment just use triple quoted strings.

[code]
”’ for example
you could do
something like this
as a multi-line comment ”’
[/code]

But personally, I will do it like this:

[code]
# This
# is
# a
# multi-line
# comment
[/code]

Permanent link to this article: https://blog.openshell.in/2013/03/how-to-use-multi-line-comment-in-python/

How to install MySQLdb module in python

To install MySQLdb module in python, download it from MySQLdb Download page

Finally, execute the following command to configure mysqldb with python:

[code]
$ tar xfz MySQL-python-1.2.4b4.tar.gz
$ cd MySQL-python-1.2.4b4
$ # edit site.cfg if necessary
$ python setup.py build
$ sudo python setup.py install # or su first
[/code]

Permanent link to this article: https://blog.openshell.in/2013/03/how-to-install-mysqldb-module-in-python/

Fatal error: Python.h: No such file or Directory

When i tried to build mysql connector for python got the below error:

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,4,’beta’,4) -D__version__=1.2.4b4 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -g
_mysql.c:29:20:
fatal error: Python.h: No such file or directory
compilation terminated.
error: command ‘gcc’ failed with exit status 1

Where can I find Python.h file and how do I fix this problem under Debian or Ubuntu Linux sever based system?

Python.h is nothing but a header file. It is used by gcc to build applications. You need to install a package called python-dev. This package includes header files, a static library and development tools for building Python modules, extending the Python interpreter or embedding Python in applications.

To install this package, enter:

[code]sudo apt-get install python-dev[/code]

Permanent link to this article: https://blog.openshell.in/2013/03/fatal-error-python-h-no-such-file-or-directory/

How to install python in ubuntu

Install python in ubuntu machine by follow the below steps, Which helps to install all necessary packages needed.

1) To be able to compile Python Source, you will need few packages. Open terminal and execute this command

[code]sudo apt-get install build-essential gcc libncursesw5-dev libreadline-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev[/code]

2) Then execute this command to install python

[code]sudo apt-get install python python-dev[/code]

Permanent link to this article: https://blog.openshell.in/2013/03/how-to-install-python-in-ubuntu/

Install Java plugin in mozilla firefox

Install Java plugin in mozila firefox

  • Go to the download page at java.com.
  • Click the Free Java Download button.
  • Click the Agree and Start Free Download button to download the Java installer to your computer.
  • After the download is complete, close Firefox.
  • Open the file you downloaded to start the Java installation.

For more information visit: https://support.mozilla.org/en-US/kb/use-java-plugin-to-view-interactive-content

Permanent link to this article: https://blog.openshell.in/2013/03/install-java-plugin-in-mozilla-firefox/

How to install Adobe Air in Ubuntu 12.04?

This steps will help you to install adobe air in ubuntu 12.04.

In terminal, run the following command one by one:

sudo apt-add-repository “deb http://archive.canonical.com/ $(lsb_release -sc) partner”

sudo apt-get update && sudo apt-get install flashplugin-installer

Next, run the commands below to download Adobe Air executable.

wget http://airdownload.adobe.com/air/lin/download/2.6/AdobeAIRInstaller.bin

Then run the commands below to change the permission on the file so that it’s executable.

sudo chmod +x AdobeAIRInstaller.bin

for run the commands below to install Adobe Air.

sudo ./AdobeAIRInstaller.bin

If everything works, all should be installed.

Note:

If you get this problems with adobe Air about missing gnome-keyring or KDE Wallet, run the commands below to fix it, then re-run the air installer.

For 32 bit –

sudo ln -s /usr/lib/i386-linux-gnu/libgnome-keyring.so.0 /usr/lib/libgnome-keyring.so.0

sudo ln -s /usr/lib/i386-linux-gnu/libgnome-keyring.so.0.2.0 /usr/lib/libgnome-keyring.so.0.2.0

For 64 bit –

sudo ln -s /usr/lib/x86_64-linux-gnu/libgnome-keyring.so.0 /usr/lib/libgnome-keyring.so.0

sudo ln -s /usr/lib/x86_64-linux-gnu/libgnome-keyring.so.0.2.0 /usr/lib/libgnome-keyring.so.0.2.0

Permanent link to this article: https://blog.openshell.in/2013/02/how-to-install-adobe-air-in-ubuntu-12-04/

How to install pear php in ubuntu?

Installing pear php in ubuntu machine helps  you to use existing libraries to make our development easy.

In terminal, run the following command:

[code]

sudo apt-get install php-pear

[/code]

Permanent link to this article: https://blog.openshell.in/2013/02/how-to-install-pear-php-in-ubuntu/

Loop mysql result set multiple times or twice in php

First we will select something from the database and loop through it like so:

[php]
$result = mysql_query("SELECT * FROM my_table");
while($row = mysql_fetch_assoc($result)) {
// inside the loop
}
[/php]

Problem:

if you want to loop through the same result set again, you will get an error because the internal pointer is currently at the end of the result.

Solution:

we need to put the pointer back at the beginning of the result set so that it can loop again.

For mysql,

[php]
mysql_data_seek($result, 0);
[/php]

For mysqli,

[php]
mysqli_data_seek($result, 0);
[/php]

Now we got solution for this problem.
[php]
mysql_data_seek($result, 0); // set the pointer of the result set back to the beginning.
while($row2 = mysql_fetch_assoc($result)) {
// inside the loop
}
[/php]

Permanent link to this article: https://blog.openshell.in/2013/01/loop-mysql-result-set-multiple-times-or-twice-in-php/