How to Change the Timezone in Linux

by admin on November 10, 2009
in Linux, Servers

  1. Logged in as root, check which timezone your machine is currently using by executing `date`. You’ll see something like Mon Nov 9 13:49:01 EST 2009, PST in this case is the current timezone.
  2. Change to the directory /usr/share/zoneinfo here you will find a list of time zone regions. Choose the most appropriate region, if you live in Hong_Kong or the Singapore this directory is the “Asia” directory.
  3. Read more…

Install bandwidth monitor vnstat

by admin on September 5, 2009
in Linux, Servers

vnStat is a network traffic monitor for Linux that keeps a log of daily network traffic for the selected interface(s). vnStat isn’t a packet sniffer. The traffic information is analyzed from the /proc -filesystem, so vnStat can be used without root permissions. However at least a 2.2.x kernel is required.

  1. Install vnStat
    wget http://humdi.net/vnstat/vnstat-1.7.tar.gz
    tar zxvf vnstat-1.7.tar.gz
    cd vnstat-1.7
    make
    make install
  2. Read more…

Block IP Addresses With IPtables & APF

by admin on September 5, 2009
in Security, Servers

Have a user that keeps hammering your FTP or trying to login over and over and over again that you just want to ban and never see again? We’ll show a quick and dirty method to ban an IP address from the server.

We commonly receive questions like:
“I would like to ban that ip address to prevent the access to the server.
how can i ban that Ip address from the server?”

Simple !

Login to the server as root.

  1. If you are running iptables, you can enter:
    iptables -A INPUT -s IP_ADDRESS -j DROP
    Ex: Block IP 68.72.72.25
    iptables -A INPUT -s 68.72.72.25 -j DROP
  2. Read more…

Tuning the Apache MaxClients parameter

by admin on July 3, 2009
in Apache

One thing that can have a really drastic effect on a large site using Apache, is the value assigned to the MaxClients parameter.

This parameter defines how many simultaneous request can be served. Any connection request from browsers that come in after that will be queued.

Apache prefork, StartServers, MaxSpareServers and MinSpareServers

In the most common case, you will be using Apache in the prefork mode, meaning one process per connection, with a pool of processes pre-forked to standby for connections. The number of spare processes is defined by the values MaxSpareServers, MinSpareServers, while the number to start is defined by StartServers.

Maxclients default

By default, the MaxClients parameter has a compiled in hard limit of 256. This can be changed by recompiling Apache however. Some distributions, or hosting companies raise this limit to a very high value, such as 512 or even 1024 in order to cope with large loads.

While this makes sense when the web server is serving static content (plain HTML, images, …etc.), it can be detrimental to a dynamic web application like Drupal. So often, we have clients calling because their web server has grind to a halt, and the reason would be a too high MaxClients value. Read more…

Simple AJAX Example

by admin on June 26, 2009
in Ajax

This aims to be the easiest possible example demonstrating AJAX (Asynchronous JavaScript and XML).

AJAX is a technique rather than a technology: It describes how JavaScript can be used to pull data from the server using the XML HTTP Request object and then insert this data into the website using DOM. This is done asynchronously – that is, in the background, without having to refresh the whole page. The technology which AJAX is based on has already been available for a while, the combination is what makes it new.

You can try the examples online or download them and run them locally (except for the PHP script, that would require a webserver with PHP).

1. The DOM

The Document Object Model is the internal representation of your website. The DOM is accessible by JavaScript and provides a way to programmatically insert, remove and modify tags in your website (except that they are called elements or nodes instead of tags, because the DOM manipulates the data model in memory and not the representation as XML). This example shows how to set the content of the

element with the id “foo” to “Hello, AJAX world!”:

<script type="text/javascript">
function replace() {
document.getElementById('foo').innerHTML = "Hello, <b>AJAX</b> world!";
}
</script>
<p><a href="javascript:replace()">Replace Text</a></p>
<div id="foo">
Hello, world!
</div>

Try here: dom.html
Read the Rough Guide to the DOM for more information. Read more…

Stop PHP nobody Spammers

by admin on June 25, 2009
in Php, Security, Servers

PHP and Apache has a history of not being able to track which users are sending out mail through the PHP mail function from the nobody user causing leaks in formmail scripts and malicious users to spam from your server without you knowing who or where.

Watching your exim_mainlog doesn’t exactly help, you see th email going out but you can’t track from which user or script is sending it. This is a quick and dirty way to get around the nobody spam problem on your Linux server.

If you check out your PHP.ini file you’ll notice that your mail program is set to: /usr/sbin/sendmail and 99.99% of PHP scripts will just use the built in mail(); function for PHP – so everything will go through /usr/sbin/sendmail =)

Requirements:
We assume you’re using Apache 1.3x, PHP and Exim. This may work on other systems but we’re only tested it on a Cpanel/WHM Red Hat Enterprise system. Read more…

Rotating Banner in PHP

by admin on June 17, 2009
in Php

This is a snippet that will rotate a banner on a page. All you have to do is set $File and $Images to the paths to the images. It will just do the next image in $Images in order. It doesn’t rotate banners for seperate users, it just goes through. Before you use it, create the $Stat file and set the contents of it to 0 and your ready to go!
Read more…

Text counter in PHP

by admin on June 17, 2009
in Php

A counter is an essential part of a site to know how many people are coming to site. Here is an easy way to make a counter. All you need is access to PHP and be able to chmod a directory. We’re going to save the amount of hits in a .dat file, so you don’t even need a mySQL database. First off, you have create a directory and CHMOD it 777 so PHP can write the counter.dat file.

Here is what we have to do:

  1. Use the file_exists() function in PHP and see if the counter.dat file exists. If it does, then open the file using the PHP fopen() function.
  2. Use the PHP fgets() function to find the number of hits there and save it in a variable.
  3. Add one to the variable.
  4. Close the file.
  5. Display the number of hits.
  6. Open the counter.dat file using the fopen() function and save it as a variable.
  7. Use the PHP fputs() function to insert the new number of hits.
  8. Close the file.
  9. If the counter.dat file doesn’t exist, then use the fopen() function and declare it as a variable.
  10. Use the Fputs() function and put a “1″ in there.
  11. Print out that 1 person has come to the page and then close the file.

Here is the code: Read more…

Changing Web Hosts ? Step-By-Step Guide

by admin on June 16, 2009
in Domain/Hosting

Every webmaster cringes at the thought of moving hosts. Like moving your home it can be messy and sometimes problems arise. But if you follow these simple steps, your move will be less painful.

Backup Backup Backup
If you’ve been diligent with your backups, you’ve got a lot of insurance to fall back on yet always make the latest backup. If you haven’t, before you do anything else, do a backup now. Backup anything and everything you can and don’t forget your database if your site relies on it. Save at least 2 copies and store them separately. One for you to work with, and the other as an archive. Do not underestimate how easy it is to copy over these files as you make changes or simply mess it up.

If you’re moving to a host who has as different control panel, make a manual backup by downloading all your files because different control panels may not be able to restore the backups made by your old host. They also have different directory structures so your file trees will be in a mess. If you need to, make a small note file with notepad with memos for you to remember the old server configurations. This will help you as you make changes on your new host server and save the confusion moving back and forth between hosts. Remember to make the correct transfer type (ASCII or Binary) as you download. If your download is not right chances are you’ll have a tough time getting your site to work on the new host server.

If server logs are especially important, remember to backup those too. There is no good way of moving logs yet because different hosts may log statistics differently. So the best thing to do is to download it and use a log analyzer on your computer to make references to later on.
Read more…

Create Random Text in PHP

by admin on June 16, 2009
in Php

Want to put a random quote on your site? Or randomize some other aspect of your site? It’s easy. You’ll want to use PHP or some other server-side scripting language instead of a client-side scripting language like JavaScript. Server-side languages write the content to the page in html before it ever leaves the server. Search engines will be able to read the content on your page, but with JavaScript they cannot, so you lose any content value of the random code. Also, if a user turns off JavaScript, that random content is lost. Google, MSN, and Yahoo will see that the content is changing often, and that may help your rankings (depending on your implementation).

Here’s how to put the random elements into your page, using PHP.

Step 1:
Create a text file called “myData.txt”. Open the file and put in your random elements, placing each random element on its own line, (whether text, images or html). Then place “myData.txt” in the same directory as your page containing the PHP script.

Step 2:
Place the following PHP code into your page where you want the random element:
Read more…

Next Page »