17 August, 2011

setup lamp server on debian/ubuntu || the easiest & the best way


The LAMP server is the commonly abbreated for Linux Apache MySql PHP server. This is a platform where web pages can be build/test/run using linux.

So setting up your LAMP server includes installing all those above said packages and configuring them to work together.

You can use either terminal or synaptic package manager to install these packages [and should have a working internet connection]. Anyway we may have to use the terminal for configuring them. So better move with the Terminal [Applications > Accessories > Terminal] itself.

1. Install Apache server

------------------------------
Below command will install apache server in your system


$ sudo apt-get install apache2

when the installation finishes, test weather it's working by pointing your web browser[firefox / chrome . . . ] to the following web address.
http://localhost/  

You should see a folder entitled apache2-default/. Open it and you will see a message saying something like > "It works!"

2. Install PHP

- - - - - - - - - - - - -

copy-paste the command given below onto a terminal and hit the enter key.


$sudo apt-get install php5 libapache2-mod-php5

While PHP installation finishes, restart the apache web server to make it compatible with apache using the following command.


$ sudo /etc/init.d/apache2 restart

testing PHP

To ensure there are no issues with PHP let's give it a quick test run.

Step 1. In the terminal copy/paste the following line:



$ sudo gedit /var/www/test.php

This will open up a file called test.php.

Add the following line into the test.php, save and close the file.


  <?php
      phpinfo();
  ?>


Now open you're web browser and type the following into the web address:



http://localhost/test.php


Note : You can change the location of the Document root [by default it is /var/www/] by reading this article.

Install MySQL
- - - - - - - - - - - - - - 

open up the Terminal and then copy/paste this line:


sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql


install phpmyadmin
-------------------------

 

sudo apt-get install phpmyadmin

Now just restart Apache and you are all set!



sudo /etc/init.d/apache2 restart


That's enough! your LAMP server  is ready, and now you can can move up with your pretty codes >>
Read rest of entry

01 February, 2011

a simple ftp program with python xmlrpc

Hope you have read my post about creating a simple client server program with python xmlrpc. Now we will  try creating a sample file transfer program through which we can transfer files (text, images, movie) over the network. The logic behind this is the same that we used in the client server program shown in the above link. The remote procedure call allows to call functions placed in a remote server, passing parameters to it and receiving return values from the remote function in the server. 

1. Sending a file to remote server 

       Inorder to send a file, say a picture file we first open the file and read it's contents. Then we call the remote function in the server with file content (of the picture) as parameter. The remote function on receiving this contents as parameters will open a new file and write it into that file...

Check the ftp client and server program below...

ftp client


   import xmlrpclib
   server = xmlrpclib.ServerProxy('http://127.0.0.1:9009')
   filepath=raw_input('Enter path to file :')
   try:
         with open(filepath, "rb") as handle:
            data=xmlrpclib.Binary(handle.read())
            handle.close()
            a=server.UploadFile(data
   except:
         print "Upload failed"



 ftp server :
 

   import xmlrpclib
   from SimpleXMLRPCServer import SimpleXMLRPCServer 
   def UploadFile(filedata):
        try:
            fp="/home/jo/Downloads/file2"
            with open(fp, "wb") as handle:
                    data1=filedata.data
                    handle.write(data1)
                    handle.close()
            return True
        except Exception,ex:
            return 'error'
   client.register_function(UploadFile)
   server.serve_forever()


2. Receiving a file from remote server 

         Here we call the remote function on the server with file path as the parameter, where file path is the path to the file that is going to be downloaded to the client. Server on receiving the file path, opens file and returns it's contents to the client which called the remote function. Client will open a new file and writes the  above returned value to the file.

ftp server :


     import xmlrpclib
    from SimpleXMLRPCServer import SimpleXMLRPCServer
    def movefile(filepath):
        try:
            handle = open(filepath)
            return xmlrpclib.Binary(handle.read())
            handle.close()
        except:
            return 'error'
    client.register_function(movefile)
    server.serve_forever()


ftp client :

   import xmlrpclib
   server = xmlrpclib.ServerProxy('http://127.0.0.1:9009')
   filepath=raw_input('enter path : ')
   try:
         handle=open("/home/jo/Downloads/file1","w")
         handle.write(server.movefile(filepath).data)
         handle.close()
    except:
         print 'Download failed'



remarks ::

In the above examples the data read from the file is converted to binary format before transferring it using the Binary() function in the xmlrpc library. Also you have to change the ip to desired on replacing 127.0.0.1 to run the program on a network.        


Read rest of entry

27 January, 2011

python xmlrpc : a simple client server connection mechanism with greater possibilities

A byte of theory . . .

XML-RPC is a Remote Procedure Call method that uses XML passed via HTTP as a transport. With it, a client can call methods with parameters on a remote server (the server is named by a URI) and get back structured data. This module supports writing XML-RPC client code; it handles all the details of translating between conformable Python objects and XML on the wire.

A byte of surprise . . .


Here the xmlrpc library of the python does the magic, by leaving the  programmer give maximum attention to logic by freeing him from the concepts of the sockets, binding, listening, accepting, etc ... which are the primary constraints while developing a  network based program. Remote Procedure Call (RPC) mechanism allows the client to call any function defined and registered as 'remote' in the server.

A byte of reality . . .


xmlrpc library offers communication between the client and server in such a way that, we can define functions in one machine (say a server) and access those functions from the other machine (say a client). Here the communication occurs in two ways.
    >< client calling the remote server function can 
           pass arguments to it. So the server recieves this 
           arguments 
   ><  Server can transport some data as the return 
           value of the function that the client called

A byte of practical . . .


    Inorder to make the client and server communicate together we need to create the server object and client object with the ip and port of the server. Here i am running the client and server on the same machine. You can replace 127.0.0.1 in sample code with the ip of the server where you need to connect the clients. Port should be greater than the 1024.

server program

   import xmlrpclib
   from SimpleXMLRPCServer import SimpleXMLRPCServer
   def add(a, b) :
         return a+b
   server=SimpleXMLRPCServer(("127.0.0.1",9009))
   server.register_function(add)
   server.serve_forever()


In server program we have to create the object of the server with a method called SimpleXMLRPCServer() with parameters as ip and port. Then the function has to be registered inorder to access it remotely. The serve_forever() function is used to put the server wait for the client request infinitely.
client program
    
    import xmlrpclib
    server = xmlrpclib.ServerProxy('http://127.0.0.1:9009')
    a=input("No 1: ")
   
b=input("No 2: ")
    result = server.add(a,b)
    print "Result  :  "+result

In the client program we will use the ServerProxy() method to specify the details(port, ip) of the server which is having a function named add() which can be called remotely. So two integers a,b are passed as parameters to the remote function. Remote function calculates the sum and returns the result to the called function.

I felt this xmlrpc library as the most awesome mechanism provided by the python. It makes the programming to the very simplest extent so that the users can give maximum attention to developing logic, instead of worrying about the networking constraints and errors related to it...



 
Read rest of entry

10 September, 2010

How to install NetBeans IDE 6.9.1 in Ubuntu 10.04


How to install java runtime environment in Ubuntu
NetBeans IDE is an open-source, fast and feature full tool for developing Java software. It runs on any operating system where a Java Virtual Machine is available. NetBeans helps to develop java applications and projects with ease and good user friendly environment. Here is the right mechanism to install NetBeans IDE in Ubuntu. You should have to install a Java Virtual Machine in the computer before installing NetBeans.

Install Java Runtime Environment in Ubuntu 10.04

1.Open the terminal and add the following repository

   $ sudo add-apt-repository "deb http://archive.canonical.com/ lucid  partner"    

2. Update the apt:

$ sudo apt-get update

3. Now install Sun Java packages using command: 

$ sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts



Install NetBeans IDE 6.9.1 in Ubuntu 10.04

Download the latest version of the NetBeans IDE binaries from the link here. The versions available from synaptic or apt-get is usually out-of-date from the version available directly from NetBeans. So the best way to get the latest version is to download the binaries directly from the NetBeans website and execute it in your machine.

><      Download the binary corresponding to Java SE.


><       After the download is complete, take the  terminal and change to the directory where the file is downloaded, usually that may be in your Downloads folder.

$ cd  /home/your_username/Downloads


><      Now install the NetBeans IDE using the shell command as follows. Change the filename with the one corresponding to the file downloaded on to your machine.

$ sudo sh  ./netbeans-6.9.1-ml-javase-linux.sh

><       The terminal will initialize the NetBeans installer in Graphical mode after executing the above command. When installation is completed you can start creating your java application by taking the NetBeans IDE from Applications > Programming > NetBeans


Read rest of entry
 

Terminal Diary | techblog Copyright © 2009 Gadget Blog is Designed by jintu jacob Powered by Blogger