07 July, 2011

Change the DocumentRoot of Apache webserver (/var/www) in Debian / Ubuntu

The document root (also called as the web root) of the Apache web server is located at the /var/www directory by default. Document root is the place where we find all the web pages and server scripts. These files are loaded on the browsers when we type in a particular url to point to that server. 

The /var/www directory doesn't allow access for a user who doesn't have the root permission. It's a headache task to switch to the root mode by typing in the root password everytime even though you know the password, since you may have to change your webpages or scripts during its development stage  very frequently. So a better idea to avoid this problem is to change the default Document root directory to some other location which doesn't require root permission for access.


Change it dude !!!
- - - - - - - - - - - - - - - - - -#

Inorder to change the document root,

#1. Make a directory somewhere inside your home directory to use as the Document root. (not necessarily be home... you can make it anywhere). I named it 'www'

$ mkdir /home/jo/www

#2. Now we have to edit the one of the configuration file of the Apache webserver. The file is located @  /etc/apache2/sites-available/default (requires root permission to edit it).

$ sudo gedit /etc/apache2/sites-available/default

The file will be opened up in the gedit text editor. Now you have to edit the DocumentRoot directive in this file. Replace the /var/www with the /path/to/your/new/document/root in the lines 4 and 9 as shown in the figure below.


#3. Restart the apache webserver.

$ sudo /etc/init.d/apache2  restart



Now test it !!!
- - - - - - - - - - - - - - - - - -#

#1. Create a html/php file inside the Document Root directory (mine is @ /home/jo/www).

#2. Take the terminal and navigate to the Document Root directory (using cd command). Use chmod command given below to allow read+write+execute permission to all.

$ chmod 777 *

#3. Take your web browser and type in http://localhost and hit the enter key! The apache server will load the contents of your Document Root directory as in the figure.


Hope you have done it right!!!


Read rest of entry

22 November, 2010

Basic javascript programs


 1. A javascript to implement variable usage
<html>
<title>Variable Using Script</title>
<body>
<script>
      var greetings;
      greetings='Hi, How are you?';
      alert(greetings);
</script>
</body>
</html>

2. A javascript to implement the pop-up boxes 
<html>
<title>Script for prompt</title>
<script>
var username;
var greeting;
username = prompt("What is your name?");
username=username.toUpperCase();
greeting="Hi, "+username;
alert(greeting);
</script>
</body>
</html>
</script>
</html>

3.Implementing the eval() function in javascript

          In javascript every input is read as string. We need to convert it to numbers for processing if the input is a number 
<html>
<title>Sum of Two Numbers</title>
<script>
var num1,num2;
var sum;
var msg;
num1=prompt("Enter the first number: ");
num1=eval(num1);
num2=prompt("Enter the second number: ");
num2=eval(num2);
sum=num1+num2;
msg="Sum= "+sum;
alert(msg);
</script></html>

4.  Using switch case in javascript.
<html>
<title>Switch Case</title>
<body>
<script>
       var num,day;
       num=prompt("Enter an integer: ");
       switch(num%7)
       {
              case 1: day="Sunday";break;
              case 2: day="Monday";break;
              case 3: day="Tuesday";break;
              case 4: day="Wednessday";break;
              case 5: day="Thursday";break;
              case 6: day="Friday";break;
              case 0: day="Saturday";break;
              default: day="Invalid Day Number!!\n";
       }
       alert("Day: "+day);
</script>
</body>
</html>

5. Implementing for loop in javascript
<html>
<title>For Loop</title>
<body>
<script>
       var i;
       for(i=0;i<10;i++)
       {
              alert("This is the message no: "+i);
       }
</script>
</body>
</html>

6. Generating local information from the browser using javascript
<html>
<title>Information</title>
<body>
<script>
       document.bgColor="blue";
       alert("Background: "+document.bgColor);
       alert("Domain: "+document.domain);
       alert("URL: "+document.location);
       alert("Last Modified: "+document.lastModified);
       alert("Last Page: "+document.referrer);
       alert("Title: "+document.title);
</script>
</body>
</html>

7.Writing dynamic javascript contents on to html page to display in browser 
<html>
<title>Dynamic Write</title>
<body>
<script>
       var name;
       name=prompt("Enter your name: ");
</script>
        Hi how are you?
<script>
       document.write(name);
</script>
</body>
</html>

8. Implementing onclick events and functions within a form using javascript
<html>
<title>Script for Form Variable Changing</title>
<body>
<script>
       function changebuttonValue()
       {
               document.myForm.button.value="changed";
       }
       function changeText()
       {
               document.myForm.text1.value="Enter you name";
       }
</script>
<form name=myForm>
<input type=text name=text1 onMouseOver='changeText();'>
<br>
<input type=button name='button' value=Enter onClick='changebuttonValue();'>
</form>
</body>
</html>

9. opening a new browser window using javascript
<html>
<title>Open a New Window</title>
<body>
<input type=button value="Show New Window" onClick="newWindow();">
<input type=button value="Close Window" onClick="closeWindow();">
<script>
       var new1;
       function newWindow()
       {
              //document.write("Hi");
              new1=window.open("frame1.html","Name","height=450,width=450");
              new1.focus();
       }
       function closeWindow()
       {
              new1.close();
       }
</script>
</body>
</html><hr align="left" size="1" width="100%">


Read rest of entry

a Javascript a day | my javascript tutorial . . .


                 Here i share my basic experimentsi had done with javascript. Its not enough for making a geekness with that, but only for making the first lessons of javascript ...

What is javascript ?

JavaScript is a scripting language that will allow you to add real programming to your webpages. You can create small application type processes with JavaScript, like a calculator or a primitive game of some sort. Important uses of javascript are
  • Browser Detection
    • Detecting the browser used by a visitor at your page. Depending on the browser, another page specifically designed for that browser can then be loaded. 
  • Cookies
    • Storing information on the visitor's computer, then retrieving this information automatically next time the user visits your page. This technique is called "cookies".
  • Control Browsers
    • Opening pages in customized windows, where you specify if the browser's buttons, menu line, status line or whatever should be present.
  • Validate Forms
    • Validating inputs to fields before submitting a form. An example would be validating the entered email address to see if it has an @ in it, since if not, it's not a valid address. 
 
where is the playground ?

The browser will use the 
<script type="text/javascript"> and </script> to tell where javascript starts and ends respectively.

The <script> …… </script>  Tag can be included in

  • <head> section
  • <body> section
  •  Both <head> section and <body> section
  •  In an External file with .js extension    
    • Eg : <script type="text/javascript" src="xxx.js"></script> 
To declare a variable in JavaScript, use the var command.    Eg : var state, city, zip, country; 

Basics

  • Write directly into the document.
     >> document.write("Welcome to my world!!!");

  • Write using POPUP Boxes
     Alert Box
     >> alert("Welcome to my world!!!");

     Confirm Box

     >>if (confirm("Do you agree")) 

               {alert("You agree")}
           else{alert ("You do not agree")};

    Prompt Box
    >> username=prompt("Please enter your 

                    name","Enter your name here");  

Check out this link to make out the rest.
Read rest of entry

04 September, 2010

Links: the browser for the terminal


Links is powerful text WWW browser with tables and frames. It runs in linux terminal providing a faster access to internet especially on slow connection. Its completely text based, so that you cant use it  as a complete replacement for usual browsers since terminal can not display images. Also since text based it can be a used for faster acces of internet when you are using mobile internet. 

 








Installing links in Ubuntu

Take the terminal and type in as follows

 $ sudo apt-get install links 

Or you can download the links package with graphics in compressed format from here. The details about installation are provided in the links site.
 
Browsing in links 

After installation take the terminal and type links

 $ links
 
command line options
-g 
            to run links in graphics mode
-no-g
            to run links in text mode

-anonymous
            Restrict links so that it can run on an anonymous  account.   No local  file  browsing.  No  downloads.  

 
-http-proxy <host:port>
              Host and port number of the HTTP  proxy,  or  blank.


-ftp-proxy <host:port>              
              Host  and  port  number  of  the FTP proxy, or blank. 

-download-dir <path>              
              Default download directory.  (default: actual dir) 


Navigation keys

ESC/F9    menu/escape
d      download link (text mode only)
/       search in the page
?       search back in the page
n       find next match
f        zoom actual frame
^R    reload page
g       go to URL
G       edit the current URL and goto the result
s       bookmark manager
q       quit, close window if more windows are open
=      document informations
\       toggle HTML source/rendered view
 
Setting proxy in links

Select Network Options from the setup menu(Click on F9 to get the menu).
 
Select Proxies to input the proxy address.







 
 

Read rest of entry
 

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