wordpress blog stats

Archive for February, 2010

If you are getting the following error while browsing any local website in Ubuntu like:

You don’t have permission to access http://localhost on this server files or folders

then you may not be having the full rights to access that folder or file(s). On the other end, you may be accessing the folders and files through the File Browser (while using gnome-terminal command sudo nautilus etc), but while browsing them through any web browser like Firefox etc., you may be getting the permissions error as mentioned:

403 Forbidden

You don’t have permission to access http://localhost on this server (or any of localhost’s subdirectory)

Apache/2.2.11 (Ubuntu) PHP/5.2.6-3ubuntu4.5 with Suhosin-Patch Server at localhost Port 80
etc.

For the solution, simply do the following method to grant yourself and all of the users, including admin, groups and other users, the read, write and execute rights, to stop getting such errors:

Goto Applications -> Accessories -> Terminal

and write the following code:

chmod a+rwx foldername or filename

with full path, for example:

Granting Rights on Folder:

If you are getting such error on the directory:
/var/www/webtechquery/

then the command should be:

chmod a+rwx /var/www/webtechquery/
or
chmod a+rwx /var/www/webtechquery/*

Granting Rights on File:

If you want to grant full rights on files e.g. abc.php, then the command should be:

chmod a+rwx /var/www/webtechquery/abc.php

If you want the rights to be granted to only the owner, group or specific user(s), then use the following commands:

For Owner:

chmod o+rwx /var/www/webtechquery/abc.php

For Group:

chmod g+rwx /var/www/webtechquery/abc.php

For User:

chmod u+rwx /var/www/webtechquery/abc.php

where:

o = owner
u = user
g = group

and

r = read
w = write
x = execute

CSS Compressor and CSS Uncompressor or CSS Beautifier or CSS Tabifier

CSS Compressor

If you have a big CSS file and want it to be compressed, remove comments and whitespaces to make it seen as one-liner code, then CSS Compressor tool can help.
Following is the web where you can compress your CSS as well as HTML codes:

http://tools.arantius.com/css-compressor

CSS Uncompressor or CSS Beautifier or CSS Tabifier

On the other end, if you want your CSS code to be uncompressed, beautify and tabify, to make it look like a real code, with lines and functions sort of environment, then try the following URL for beautifying your code:

http://tools.arantius.com/tabifier

If you are about to save an IP address into a MySql table of type char or varchar, then it is preferable to make use of the SQL function INET_ATON and save it in integer format instead of char or varchar.

Why to convert from IP Address to Numeric (INET_ATON) ?

Well, this will let you save the value into integer instead of character, and when later, you want to search your saved IP addresses, then you can assume that searching on an integer field is pretty much faster than the string i.e. char, varchar etc.
Even it may help you in creating integer indexes instead of string, for the searching purpose.

How to convert from IP Address To Numeric (INET_ATON) ?

While saving the IP address into numeric or integer field, you can simply use the function as follows:

INSERT INTO tbl_test (id, ip_to_numeric)
VALUES (1, INET_ATON('117.34.70.115'));

Where tbl_test is the table name, and ip_to_numeric is the numeric field.

How to convert back from Numeric to IP Address (INET_NTOA) ?

After successfully converting and saving the values from IP Address into Numeric, you can reconvert those converted values into IP Address through the following query:

SELECT INET_NTOA(ip_to_numeric)
FROM tbl_test;

This will dispolay all the converted numeric IP addresses into their original format.

If you are having a table with huge amount of data, and

  1. want to check that which of the values are duplicate in a field, or which values are redundant, or
  2. want to make a field as unique, but don’t know how much data is redundant or duplicate to make it remove first, and then make it unique, then the following query will help you in finding the duplication or redundant values in a table:

SELECT id1 FROM tbl_test
GROUP BY id1
HAVING count(id1) > 1;

Where tbl_test is the table, and id1 is the field having redundant or duplicate values.

View, Add and Drop Indexes in MySql

In this short article, you will learn how to view, add and drop indexes using MySql:

To view the indexes in a table, try the following syntax, where test_table is the table name:

View Index in MySql

SHOW INDEX FROM test_table;

Add Index in MySql

To add an index on a field, try the following syntax, where index name is indexed_id having the field name test_id :

ALTER TABLE test_table
ADD INDEX indexed_id (test_id);

Drop Index in MySql

To drop or remove index on a field, try the following syntax:

ALTER TABLE test_table
DROP INDEX indexed_id;

Please note that if you are running an online website with heavy traffic, and you want to modify any index, for which you first have to drop the previous index and then add it. Then it is highly recommended to add the index first, with another index name, and then drop the previous index. By doing this, you will be able to have the following benefits:

  • If in case the drop index query runs successfully, and add index query fails, then the time between fixing that query might be very critical, as it will affect the performance of your website, and the users will have difficulty in accessing your website in that time.