Categories
Apache Web Server Tutorials & Tips PHP Tips & Tutorials SQL / MySQL Tips and Tutorials

How to bring down / optimize memory usage in your unmanaged Linux VPS box and avoid OOM (Out Of Memory) errors?

The other day I was very upset about some extraordinary down times of my unmanaged VPS box at Linode. As it’s unmanaged, support staff at Linode are not responsible for the failures. I contacted them and they told me it’s OOM (Out Of Memory), pointing me to the right documentation to figure out how to get the problem sorted out myself. After a few tweaks and observations for a week, so it seems that I have successfully optimized my VPS server to take on more traffic with less resources such as RAM.

The problem almost always lies in where the user is free to feed stuff to your website or program. Sometimes Convert Hub spikes in memory usage and forces my box to use swap that relies on disk I/O to work. This happens when someone uploads an ultra large picture to be processed or converted. While I may restrict the size of the picture that is allowed to be uploaded, I may also do the following settings to optimize the entire LAMP environment so the other websites enjoy it as well.

Apache 2 Low-Memory Optimization

Use this command to identify the MPM you are using:

apache2 -V | grep 'MPM' # for Debian-based systems
httpd -V | grep 'MPM' # for Fedora/CentOS systems

Find and change these settings in your Apache 2 configuration file (usually found at /etc/apache2/apache2.conf):

StartServers 1
MinSpareServers 3
MaxSpareServers 6
ServerLimit 24
MaxClients 24
MaxRequestsPerChild 3000

Switch to Lighttpd or Litespeed if possible.

MySQL Low-Memory Optimization

Same as above, find and change these settings of the MySQL configuration file (may be at /etc/mysql/my.cnf) accordingly:

key_buffer = 16K
max_allowed_packet = 1M
thread_stack = 64K
table_cache = 4
sort_buffer = 64K
net_buffer_length = 2K

PHP Low-Memory Optimization

Find your PHP configuration file (php.ini) and modify the PHP script memory limit to 32M or less (default is 128M):

memory_limit = 32M
Categories
Coupons and Promo Codes Hosting Tips & Deals My Personal Reviews

My WiredTree Review and Some Discount Coupon Codes

Update: Here’s my most recent review of WiredTree.

I had an enjoyable experience with WiredTree (Some Coupons) half a year back when I was starting a joint venture with one of my friends and needed managed VPS hosting. Joe Doss was very helpful in answering my concerns and questions before sign-up. After testing out their demo download and ensured of a good data center and smooth Internet connections, I decided to go with them.

I went with the $99 managed hybrid plan. I was then pretty new to VPS hosting / dedicated hosting where you are in control of much more stuff than when you are with shared hosting. Though they are all very well managed at WiredTree (click to activate coupon), it’s still a bit overwhelming with all the options and different control panel sections. I asked questions. A lot of them. And they responded to my support tickets within 15 minutes EVERY time, no matter when you submit them. I dealt with not just one of their support staff but quite a few of them and they are all quick, polite and to the point. When I search through my Gmail inbox, there are a total of 60 conversations (hundreds of messages back and forth) I had with them in a short matter of less than one month. They were professional and kind in every message they addressed to me.

The hosting part of my joint venture was absolutely awesome. If it weren’t the decision to abort the project with my friend, I’d trust the most important of my sites to WiredTree. So when I told them that I had to close the contract and leave them after just one month, I was kind of upset for them because they have been so nice to me. They replied to my request to close my hosting account with complete understanding and even offered me refund for the remaining days of the month (it wasn’t a full month, just 20 days or so), I asked them to keep it.

As for uptime and server performance, I didn’t set up any 3rd party monitoring or pinging service but as I was working furiously on the project in the 20 days, accessing my websites at WiredTree thousands of times and hundreds of hours, I have not seen the slightest of indications of slowness or down time.

4.8 / 5 from me.

WiredTree Coupons

You can get very nice discounts by using one of these coupons of WiredTree when you host with them, such as extra 50% RAM, extra 50% bandwidth or lifetime 20% off. Just enter the code in the Coupon Code text box and hit Update Total button on the order page. All coupon codes listed there are confirmed to be working as of today, except V768-333333 that may be unreliable.

Categories
vBulletin Tips

How to Enable / Change vBulletin Default Thread Subscription Mode for New User Registrations?

One of the foremost things you want of your own vBulletin forum is that the users can engage in it as much as they would. Though email subscription is a little too bothering than people need, control panel subscription that lists all the threads your users have started or participated in will definitely increase the vitality of your community because they can easily find out if their threads / posts have been responded to and then feel compelled to post back.

The default subscription mode when a new user registers with vBulletin is no subscription at all. People would have no way to find out how their posts have been received and responded to thus would become engaged in the conversations. You should turn the control panel subscription on by default so all new users will subscribe to their own threads or threads that they have posted in automatically.

Log in your vBulletin control panel:

Admin CP –> Settings –> Options –> User Registration Options –> Default Registration Options –> Automatic Thread Subscription Mode

Select the dropdown list to Subscribe with no notification. And click Save. However, for users who have already registered, they’d have to manually change their account settings to change their subscription options:

User CP –> My Settings –> My Account –> General Settings –> Messaging & Notification –> Default Thread Subscription Mode

Change it to Through my control panel only.

Categories
.htaccess Tutorials & Tips Information Security

Use .htaccess to allow access only from a single HTTP referrer

Sometimes you want the user to access something (a web page or a downloadable file) only by clicking a link on your own website instead of being able to directly access it by typing in the URL address in the browser address bar. This is achievable by a few lines in .htaccess.

RewriteEngine On
RewriteCond %{HTTP_REFERER} !(www.)?example.com/download-page.php
RewriteRule .* - [F]

Write down the above lines in the .htaccess of the directory that you want users to access only by clicking links on http://www.example.com/download-page.php or http://example.com/download-page.php. Direct access to download stuff from the directory or from any other HTTP referrer will fail.

While this may not be bullet proof as referral information can be faked from the client side, it is a simple solution that should suffice in most cases. For example, this can be used to prevent hot linking from other websites that link directly to something on your website, reducing traffic stealing.

Categories
CSS & HTML Tips

The Ultimate Way to Cloak and Hide any Website Address or URL (Stealth Forwarding)

Most of the existing URL cloaking services are only a redirection by a randomly generated short URL. The real URL of the target website or web page will eventually be revealed when the visitor arrives at it after the obscure redirection. So how to ACTUALLY hide and cloak the destination URL of any website or web page so the address bar of the browser stays unchanged? In other words, how to create a stealth forwarding?

With a simple HTML web page, you can do that very easily. Copy and paste the following HTML code into a file named google.html and save it at example.com/google.html:

<!doctype html>
<html>

<head>
<title>Google</title>
<style type="text/css">
body {margin:0;}
iframe {padding:0;border:0;position:absolute;width:100%;height:100%;}
</style>
</head>

<body>
<iframe src="http://www.google.com/"></iframe>
</body>

</html>

Now navigate to your website http://www.example.com/google.html. It’s Google’s home page no problem. Better yet, the URL in the browser address bar doesn’t change to http://www.google.com/.

Categories
Free Webmaster Resources Internet Tools My Products & Services

Create Contact and Survey Forms with FormKid.com the Free Online Form Builder

I just finished creating yet another web application that may be useful to fellow webmasters, FormKid.com. It helps you create professional online web forms for your website. Check out what I created just now, a contact form for Kavoir.com. You can contact me by filling out and submitting the form from now on!

Currently you can add 8 different types of input controls to your forms, namely

  1. Single Line Text
  2. Paragraph Text
  3. Check Boxes
  4. Radio Buttons
  5. Dropdown Selection
  6. Section Break
  7. Arbitrary HTML
  8. Captcha

Captcha is for recognizing and capturing spams and uses one of the 3 available approaches at your choice. The reCaptcha service that’s recently acquired by Google is one of them. So you can be rest assured that your form will stay clear of online spamming.

I’m planning to add more features such as advanced entries management in future but not until this application proves itself to be useful and popular. Before that, a lot of work need to be done to make the whole thing smooth, safe and frustration-free. Please join in the forum and let me know of your ideas.

If all you need is a simple PHP contact form, our company Simple PHP Script has it.

Categories
Free Webmaster Resources Internet Tools My Products & Services Web Design Tips and Insights

How to convert .png, .gif, .bmp or .jpg images to .ico icons to make favicon.ico for your website?

image conversion tool Over a year ago I created this online web application Convert Hub by the help of the splendid open source image manipulation library Netpbm. Give it a try, upload an image and convert it to another format. But not just that, it’s also capable of resizing an image, rotating or flipping it.

I love it. It’s simple yet adequately useful. The best part of it for a webmaster like me is that it can convert other image formats such as .bmp, .jpg, .gif and .png to .ico so I can use them as favicon.ico for my sites. Try these US state flags and convert them in any way you want!

It’s a great tool and gained tremendous popularity. I know this because one day DreamHost warned me of overwhelming server resource usage and took it down for good reasons. I had to move it elsewhere and Linode is where it currently resides on.

Server side computing is too expensive for a free application like this. After a few ideas and thoughts, I decided to create a client side software program to do the job instead. It’s called Batch Image Converter. And it proves to be much better. It doesn’t come with a daily limit on the number of conversions allowed per IP but you can do as many conversions as you want. The whole software consists of one single executable file, there’s even no need to go through any installation steps. It’s totally green to your system. What’s best, it can work in batches which means you are able to perform operations such as format conversion and dimension resizing on a lot of images by a single click.

All you need is to download it there. It’s free. The problem is that it only supports Windows for now. I’m planning on rolling out versions for other platforms but this may not happen soon.

Please do let me know what you think of the application in the forum.

Categories
PHP Tips & Tutorials

Simplest PHP Hit Counter or Download Counter – Count the Number of Times of Access (Page Views or File Downloads)

Here’s how you can create yourself the simplest PHP hit counter that records the number of times any resource on your website that has been accessed (visited or downloaded). It can be either a web page or a downloadable file package. The hits number will be stored in a plain text file named count.txt.

Hit counter for a web page

You have a web page at here: http://www.example.com/mypage.php and you want to display the number of times this page has been visited on the web. Put these lines in mypage.php where you want the hit count displayed:

<?php

$hit_count = @file_get_contents('count.txt'); // read the hit count from file
echo $hit_count; //  display the hit count
$hit_count++; // increment the hit count by 1
@file_put_contents('count.txt', $hit_count); // store the new hit count

?>

Depending on the permissions set, you may need to manually create the text file count.txt. With most hosts, however, this snippet should automatically create the file for you. If it doesn’t work, create a text file count.txt in the same directory with mypage.php and put an 0 in it.

Download counter for a downloadable file package

To record the number of times a file has been downloaded, for instance, for a file located at here: http://www.example.com/download/pics.zip, first you need to create a PHP file named download-pics.php, place it in the /download directory and put these lines in it:

<?php

$hit_count = @file_get_contents('count.txt');
$hit_count++;
@file_put_contents('count.txt', $hit_count);

header('Location: http://www.example.com/download/pics.zip'); // redirect to the real file to be downloaded

It’s basically the same with the counter of web page hits except that download-pics.php redirects to the real file URL after recording the hit in count.txt. Similarly, you may need to create count.txt in /download directory and put an 0 in it for the first time.

Now, instead of giving the real URL of the file to your user, you would give them this URL:

http://www.example.com/download/download-pics.php

So they will download pics.zip from here instead of from the real URL or the download hit will not be recorded.

To show the number of times pics.zip has been downloaded, just put these lines in the intended place of any PHP file that’s located in the /download directory (the same directory of count.txt):

<?php

$hit_count = @file_get_contents('count.txt');
echo $hit_count;

?>
Categories
.htaccess Tutorials & Tips Information Security PHP Tips & Tutorials

Turn off and disable magic_quotes_gpc in .htaccess

It’s not only insecure but it inconveniently commands the use of PHP function stripslashes() every time you pull something from the database or when you get something from the client side. While most of the hosts out there are using factory settings of PHP that turn off magic_quotes_gpc by default, there are a few that don’t.

The value of magic_quotes_gpc cannot be set with the ini_set() function after PHP 4.2.3, some hosts enable custom php.ini in your home directory which you can use to set magic_quotes_gpc to 0 (zero) or false. Otherwise, you’d have to resort to .htaccess to set the PHP configuration values for your local directories.

To turn off magic_quotes and magic_quotes_gpc off in .htaccess, simply put these lines in the .htaccess file of your site / directory wherein you want magic_quotes or magic_quotes_gpc disabled:

php_value magic_quotes 0
php_flag magic_quotes off
php_value magic_quotes_gpc 0
php_flag magic_quotes_gpc off
Categories
Free Web Templates

A simple business web template with PHP contact form

The other day I created a simple website template in PHP for one of my friends and he eventually decided that he’s not going to need the website any more so I’m releasing it here for just $2.5 a copy. You are free to use it on any sites that you own.

Just purchase it at here: http://www.winkcart.com/store/phpscripts/foo-business-website-template/ and use the coupon code: SPECIAL5 to claim the $5 discount. You will be immediately downloading the template after paying via PayPal. Totally automatic.

I wanted to set up a demo for this template but it only works in the root directory of the domain so I’m going to save the trouble. If you decide that you don’t like it after paying and downloading, just let me know via the contact from on the sales page and I’ll issue the refund. No questions asked. 😉

Update: We have also a business directory script and a contact form script readily to be deployed to your website. Very easy to use and install.