May 10th, 2012 | Tags: , , ,

From Google Webmaster Tools:

HTTP/1.1 404 Not Found
Date: Thu, 10 May 2012 06:43:57 GMT
Server: Apache/2.2.14 (Ubuntu)
X-Powered-By: PHP/5.3.2-1ubuntu4.10
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 5626
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="bg-bg" lang="bg-bg">
<head>
<title>Страница грешка - 404, 404 Error page</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

The PHP code

       header('HTTP/1.1 404 Not Found');
        readfile('notfound.html');
        die();
May 10th, 2012 | Tags: , , ,

To achieve permanent URL redirect 301 as shown from Google Webmaster Tools:

Old URL is  http://www.example.com/details.php?id= ….. ,  new URL is SEO friendly http://www.example.com/seo-friendly-url.html

This is how Googlebot fetched the page.
URL: http://www.webdir.bg/details.php?id=4&KeepThis=true&TB_iframe=true&height=340&width=600
Date: Thursday, May 10, 2012 12:10:50 AM PDT
Googlebot Type: Web
Download Time (in milliseconds): 343
HTTP/1.1 301 Moved Permanently
Date: Thu, 10 May 2012 07:07:52 GMT
Server: Apache/2.2.14 (Ubuntu)
X-Powered-By: PHP/5.3.2-1ubuntu4.10
Location: http://www.webdir.bg/%D0%B3%D1%80%D0%B0%D0%B4%D0%B8%D0%BD%D1%81%D0%BA%D0%B8.html
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 20
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8

PHP Code:

    header('HTTP/1.1 301 Moved Permanently');
    $location = "www.example.com/newurl.php";
    header("Location: $location",true,301);
    die();
October 13th, 2011 | Tags: ,

XCache is a fast, stable  PHP opcode cacher that has been tested and is now running on production servers under high load. Install php5-xcache:

apt-get install php5-xcache

Configuration file is /etc/php5/conf.d/xcache.ini . Some of major config options:

extension=/usr/lib/php5/20090626/xcache.so - load xcache
xcache.admin.enable_auth = On - enable auth of admin page
xcache.admin.user = "UserName" - username
xcache.admin.pass = "ca34ew" - password, must be md5(password)
xcache.size = 256M - memory used for xcache
xcache.coverager = On - to enamble coverage
xcache.coveragedump_directory = /tmp

To enable xcache admin page, create file /etc/apache2/conf.d/xcache.conf

Read more…

September 21st, 2011 | Tags: , ,

Refreshing iframe using jQuery.

setInterval(function() { loadFrame(); }, 1000);
function loadFrame() {
    var frames = jQuery('._frameToRefresh');
    var link = 'http://blog.webdir.bg/demo/iframe-time.php';
    frames.each(function(index) {
    	jQuery(this).slideDown('slow');
    	jQuery(this).attr( 'src', link) ;
    });
}

Read more…

September 21st, 2011 | Tags: , ,

Apache config: (you need to set AllowOverride all)

<Directory /var/www/>
                Options FollowSymLinks MultiViews
                AllowOverride all
                Order allow,deny
                Allow from all
</Directory>

Create .htaccess file in document root ( /var/www/.htaccess ) and set

AddHandler application/x-httpd-php js
August 3rd, 2011 | Tags:

If you are using http://pagespeed.googlelabs.com to view the speed your site, some of most common suggestions for improvement is Leverage browser caching

To set up caching you need to edit apache configuration (This code uses the FilesMatch directive and the Header directive to add Cache-Control Headers to certain files):

                <IfModule mod_expires.c>
                        ExpiresActive On
                        <FilesMatch "\.(js|jpg|jpeg|png|gif|swf|css|js)$">
                                ExpiresDefault "access plus 7 days"
                        </FilesMatch>
                </IfModule>
June 8th, 2011 | Tags: , , , , ,

Ubuntu 10.04 configuration:

Install ifenslave — Attach and detach slave network devices to a bonding device.

apt-get install  ifenslave

Ubuntu 10.04 introduce a new way of configuring bond interface ( you don’t need to use /etc/modprobe.d/aliases.conf ).
Open and edit /etc/network/interfaces

# The loopback network interface
auto lo
iface lo inet loopback

auto bond0
iface bond0 inet static
        address 192.168.200.5
        netmask 255.255.255.0
        network 192.168.200.0
        broadcast 192.168.200.255
        bond-slaves eth0 eth1
        bond_mode 802.3ad
        bond_miimon 100
        bond_xmit_hash_policy 1
        bond_lacp_rate 1

bond-mode 802.3ad - use 802.3ad protocol. You can read supported modes in kernel’s documentation bonding.txt
bond_xmit_hash_policy 1 – default value is 0

  • 0 (layer 2) - Uses XOR of hardware MAC addresses to generate the hash.
  • 1 (layer3+4) - This policy uses upper layer protocol information, when available, to generate the hash. This allows for traffic to a particular network peer to span multiple slaves, although a single connection will not span multiple slaves.

bond_lacp_rate 1 - default 0

April 15th, 2011 | Tags:

You can use a port on EX4500 as access ( using native vlan ) and trunk.
For our example on a linux box we have a tagged traffic (vlan 100) and untagged traffic ( vlan 10 ):
EX4500 configuration:

root@bravo# set interfaces ge-0/0/8 unit 0 family ethernet-switching port-mode tagged-access
root@bravo# set interfaces ge-0/0/8 unit 0 family ethernet-switching native-vlan-id 10
root@bravo# set interfaces ge-0/0/8 unit 0 family ethernet-switching vlan members 100
root@bravo# run show configuration interfaces ge-0/0/8
unit 0 {
    family ethernet-switching {
        port-mode tagged-access;
        vlan {
            members 100;
        }
        native-vlan-id 10;
    }
}
March 7th, 2011 | Tags:

To match a white space in MySQL table field use REGEXP.

SELECT username FROM mytable WHERE username REGEXP '[[:space:]]'

the result will be

+--------------+
| username     |
+--------------+
| user 474     |
| user 113     |
| user 22      |
+--------------+
March 4th, 2011 | Tags:

This howto is installed and tested on:

Distributor ID: Ubuntu
Description:    Ubuntu 9.10
Release:        9.10
Codename:       karmic
*******************************************************
PHP 5.2.10-2ubuntu6.7 with Suhosin-Patch 0.9.7 (cli) (built: Jan 12 2011 17:56:07)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
*******************************************************
Linux sns 2.6.31-14-server #48-Ubuntu SMP Fri Oct 16 15:07:34 UTC 2009 x86_64 GNU/Linux

P.S ( this howto is tested and working also on Ubuntu 10.04 )
STEP 1 : install the following packages:

apt-get install rrdtool librrd-dev php5-dev gcc binutils

STEP2: Go to http://oss.oetiker.ch/rrdtool/pub/contrib/ to get the PHP rrdtool source : php_rrdtool.tar.gz Read more…