cPanel: How to block visitor by country through GeoIP

To block a certain country IP range, you do not need to know which IP range it is and what you need is to use the GeoIP feature.

To install GeoIP, refer to the following URL,
http://www.mickgenie.com/cpanel-how-to-install-mod_geoip

Next, you will need to insert the following command to the .htaccess file,

RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CN$
RewriteRule ^(.*)$ http://www.google.com [L]

The command use to redirect China IP to google.com***

***This is an example only and it is not to abuse any user/visitor reside in China.

WordPress migration with FTP

Scenario:
Old Site: www.domain.com/blog
Path: /home/domain/public_html/blog
New Site: www.domain.com (Assume the site is empty)
Path: /home/domain/public_html

In order to move the WordPress account manually without any plugin, you may choose to use FTP to perform download and upload.

Folder/File:
1.  Download your web file/folder from /home/domain/public_html/blog to your PC.
2. Reupload those file/folder back to the /home/domain/public_html.
3. If you using Permalink and having mod_rewrite rule, you may edit your .htaccess file from your local PC from,

RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]

To,

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

4. Upload the .htaccess file to /home/domain/public_html.

Database:
1.  You may backup through SSH, PHPMyAdmin or any other method.
2. Download the backup file through FTP.
3. Open Notepad, find and replace from www.domain.com/blog to www.domain.com.
4. Upload the database back to the server.

WordPress migration with SSH

Scenario:
Old Site: www.domain.com/blog
Path: /home/domain/public_html/blog
New Site: www.domain.com (Assume the site is empty)
Path: /home/domain/public_html

In order to move the WordPress account manually without any plugin, you may done it through SSH without any trouble.

Folder/File
1.  Log into the SSH.
2.  Copy the folder and file from blog folder to main site.

cp -apr /home/domain/public_html/blog /home/domain/public_html

3. If you using Permalink and having mod_rewrite rule, you may edit your .htaccess file,

vi /home/domain/public_html/.htaccess

4. Change the rewrite rule from,

RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]

to

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Database:
1.  Dump the database. Assume your database named wordpress.

mysqldump wordpress > wordpress.sql

2. Change the entry from www.domain.com/blog to www.domain.com.

sed -i 's/www\.domain.\com\/blog/www\.domain\.com/g' wordpress.sql

3. Restore the database back to the domain.

mysql wordpress < wordpress.sql

Howto: Password protected a folder from Apache .htaccess

To protect a folder from your website, you may actually use the htpasswd feature available from the server.

To create a password protected folder to /home/user/public_html/important with user named admin, run the following command.

[[email protected] ~]# htpasswd -c /home/user/public_html/.htpasswd admin
New password:
Re-type new password:
Adding password for user admin
[[email protected] ~]#

Then, add the following code to your .htaccess file located at /home/user/public_html folder.

AuthUserFile /home/user/public_html/.htpasswd
AuthName "important"
AuthType Basic
Require valid-user

Now, access to your folder with the credential created.

Howto: Enable FastCGI from Linux

To enable FastCGI from your Apache server, you may follow this article.

1. Copy the php.ini file to your cgi-bin folder.
2. Create a file named php.fcgi in the cgi-bin folder.
3. Insert the following script,

#!/bin/sh
export PHP_FCGI_CHILDREN=1
export PHP_FCGI_MAX_REQUESTS=10
exec /usr/local/cpanel/cgi-sys/php5

4. Change the php.fcgi permission to 755.
5. Create/Edit the .htaccess file and insert the following script.

AddHandler php5-fastcgi .php
Action php5-fastcgi /cgi-bin/php.fcgi

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_METHOD} POST
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.

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

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.
http://www.php.net/manual/en/timezones.php

How to Disable directory listing

Some web hosting server setting allow the directory listing by default and you wish to disable it as you might not use the hosting space for web purpose but storage purpose.

There are several ways to disable it through your space as steps below.

Apache Linux with cPanel
If your hosting company provide cPanel, it will be great it allow you easily to disable it through the control panel.

In this guide, Mick Genie guide you how to disable it through cPanel 11.25(x3 themes).
1. Log into the cPanel control panel.
2. Look for Advance box and click on Index Manager.
3. A pop up box show and select the domain name that you wish to disable it.
4. Select the folder.
5. From the radio button, select No Indexing and save it.

Apache Linux without cPanel
If you do not come with cPanel, it isn’t a hard step to disable it.

1. Log into the SSH console.
2. Change directory to the public_html path(assume your root path is /home/mickgenie/public_html/)

cd /home/mickgenie/public_html

3. Edit/create the .htaccess file

vi .htaccess

4. Add the line as below to the .htaccess file by click on Insert button and insert,

Options -Indexes

5. Save it by type in :wq!.

How to disable mod_security for an account

Sometimes, you might want to disable the mod_security applied to the virtual server and you might wonder how to do it.

If you are using Apache with mod_security, it could be done from the configuration file.

However, you have to understand the Apache version and mod_security version that you used.

Normally, a hosted server will use Apache 1.x with mod_security 1.x and Apache 2.x with mod_security 2.x.

To find out the Apache version, you may use the following command.

httpd -v

With mod_security 1.x, you may use the following command from each of the virtual host path and add into the .htaccess file.

Continue reading How to disable mod_security for an account