Saturday, 27 November 2010

Getting started with PHP and apache

Someone who gives it a thought of using PHP , apache and stuff for the first time will be faced up with a few number of fixed problems . Configuring your apache server , establishing a connection between PHP and apache , stuffs like that . Here is a basic introduction to start using these things and kick off as a web programmer .

Obviously you need to have PHP and apache installed on your system .

$ : sudo apt-get install apache2

$ : sudo apt-get install php5-cli

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

 

would get you apache and PHP installed on your system  .

Using the appropriate versions is left upto individuals .

Just have a peep into some of the files like :

/etc/php5/apache2/php.ini -----> You would see a lot of variables set to 'ON'  and 'OFF' . You may well have to toggle those values as and when necessary .

 

Try starting , stopping and restarting your apache web server .

$ :sudo  /etc/init.d/apache2 start

$: sudo /etc/init.d/apache2 stop

$: sudo /etc/init.d/apache2  restart

 

Once everything is fine and and perfect  , try out your first PHP script . Script it , save it in a file with a '.php' extension and put your file in the directory '/var/www '. Now you could access this script from your browser

localhost/'scriptname'

and you see the result right there in front of you . Thats just how you enter the world of web programming .

Wednesday, 24 November 2010

GreaseMonkey : Customizing your webpages

There would have been times when you would have felt if the web page in front of you behaved a bit more according to your like . This might specially happen if the page consists of forms that you fill with data directed to live servers .  In such cases you wouldn't mind customizing the page to suit your needs so that you don't do some nonsense that would result in chaos .

Firefox , i see many using it as their default browser , offers a plugin called 'Grease monkey'  that allows you to do just that . All you need to is to install the plugin , write your own javascripts , install them ( thats pretty easy to do ) and start using them  .

Write your javascripts to customize your webpage . What you need to do in addition is to add some metadata providing extra information to greasemonkey .

The meta data might look as follows :



 

 

 

 

 

 

The first and the last lines are necessary to indicate to the greasemonkey that the script it to be processed by it .

The name and the description are optional . It might prove helpful to you if you have scripted and installed a number of greasemonkey scripts .

The 4th an the 5th line of the metadata are extremely important and needs to be well understood . These lines tell the greasemonkey the URLs on which the script is to be applied and not to be applied .

@include -> specifies the URLs on which the script is to be installed . Here '*' is specified which is just a wildcard and indicates that the script is to applied on all the sites  .

@exclude -> specifies the URLs that are to be left out . It is to be noted that @exclude is processed before @include .

This gives you an idea of the metadata part of the script . Now you may write your own javascript , add your metadata at the beginning and save the file with the extension ' .user.js '  .

To install the script , open the file in firefox and you would see an option 'install' . Just give a click and you are ready to use your greasemonkey script .You could manage your script , disable it , uninstall it as well . Just click

Tools ----> Greasemonkey ----> Manage user scripts ....

Having another plugin 'firebug' may help you in the process of writing the script . This allows you to view the html code of the webpage that is infront of you . Infact the plugin is almost a necessity to help you write efficient code with greasemonkey .

Now you may start writing your own greasemonkey scripts and customize any of the webpages as and according to your like . It's also to be understood that greasemonkey is a plugin of firefox . If you use Google chrome as your browser , you wouldn't need to install any plugin . The facility to customize the webpage is provided by default . You may use the same code that you have written to work with greasemonkey . The metadata and the process of installing is the same and obviously the results are the same as well .

Using Screens

You might have often had the experience where you would have had to open quite a few terminals on your screen simultaneously . This might often be the case when you are doing stuffs like data processing on particular files and you intend not to sit idle during that particular time . What you do is to keep unnecessary number of terminals open on your screen .

You could get rid of this by using the 'screens' option in Linux . This allows you to enter a new screen where you could perform time consuming processes like a data processing operation using the  'awk'  command . Start the process in the screen , exit the screen and now do your own stuff in the main console , go back to your screen after a while and view the results of  whatever operations you had performed . You could do all this stuff without the necessity of opening terminals again and again .

Create a new Screen :

$ : screen -S 'Screen name'

To detach from the current screen :

Use CTRL + a + d

To terminate a screen :

Use CTRL + d

To attach an already created screen :

$ : screen -x 'screen name'

You could keep on creating screens within screens and keep going on as and when needed  .