Necessary commands (tips) to tune apache

To search in the current directory and all sub directories for a file named httpd.conf
find . -name "httpd.conf" -print
To find some string or text, type
find . -exec grep "MaxClients" '{}' \; -print
This command will search in the current directory and all sub directories. All files that contain the string with the path.

If you want to just find each file then pass it on for processing use the -q grep option. This finds the first occurrance of the search string. It then signals success to find and find continues searching for more files.
find . -exec grep -q "www.athabasca" '{}' \; -print
Send 1000 Request to apache using apache benchmark
ab -n 1000 -c 200 -k YOUR_URL
To view error log of httpd. type
grep -i maxclient /var/log/httpd/error_log*
To view Process status type
top
To view Load average, users, type
uptime
To open a file and search something(Here Example is: MaxClients) from there type
vi +/MaxClients /etc/httpd/conf/httpd.conf
To view total memory used by httpd, type
ps -ylC httpd --sort:rss
To restart apache, type
service httpd restart or etc/init.d/httpd restart
Have fun! :)

How to tune Apache and Mysql

By default, Apache comes preconfigured to serve a maximum of 256 clients simultaneously. This particular configuration setting can be found in the file /etc/httpd/conf/httpd.conf

If your server has 2 GB of RAM, and you’re sharing your server with MySQL(true in my case), you’ll want to reserve about half of it for Apache (1 GB)

MaxClients: here is the process of determining MaxClients. type
ps -U apache -u apache u
See the number of apache process running in you command prompt.
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
apache 7694 0.0 0.3 42704 6680 ? S 18:30 0:00 /usr/sbin/httpd

The above indicates that a single httpd process is using 6.6 MB of RSS (Resident Set Size) memory (or non-swapped physical memory) and that it is using 42 MB of VSZ (Virtual Size) memory. This depends on the number of modules you have loaded and running in Apache.
As shared libraries are included in this number, it’s not 100 percent accurate. We can assume that half the RSS number is “real” memory. Let’s assume that each httpd process is using (6.6/2=3.3) 4 MB of memory. So if you have 1 GB ram then divide it with 4 MB of memory, which leaves room for around 256 concurrent httpd processes. Set MaxClients 256

Or

Somebody prefers to set MaxClients using following rule
MaxClients = 150 x RAM (GB)
So for example if you have 2 GB RAM (dedicated for apache) set this value to 300. In my case IT WILL BE 150

Or

Some individuals maintain that each httpd thread uses about 5 MB of “real” memory. So they determine by the following way..
Or MaxClients = RAM(MB)/5
So for example if you have 2 GB RAM (dedicated for apache) set this value to 409. In my case IT WILL BE 204(1 GB for apache)

Note: There is no reason for you to set it any higher unless you have a specific problem with this value. A high value can lead to a complete server hang in case of a DOS attack. A value too low can create timeout problems for your clients if the limit is reached

StartServers - Sets the number of child server processes created on startup. This setting depends greatly on the type of webserver you run. If you run low traffic websites on that server set it low to something like 5. If you have resource intensive websites on that server you should set it close to MaxClients.

MaxRequestsPerChild - Controls the number of request the a child serves before the child is killed. This should not be set too low as it will put an unnecessary load on the apache server to recreate the child. I suggest setting it to 1000. But we are going to use 2000 for handling heavy traffic load properly.

MinSpareServers and MaxSpareServers - MaxSpareServers and MinSpareServers control how many spare (unused) child-processes Apache will keep alive while waiting for more requests to put them to use. Each child-process consumes resources, so having MaxSpareServers set too high can cause resource problems. On the other hand, if the number of unused servers drops below MinSpareServers, Apache will fork. Leave those values to: MinSpareServers 5 MaxSpareServers 10

ServerLimit: Its better to keep Server limit same as the value of MaxClients.
MaxRequestsPerChild: I’ve Kept default apache value for this one.

So few changes need to be made in httpd.conf file which is located in /etc/httpd/conf/ directory

<IfModule prefork.c>
StartServers     140
MinSpareServers    5
MaxSpareServers   10
ServerLimit      150
MaxClients       150
MaxRequestsPerChild  4000
</IfModule>

[Note]: Response time depends on MaxClients. If you increase the MaxClients number, server will response more quickly for each request but  a high value can lead to a complete server hang.

Ab is a tool for benchmarking the performance of your Apache HyperText Transfer Protocol (HTTP) server. It does this by giving you an indication of how many requests per second your Apache installation can serve.

uptime command in your root login should not yield a load average above 1, and the server should respond to commands quickly
ab -n 10000 -c 200 -k http://your_url
-c = concurrent connections
-t = time limit
-n = # of requests

Keep tuning until you hit your maximum desired load average. For servers used interactively often, having a load above 3 is way too much to use the server comfortably. For servers used mostly as real servers, a maximum load average of 10 should be acceptable. More than that, and you’ll find yourself needing to reboot the server when experiencing heavy traffic conditions, because no terminal or remote console will respond quickly to commands, and managing the server will be impossible.

How to configure few things in php.ini file for supporting huge traffic

* Enable the compression of HTML by putting in your php.ini:
output_handler = ob_gzhandler
** Switch from file based sessions to shared memory sessions. Compile PHP with the –with-mm option and
set session.save_handler=mm

Configure mysql. Change my.cnf file for better performance.

The database parameters are tuned for systems with 1 GB RAM (for ISO CD images). If you have higher RAM, please change the following in the “my.cnf” MySQL configuration file under /etc/mysql or /etc directory.
For a machine running with 512 MB of RAM, you can set these to:
key_buffer=128M table_cache=1024 sort_buffer=64M read_buffer=2M record_buffer=4M
For a machine running with 1 GB of RAM, you can set these to:
key_buffer=256M table_cache=2048 sort_buffer=128M read_buffer=2M record_buffer=8M
For a machine running with 2 GB of RAM, you can set these to:
key_buffer=512M table_cache=3072 sort_buffer=256M read_buffer=2M record_buffer=8M
For a machine running with 4 GB of RAM, you can set these to:
key_buffer=1G table_cache=4096 sort_buffer=512M read_buffer=2M record_buffer=8M

How to setup vmware server 1.0.5 in fedora 9

Setting up vmware server is bit different in fedora. Here there is no need for vmware any any update. What you have to do is

step1: Download vmware server 1.0.5 from here and install vmware-server. you can see my earlier post for step by step installation instructions here
During installation, if it’s failed to find the proper location of c header file, that means you dont have kernel-devel installed in your OS. If so then follow step 2 otherwise skip step 2.

Step2: Download devel-kernel (must have to match with your running kernel). Right now i’m using fedora 9.
To view the kernel that is running type uname -r in the terminal. Mine one is 2.6.25-14.fc9.i686
you can download your desired kernel-devel from this link. click here to download kernel-devel

Step3: Download 2 patches (vmnet &vmmon) for the kernel 2.6.25 (or whatever your kernel is)
I’ve downloaded those patch from jon.limedaley.com. Click on those link to dl those patch.
vmnet here and vmmon here

Step4: Now apply those patches. What you have to do is…

Copy vmnet.tar and vmmon.tar from /usr/lib/vmware/modules/source directory to other directory.

Untar both these files by running tar xvf vmnet.tar and tar xvf vmmon.tar.

You will see two new directories named vmnet-only and vmmon-only in this directory

Now, copy both of the downloaded patch files into this directory as well.

Now go to your terminal and do..

cd vmnet-only

patch -p1 < ../vmnet-2.6.25.patch

cd ../vmmon-only

patch -p1 < ../vmmon-2.6.25.patch

Set read write execute permission to source, vmmon-only and vmnet-only folder.

Now in your terminal go to source directory and create the tar files again

tar cvf vmnet.tar vmnet-only/

tar cvf vmmon.tar vmmon-only/

Finally run vmware-config.pl file again.

Thats it.

How to use windows application in linux.

There is several way to use windows application in linux. As i used to play games a lot in windows so after installing linux i was worried about all those stuff :(

Then after surfing internet, I’ve found several way to use windows application.

I was very much excited about the way of setting up virtual machine in linux and one can switch to any operating system using vmware server without rebooting. I’ve already installed it now I can boot windows from my linux (fedora and ubuntu) using vmware server and play my favorite games there. But one important thing is :) vmware works good for high configured pc. ( i mean at least 1 gb ram, around 8 gb space for vm, above 1.7 ghz processor bla bla )

OR
You can install wine in linux which creates windows environment to run windows application. But it doesn’t support all the application.

OR

Search www.osalt.com to find open source alternative solutions of your windows application.  You  may find several alternative software for linux operating system.

How to configure for GPRS/EDGE modem in grameen phone or aktel and broadband connection(pppoe) in linux.

Connect to GPRS/EDGE modem

At first, Take a look at the wvdial.conf file. There you will see only 4 lines for username, password… Dont bother with it now.. that’s not the full specification. What you have to do is , type

wvdialconf in the terminal. It will locate your modem and do some necessary configuration in that file.

In the terminal window you may see permission problem with /etc/ppp folder or may be with some other folder. So give that folder permission to write and run wvdialconf in the terminal again.

And now look at the wvdial.conf folder again. You will notice few changes with some modem configuration. Now just add the following line if you are using grameen phone service.

Init3 = AT+CGDCONT=1,”IP”,”gpinternet”

and modify phone number

Phone = *99***1#

Now type wvdial in the terminal to connect now

OR

you may connect and configure your modem by launching KPPP or GNOME-PPP (kppp for kde and gnome-ppp for gnome environment) in your terminal window too

Broadband connection (pppoe).

Last month i was bit worried about my broadband connection cause i wasn’t able to connect to internet as it was in linux. I was more confused because my Internet service provider has given me an username and password to dial though it was a broadband connection:o. (later i knew that mine one is pppoe connection that’s why username nad password is required for proper configuration. lol) Before that i was using gpinternet.

Anyway, then i called my isp. But what has surprised me is, even they dont know how to configure it in a linux machine and they told me that they will call me after 2 days after consulting with their engineers .But i dont have that much time you know ;) I started to surfing around in different forums. and found a way to configure it.

Just type pppoeconf in the terminal window. A window will appear and will prompt for your username and password (what your isp may have given you) and for all the other prompt action, just enter default options(yes) . now restart networking service.

./etc/init.d/networking restart

Ping any site. I guess, you are connected ;)

Both the way for connecting internet is pretty simple. Isn’t it?

Enjoy

USB support for vmware server 1.0.5

After installing vmware server 1.0.5 in my ubuntu hardy heron i was excited to test it. then i’ve created a VM of windows xp (I love to play games a lot) :-s

But problem occured when i was trying to connect my usb device. I found it in ubuntu but not in xp. Now, to recognise usb device in your virtual mechine what you have to do is

Step 1: Edit mountdevsubfs.sh file which is located in ‘ /etc/init.d/ ‘ directory.

sudo gedit /etc/init.d/mountdevsubfs.sh

and uncomment these four lines

#
# Magic to make /proc/bus/usb work
#
mkdir -p /dev/bus/usb/.usbfs
domount usbfs “” /dev/bus/usb/.usbfs -obusmode=0700,devmode=0600,listmode=0644
ln -s .usbfs/devices /dev/bus/usb/devices
mount –rbind /dev/bus/usb /proc/bus/usb

Also add the following line

usbfs /proc/bus/usb usbfs auto 0 0

to /etc/fstab file.

sudo gedit /etc/fstab

[This is not preffered way. The preferred method is not to use /proc/bus/usb and should be used when supported by the VM software.]

After that, do

sudo /etc/init.d/mountdevsubfs.sh start

and

sudo mount -a

Now reboot your system, start vmware server then play the vm and select the usb from VM->Removable Devices->Usb->your device

Hope you will get your usb device working in vm.

Enjoy!!

How to share linux folder with others.

Step 1: First what you should do is install samba (if not yet installed).

sudo apt-get install samba

Then edit the ” smb.conf ” file which is located in /etc/samba/ directory.

Here i’m going to share a folder named “share” which is located in ‘/home/shabuz/’ directory. So path should be, directory of the folder that you are sharing. you can write anything in place of ‘myShare’ . This will be the shared folder name.

sudo gedit /etc/samba/smb.conf

[myShare]
comment = Public Stuff
path = /home/shabuz/share
public = yes
writable = yes
printable = no

That’s it. Now in the address bar type smb://YOUR_IP/ and you will find a folder named myShare.

You can set password to access your folder too. What you have to do is,

sudo smbpasswd -a username

it will ask you for setting a password

Yup. Now your folder will be visible to others.

How to Install vmware server in ubuntu hardy heron.

I had vmware installed in my pc (with the operating system ubuntu (gutsy gibon)) . I used xp on my ubuntu as vm. But after upgrading to hardy heron i found some of my favourite softwares stop working in this new version. I was worried and tried to find the solution in several forum and after surfing lots of forum i was able to run my vmware server. :)

Here is the process to follow ( Here i’ve given detailed steps to follow for new installatioin, you may have linux-headers, build-essential, xinetd installed in your pc, if so, then ignore those step). Hope this will help.

step 1: Install linux-headers build-essential

sudo apt-get install linux-headers-`uname -r` build-essential

Step 2: The vmtools rely on the config.h header file, which does not exist in recent kernels. So, you’ll have to create a dummy file:

sudo touch /usr/src/linux-headers-`uname -r`/include/linux/config.h

step 3: Install xinetd

sudo apt-get install xinetd

Step 4: then install vmware server. (you have to download it) You can download vmware server 1.0.5 from here

sudo ./vmware-install.pl

Step 5: Now apply the patch. Download any any update 116 and run the runme.pl file (you may need to set 777 permission to vmware-any-any-update folder).

sudo ./runme.pl

Step 6: Now run vmware server from Applications -> System.

When you launch the application it might generate an error message saying that it can’t find the cairo version. just copy the files over.

sudo cp /usr/lib/libpng12.so.0 /usr/lib/vmware/lib/libpng12.so.0/
sudo cp /lib/libgcc_s.so.1 /usr/lib/vmware/lib/libgcc_s.so.1/

Now run vmware from Application->System/Other->Vmware Server Console.

That’s it.
Enjoy

How to grab data from other websites using curl

First of all, you need to enable curl support for php.  To do this, remove the comment (to enable curl operation) from php.ini file

To get a remote file executed, we need to pass http request from a php file. CURL is used for this purpose. Here is a simple example that you can try.

<?php

$ch = curl_init();

// set URL and other appropriate options

curl_setopt($ch, CURLOPT_URL, “http://www.google.com.bd/”);

curl_setopt($ch, CURLOPT_HEADER, 0);

$file_contents = curl_exec($ch);

curl_close($ch);

// display file

//echo $file_contents;

echo “<pre>”;

print_r($file_contents);

?>

Now what we generally do is parse the html and show any portion that you want in your own site or use these data to modify, update or for other purpose. Have fun. :)

how to set cron

Via the “crontab” command from the shell.

crontab -l will show you your currently set up cron jobs on the server.

crontab -r will delete your current cron jobs.

crontab -e will allow you to add or edit your current cron jobs by using your default text editor to edit your “crontab file”.

Note, vi has a bug in it and will not work to edit your crontab! We recommend nano (which is just like pico), which is the default editor anyway!

Your crontab includes all the cron jobs you’d like, with one cron entry per line. A cron entry looks like this:

45 2 * * *     /home/user/script.pl

# The first number is the minute of the hour for the command to run on.
# The second number is the hour of the day for the command to run on.
# The third number is the day of the month for the command to run on.
# The fourth number is the month of the year for the command to run on.
# The fifth number is the day of the week for the command to run on.

Here are some examples to help you learn the syntax for the numbers:
# 32 * * * * : will be run every hour on the 32nd minute.
# 12,42 * * * * : will be run twice an hour on the 12th and 42nd minutes.
# */15 */2 * * *: will be run at 0:00, 0:15, 0:30, 0:45, 2:00, 2:15, 2:30, …
# 43 18 * * 7: will be run at 6:43pm every Sunday.