Howto: Install Apache 2.2.x and PHP 5.3.x on CentOS 5

Assume that you do not want to spend money on your server to have a control panel and having minimal requirement for your website,

1. Install the required packages,

yum install bison flex gcc db4 db4-devel libxml2-devel libpng-devel mysql-devel make

2. Download Apache source (refer the latest one from


3. Download PHP source (refer the latest one from


4. Build the Apache,

tar zxvf httpd-2.2.21.tar.gz
cd httpd-2.2.21
./configure --enable-so --enable-rewrite=shared
make install
cd ..

5. Build the PHP,

tar zxvf php-5.3.8.tar.gz
cd ../php-5.3.8
./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql --enable-bcmath \
--enable-ftp --enable-magic-quotes --with-pear --enable-sockets --with-zlib --with-gd
make install
cp php.ini-production /usr/local/lib/php.ini
cd ..

6. Now, start the Apache services,

/usr/local/apache2/bin/apachectl start

Allow allow_url_fopen on cPanel server

Sometimes, you might want to enable allow_url_fopen from your account for some purpose.

To enable the allow_url_fopen, you may need to understand if you are using a suPHP server.

With non phpsuexec or suphp server,
1. Go to /usr/local/apache/conf/ path,
cd /usr/local/apache/conf/
2. Open the file named /usr/local/apache/conf/httpd.conf and find if you got the line with “Include “/usr/local/apache/conf/…”
3. Remove the # symbol if it is there.
4. Create the file in userdata according to step 2 where the username should replace with your cPanel username.
vi /usr/local/apache/conf/userdata/<number>/<username>/allowurl.conf
5. Add the following command and save it.
<IfModule mod_php5.c>
php_admin_value allow_url_fopen On
php_admin_value allow_url_include On
6. Run the following command,
/usr/local/cpanel/bin/apache_conf_distiller –update
service httpd restart

With suPHP server,
1. Copy the default php.ini to your user folder where username is your cPanel username.
cp /usr/local/lib/php.ini /home/<username>/public_html/
2. Change the value as,
allow_url_fopen = On

Optimize your site Apache mod_deflate compression

Website compression is a way to save your bandwidth and speed up your website. You may easily apply this deflation to your site by referring to this article.

1. First of all, you should compile mod_deflate to your Apache.
2. Next add the following script to your .htaccess.

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

Increase Apache 2.0 max clients hard limit from cPanel

If you are using cPanel with Apache 2.0, you will find out your Apache max clients limit is set to 256 only and this is a little harder for a normal server to serve their user.

To make this setting done, you may refer to the step as below.
1. Log into WHM.
2. Select Service Configuration and click on the Apache Configuration.
3. Select Global Configuration.

4. Change the ServerLimit and MaxClients limit to 512, save it.
5. Rebuilt the Apache.

With the above term, make sure that you have enough CPU and Memory resource or your server will down because of limited resource.

Block WordPress spam comment with .htaccess

If you have self hosted WordPress and always got lots of spam comment, you may actually blocked them through your .htaccess file.

The source code as below was get from AllGuru.Net,

RewriteEngine On
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !.*xyz.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]

Open the .htaccess file and place the code as above then you shall be able to filter the spam automatically.

Install Memcache with cPanel that running CentOS

I was trying to install Memcache from cPanel from yesterday night but it seems to be sucks when installing from cPanel control panel.

Hence, I am sharing the step as below which I used to compiled manually from the shell.

Create a temporary folder
1. As it is a manually work, you might want to clear the source file after the installation, so create a folder as command below.

mkdir ~/memcache

Install LibEvent
To install memcache, you will need LibEvent, go to their site to get the latest version.

cd ~/memcache
tar zxvf libevent-1.4.14b-stable.tar.gz
cd libevent-1.4.14b-stable
make install

Install Memcache
Now, install the memcache and get the latest version from their site.

cd ~/memcache
tar zxvf memcached-1.4.5.tar.gz
cd memcached-1.4.5
./configure --with-lib-event=/usr/local/
make install

Install PHP Memcache
Now, install PECL Memcache and get the latest version.

cd ~/memcache
tar zxvf memcache-2.2.6.tgz
cd memcache-2.2.6
make install
vi /usr/local/lib/php.ini

Find the extension as below and if it is not existed, add it in the php.ini.

Restart the Apache services.

service httpd restart

Domain, subdomain, addon domain or parked domain not able to remove from cPanel

Sometimes, when you want to remove a domain, sub-domain, addon domain, or even parked domain, you will found out the account is not belong to the owner of you or you might found out the domain is existed but does not belong to any owner.

With this case, you may firstly check for the ownership from the SSH with root.
/scripts/whoowns domain
where domain should be the domain name that you want to find who own it.

If you are not able to find any result from the above script. Run the following script(each a line).

Enable SSI through htaccess

SSI, Server Side Include is a simple interpreted  server-side script that used shtml to include some of the option from external file.

With SSI enabled, user may use include feature to include file or virtual directory.

To enable SSI, you may use .htaccess file command as below.

AddType text/html .shtml
AddHandler server-parsed .shtml
Options Indexes FollowSymLinks Includes

With the command as above it is to tell the server that the .shtml extension (Parsed HTML).

Either way, you may use .html to act as the server-parsed file.

AddHandler server-parsed .html

Perl Script getting Premature End Of Script Headers Error

Assume that you have a sample Perl script that only print the clear text and you still got the premature end of script headers error.

Sample Perl Script used.

print “Content-type: text/html\n\n”;
print “Hello, Mick Genie!\n”;

Step to overcome the problem.

1. Check the Apache error_log or domain error log.
2. Check if the perl script come with permission 755 where this will allow the script to execute.
Continue reading Perl Script getting Premature End Of Script Headers Error

Changing TimeZone in .htaccess file

As you know, the server hosted for your web site’s time zone might not the time zone that you want as you might purchased a hosting server hosted somewhere from your location.

Hence it is important if you could define the timezone from the server setting instead of working on each of the script.

Although you set set a global value the inc file from each of your script, but isn’t it easier if you set it to your .htaccess file?

Open up your .htaccess file, enter the command as below.

SetEnv TZ location

The location indicate the timezone that you want to set, for more information on the location information, you may refer to the URL as below.