ManyCodes.com – codes & scripts Get free programming codes and tutorials!

10Aug/091

Apache performance tips

If you run the command top on your box and the CPU is mostly idle and there is plenty of memory available, and yet Apache seemed sluggish. Here are a couple of things I would recommend to speed things up.

1. Increase MaxClients and ServerLimit

This is a well-known Apache performance optimization tip. Its effect is to increase the number of httpd processes available to service the HTTP requests.

However, when I tried to increase MaxClients over 256 in the prefork.c directives and I restarted Apache, I got a message such as:

WARNING: MaxClients of 1000 exceeds ServerLimit value of 256 servers, lowering MaxClients to 256. To increase, please see the ServerLimit directive.

There is no ServerLimit entry by default in httpd.conf, so I proceeded to add one just below the MaxClients entry. I restarted httpd, and I still got the message above. The 2 entries I had in httpd.conf in the IfModule prefork.c section were:
ServerLimit 1000
MaxClients 1000
(make sure that serverlimit comes before maxclients)

At this point I resorted to all kinds of Google searches in order to find out how to get past this issue, only to notice after a few minutes that the number of httpd processes HAD been increased to well over the default of 256!

Note: It turns out that the new MaxClient and ServerLimit values take effect only if you stop httpd then start it back again. Just doing a restart doesn't do the trick...

So, lesson learned? Always double-check your work and, most importantly, know when to ignore warnings 🙂

Now I have a procedure for tuning the number of httpd processes on a given box:

1. Start small, with the default MaxClients (150).
2. If Apache seems sluggish, start increasing both MaxClients and ServerLimit; restart httpd every time you do this.
3. Monitor the number of httpd processes; you can use something like:

ps -def | grep httpd | grep -v grep | wc -l

If the number of httpd processes becomes equal to the MaxClients limit you specified in httpd.conf, check your CPU and memory (via top or vmstat). If the system is not yet overloaded, go to step 2. If the system is overloaded, it's time to put another server in the server farm behind the load balancer.

That's it for now. There are many other Apache performance tuning tips that you can read from the official Apache documentation here.

10Aug/090

How to install webmin on your Linux web server (Redhat Fedora Caldera Mandrake SuSE MSC)

Installing webmin on your linux webserver is easy. With webmin, you can use ispconfig which is a web hosting script that you can use to host many website in one server.
Webmin website: http://www.webmin.com/

Since I have fedora I can install like this:
(this tutorial is suitable for Redhat, SuSE, Caldera, Mandrake or MSC Linux, 13M)

Login to your shell, i will be using ssh so i send this command:

wget http://prdownloads.sourceforge.net/webadmin/webmin-1.350-1.noarch.rpm

Once it has finished downloadin i send this command:

rpm -U webmin-1.350-1.noarch.rpm

(make sure to use upper case U above)

The rest of the install will be done automatically to the directory /usr/libexec/webmin, the administration username set to root and the password to your current root password. You should now be able to login to Webmin at the URL http://localhost:10000/ .

Webmin install complete. You can now login to https://hostname.domain:10000/
as root with your root password.

NOTE: the default login and password is your root and root password. this is the same login you used with you ssh to your server or whatever your root password is, so your login will be like this:

Username: root
Password: xxxx (what ever your root password is)

8Aug/090

Star / Stop / Restart Apache 2 Web Server

Q. How do I restart Apache 2 Web Server under Debian / Ubuntu Linux?


A. Apache is primarily used to serve both static content and dynamic Web pages on the World Wide Web. Many web applications are designed expecting the environment and features that Apache provides.

First, login to server using ssh. To ssh to your server, you will need to a ssh client like putty (download putty from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html).

The ssh client will need you to enter the IP, username and password of your server. Choose port as 22.
Once logged in type the following commands as need be.

How To start Apache 2 web server, enter:

# /etc/init.d/apache2 start

OR

$ sudo /etc/init.d/apache2 start

Linux Command to restart Apache 2 web server, enter:

# /etc/init.d/apache2 restart

If you are using Ubuntu use sudo:

$ sudo /etc/init.d/apache2 restart

How To stop Apache 2 web server, enter:

# /etc/init.d/apache2 stop

OR

$ sudo /etc/init.d/apache2 stop
6Aug/092

How to enable mod_rewrite in apache 2.2 in Debian and Ubuntu

I am going to describe how to enable mod_rewrite in apache2.2 - specaily for debian.

In default installion of apache2.2 on debian never enable mod_rewrite default. So you may need to enable.

debian user please use “su” before start this process
ubuntu user please use “sudo su” before start this process

  1. First install the apache2.2 with this command :
apt-get install apache2

(it will install apache 2.2)

now use locate to find if the mod_rewrite.so is availble on your server

updatedb
 locate mod_rewrite.so

it will found in “/usr/lib/apache2/modules”

new apache follow some folders to enable and desuable mods.
so now do this:

cd /etc/apache2/mods-enabled
 touch rewrite.load
 gedit rewrite.load

(you may use any editor to edit this file)

now paste this following line

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

Then edit /etc/apache2/sites-available/000-default

Find the following

Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all

and change it to

Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all

and finally restart Apache

/etc/init.d/apache2 restart

OK, you done :D

Don’t forget to comment, if it works or not.

5Aug/090

How to Check Bios Version on a Dell Laptop

There are two easy ways to check the bios version on your Dell laptop.

  1. During Boot: When your laptop boots up the bios version will splash on the screen. A current version of your bios will be something similar to A06.
  2. CPU-Z: Download and run CPU-Z here. Once you download and run this application click on the Mainboard tab which has a BIOS section.

Once you know the bios version you can check Dell’s web site to see if a newer version is available. If a new version is available installing it can resolve possible bugs with your computer.

Filed under: Linux No Comments
5Aug/091

Install the Latest PostgreSQL Yum Repository for CentOS

Keeping PostgreSQL updated via yum should be done via the pgdg yum repository supplied by pgsqlrpms.org.

The latest CentOS PostgreSQL repo can be viewed here.

You will need to download the repo and then install using rpm as shown below.

wget http://yum.pgsqlrpms.org/reporpms/8.4/pgdg-centos-8.4-1.noarch.rpm</span></div>
<div style="width: 506px;">rpm<span> -Uhv</span><span> pgdg-centos-8.4-1.noarch.rpm

wget http://yum.pgsqlrpms.org/reporpms/8.4/pgdg-centos-8.4-1.noarch.rpm
rpm -Uhv pgdg-centos-8.4-1.noarch.rpm

Another helpful postgresql install and management link is located here.

5Aug/090

How to Install the Latest git on CentOS 5 from Source

To install the latest git on CentOS 5 you will need to install from source since the yum repos are typically fairly far behind. Follow the instructions below and installing git will be a snap.

  1. Install Dependencies: First we need to install a couple packages via yum to cover the dependencies for building git from source.
  2. [root@server ~]#yum install curl-devel
    [root@server ~]#yum install expat-devel
    [root@server ~]#yum install gettext-devel
    [root@server ~]#yum install openssl-devel
    [root@server ~]#yum install zlib-devel 
[root@server ~]#yum install curl-devel
[root@server ~]#yum install expat-devel
[root@server ~]#yum install gettext-devel
[root@server ~]#yum install openssl-devel
[root@server ~]#yum install zlib-devel
  • Download git Source: Now download the git source by issuing the below command. Verify the latest source here.
  • [root@server ~]#cd /usr/local/src
    [root@server ~]# wget http://www.kernel.org/pub/software/scm/git/git-1.6.0.4.tar.gz
    

    [root@server ~]#cd /usr/local/src
    [root@server ~]# wget http://www.kernel.org/pub/software/scm/git/git-1.6.0.4.tar.gz
  • Build Source:Unpack the file that has been downloaded and compile the source using the “make” command.
  • [root@server ~]#tar -zxvf git-1.6.0.4.tar.gz
    [root@server ~]#cd git-1.6.0.4
    [root@server ~]#make prefix=/usr/local all
    
    [root@server ~]#tar -zxvf git-1.6.0.4.tar.gz
    [root@server ~]#cd git-1.6.0.4
    [root@server ~]#make prefix=/usr/local all
  • Install git: After successfully compiling the source you need to install git.
  • [root@server ~]#make prefix=/usr/local/ install
    
    [root@server ~]#make prefix=/usr/local/ install
  • Download git Manpages:Now let’s download the manpages. Verify the latest manpages here.
  • [root@server ~]#cd /usr/local/src
    [root@server ~]#wget http://www.kernel.org/pub/software/scm/git/git-manpages-1.6.0.4.tar.gz
    [root@server ~]#cd /usr/local/src
    [root@server ~]#wget http://www.kernel.org/pub/software/scm/git/git-manpages-1.6.0.4.tar.gz
  • Install git Manpages:Now change into the share directory and unpack the git manpages.
  • [root@server ~]#cd /usr/local/share/man
    [root@server ~]#tar -zxvf /usr/local/src/git-manpages-1.6.0.4.tar.gz
    
    [root@server ~]#cd /usr/local/share/man
    [root@server ~]#tar -zxvf /usr/local/src/git-manpages-1.6.0.4.tar.gz
  • Verify:Lets verify that git was installed successfully and the manpages are working properly.
  • [root@server ~]#git --version
    [root@server ~]#man git
    
    [root@server ~]#git --version
    [root@server ~]#man git

    After following the above steps you should be able to successfully use git.

    [root@server ~]#yum install curl-devel
    [root@server ~]#yum install expat-devel
    [root@server ~]#yum install gettext-devel
    [root@server ~]#yum install openssl-devel
    [root@server ~]#yum install zlib-devel

    29Jul/090

    How to you can randomly change color of the background of your website

    Here is how you can randomly change color of the background of your website.

    Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website

    Code:

    <!-- this script is from www.manycodes.com -->
    <script>
    
    // Select fade-effect below:
    // Set 1 if the background may fade from dark to medium
    // Set 2 if the background may fade from light to medium
    // Set 3 if the background may fade from very dark to very light light
    // Set 4 if the background may fade from light to very light
    // Set 5 if the background may fade from dark to very dark
    var fade_effect=3
    
    // What type of gradient should be applied Internet Explorer 5x or higher?
    // Set "none" or "horizontal" or "vertical"
    var gradient_effect="horizontal"
    
    // Speed higher=slower
    var speed=60
    
    ///////////////////////////////////////////////////////////////////////////
    // CONFIGURATION ENDS HERE
    ///////////////////////////////////////////////////////////////////////////
    
    var browserinfos=navigator.userAgent
    var ie4=document.all&&!document.getElementById
    var ie5=document.all&&document.getElementById&&!browserinfos.match(/Opera/)
    var ns4=document.layers
    var ns6=document.getElementById&&!document.all
    var opera=browserinfos.match(/Opera/)
    var browserok=ie4||ie5||ns4||ns6||opera
    
    if (fade_effect==1) {
     var darkmax=1
     var lightmax=127
    }
    if (fade_effect==2) {
     var darkmax=127
     var lightmax=254
    }
    if (fade_effect==3) {
     var darkmax=1
     var lightmax=254
    }
    if (fade_effect==4) {
     var darkmax=190
     var lightmax=254
    }
    if (fade_effect==5) {
     var darkmax=1
     var lightmax=80
    }
    var hexc = new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F')
    
    var newred
    var newgreen
    var newblue
    var oldred
    var oldgreen
    var oldblue
    
    var redcol_1
    var redcol_2
    var greencol_1
    var greencol_2
    var bluecol_1
    var bluecol_2
    var oldcolor
    var newcolor
    var firsttime=true
     
    var stepred=1
    var stepgreen=1
    var stepblue=1
    
    function setrandomcolor() {
     var range=(lightmax-darkmax)
     if (firsttime) {
     newred=Math.ceil(range*Math.random())+darkmax
     newgreen=Math.ceil(range*Math.random())+darkmax
     newblue=Math.ceil(range*Math.random())+darkmax
     firsttime=false
     }
     
     oldred=Math.ceil(range*Math.random())+darkmax
     oldgreen=Math.ceil(range*Math.random())+darkmax
     oldblue=Math.ceil(range*Math.random())+darkmax
     
     stepred=newred-oldred
     if (oldred>newred) {stepred=1}
     else if (oldred<newred) {stepred=-1}
     else {stepred=0}
     
     stepgreen=newgreen-oldgreen
     if (oldgreen>newgreen) {stepgreen=1}
     else if (oldgreen<newgreen) {stepgreen=-1}
     else {stepgreen=0}
     
     stepblue=newblue-oldblue
     if (oldblue>newblue) {stepblue=1}
     else if (oldblue<newblue) {stepblue=-1}
     else {stepblue=0}
     fadebg()
    }
    
    function fadebg() {
     if (newred==oldred) {stepred=0}
     if (newgreen==oldgreen) {stepgreen=0}
     if (newblue==oldblue) {stepblue=0}
     newred+=stepred
     newgreen+=stepgreen
     newblue+=stepblue
     
     if (stepred!=0 || stepgreen!=0 || stepblue!=0) {
     redcol_1 = hexc[Math.floor(newred/16)];
     redcol_2 = hexc[newred%16];
     greencol_1 = hexc[Math.floor(newgreen/16)];
     greencol_2 = hexc[newgreen%16];
     bluecol_1 = hexc[Math.floor(newblue/16)];
     bluecol_2 = hexc[newblue%16];
     newcolor="#"+redcol_1+redcol_2+greencol_1+greencol_2+bluecol_1+bluecol_2
     if (ie5 && gradient_effect!="none") {
     if (gradient_effect=="horizontal") {gradient_effect=1}
     if (gradient_effect=="vertical") {gradient_effect=0}
     greencol_1 = hexc[Math.floor(newred/16)];
     greencol_2 = hexc[newred%16];
     bluecol_1 = hexc[Math.floor(newgreen/16)];
     bluecol_2 = hexc[newgreen%16];
     redcol_1 = hexc[Math.floor(newblue/16)];
     redcol_2 = hexc[newblue%16];
     var newcolorCompl="#"+redcol_1+redcol_2+greencol_1+greencol_2+bluecol_1+bluecol_2
     document.body.style.filter=
    "progid:DXImageTransform.Microsoft.Gradient(startColorstr="+newcolorCompl+", endColorstr="+newcolor+" GradientType="+gradient_effect+")"
     }
     else {
     document.bgColor=newcolor
     }
     var timer=setTimeout("fadebg()",speed);
     }
     else {
     clearTimeout(timer)
     newred=oldred
     newgreen=oldgreen
     newblue=oldblue
     oldcolor=newcolor
     setrandomcolor()
     }
    }
    
    if (browserok) {
     window.onload=setrandomcolor
    }
    </script>
    <font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>
    
    28Jul/090

    How to make text dance on your website

    Here is how you can make text dance on your website.

    Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website

    Code:

    <!-- this script is from www.manycodes.com -->
    <script language="JavaScript1.2">
    //configure message
    message="Welcome to www.javascriptfreecode.com"
    //animate text in NS6? (0 will turn it off)
    ns6switch=1
    
    var ns6=document.getElementById&&!document.all
    mes=new Array();
    mes[0]=-1;
    mes[1]=-4;
    mes[2]=-7;mes[3]=-10;
    mes[4]=-7;
    mes[5]=-4;
    mes[6]=-1;
    num=0;
    num2=0;
    txt="";
    function jump0(){
    if (ns6&&!ns6switch){
    jump.innerHTML=message
    return
    }
    if(message.length > 6){
    for(i=0; i != message.length;i++){
    txt=txt+"<span style='position:relative;' id='n"+i+"'>"+message.charAt(i)+"</span>"};
    jump.innerHTML=txt;
    txt="";
    jump1a()
    }
    else{
    alert("Your message is to short")
    }
    }
    
    function jump1a(){
    nfinal=(document.getElementById)? document.getElementById("n0") : document.all.n0
    nfinal.style.left=-num2;
    if(num2 != 9){
    num2=num2+3;
    setTimeout("jump1a()",50)
    }
    else{
    jump1b()
    }
    }
    
    function jump1b(){
    nfinal.style.left=-num2;
    if(num2 != 0){num2=num2-3;
    setTimeout("jump1b()",50)
    }
    else{
    jump2()
    }
    }
    
    function jump2(){
    txt="";
    for(i=0;i != message.length;i++){
    if(i+num > -1 && i+num < 7){
    txt=txt+"<span style='position:relative;top:"+mes[i+num]+"'>"+message.charAt(i)+"</span>"
    }
    else{txt=txt+"<span>"+message.charAt(i)+"</span>"}
    }
    jump.innerHTML=txt;
    txt="";
    if(num != (-message.length)){
    num--;
    setTimeout("jump2()",50)}
    else{num=0;
    setTimeout("jump0()",50)}}
    </script>
    </head>
    <body>
    
    <h2><div id="jumpx" style="color:green"></div></h2>
    <script>
    if (document.all||document.getElementById){
    jump=(document.getElementById)? document.getElementById("jumpx") : document.all.jumpx
    jump0()
    }
    else
    document.write(message)
    </script>
    
    <font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>
    
    28Jul/090

    How to have a opening popup with your website

    Here is how to have a opening popup with your website.

    Put the code below within your site's <head> </head> tags. If you dont know how to implement this code into your site, please goto how to implement the code to your website

    Code:

    <!-- this script is from www.manycodes.com -->
    
    <!--   DESCRIPTION:  This will make a small Navigation Window in which you can place links to different pages.
    
     INSTRUCTIONS:  Place this script in the HEAD tags of
    your webpage.
    
     FUNCTIONALITY:  Works in both Netscape & IE.
    -->
    
    <SCRIPT LANGUAGE="JavaScript">
    
    //Modified by CoffeeCup Software
    //This code is Copyright (c) 1997 CoffeeCup Software
    //all rights reserved. License is granted to a single user to
    //reuse this code on a personal or business Web Site.
    
    <!--
    
    coffeeWin=window.open("","coffeeWin","toolbar=no,width=200,height=250,directories=no,menubar=no,SCROLLBARS=no");
    
    coffeeWin.document.write("<HTML>");
    coffeeWin.document.write("<HEAD>");
    
    coffeeWin.document.write("</HEAD>");
    
    coffeeWin.document.write("<BODY BGCOLOR=#FFFFFF TEXT=#000000 LINK=#0000FF VLINK=#0000FF>")
    
    coffeeWin.document.write("<CENTER>")
    
    coffeeWin.document.write("<FONT FACE=VERDANA,ARIAL SIZE=2>");
    
    coffeeWin.document.write("<B>");
    
    coffeeWin.document.write("<FONT SIZE=3>Navigation Window</FONT>");
    
    coffeeWin.document.write("<BR><HR WIDTH=180><BR><P>");
    
    coffeeWin.document.write("<A HREF=http://www.webloger.5u.com TARGET=MAIN>Webloger Website</A>");
    
    coffeeWin.document.write("<P>");
    
    coffeeWin.document.write("<A HREF=http://www.microsoft.com TARGET=MAIN>Microsoft</A>");
    
    coffeeWin.document.write("<P>");
    
    coffeeWin.document.write("<A HREF=http://www.netscape.com TARGET=MAIN>Netscape</A>");
    
    coffeeWin.document.write("<P>");
    
    coffeeWin.document.write("<A HREF=http://www.infoseek.com TARGET=MAIN>InfoSeek</A>");
    
    coffeeWin.document.write("<P>");
    
    coffeeWin.document.write("</B>");
    
    coffeeWin.document.write("</FONT>");
    
    coffeeWin.document.write("</BODY>");
    
    coffeeWin.document.write("</HTML>");
    
    //-->
    </SCRIPT>
    <font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>