Restore MySQL Database using mysqlbinlog

1.  Get log for database to restore
$ mysqlbinlog --database=db_name mysql-bin.000001 > /tmp/db/restore.sql
$ mysqlbinlog --database=db_name mysql-bin.000002 >> /tmp/db/restore.sql
$ mysqlbinlog --database=db_name mysql-bin.000003 >> /tmp/db/restore.sql

2.  Edit restore.sql

3.  Execute SQL commands on restore.sql

Posted in Database | Tagged , | Leave a comment

mod_deflate for faster page load

Just make sure that the Header module is loaded
LoadModule headers_module /path/mod_headers.so

<IfModule mod_deflate.c>
# Insert filter
SetOutputFilter DEFLATE

# The value must between 1 (less compression) and 9 (more compression).
DeflateCompressionLevel 9

# Netscape 4.x has some problems…
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won’t work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

# Don’t compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don’t deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</IfModule>

Posted in Apache2 | Tagged , , , | Leave a comment

Synchronize time in Linux

This procedure needs root access.
$ sudo ntpdate pool.ntp.org

Posted in Linux, Linux Administration | Tagged , | Leave a comment

Prohibit execution of PHP scripts inside include directory

  1. Create a PHP file
    /**
    * prepend_goto_index.php
    */
    header('Location: http://' . $_SERVER['HTTP_HOST']);
  2. Inside the include directory, create .htaccess file
    php_value auto_prepend_file prepend_goto_index.php
Posted in PHP | Tagged , | Leave a comment

Disable PHP in directory

In .htaccess
php_flag engine off

Posted in Apache2, PHP | Tagged , | Leave a comment

Ignore whitespace in a Subversion diff

$ svn diff --diff-cmd diff -x -uw /path/to/file

Solution copied from Ignore whitespace in a Subversion diff

Posted in subversion | Tagged , , | Leave a comment

selective mysqldump

$ mysqldump -uroot -p DB TBL --where="COL_ID=3" | grep INSERT

Posted in Database, MySQL | Tagged , , | Leave a comment

Save streaming video using mplayer

$ mplayer -dumpstream -dumpfile stream_video_name.wmv mms://example.com/video_name.wmv

Posted in Linux | Tagged , | Leave a comment

Plesk: command to reconfigure one site

/usr/local/psa/admin/sbin/websrvmng -u --vhost-name=domain.com

If you encounter WARNING: You are using obsolete option, use corresponding option of httpdmng.

/usr/local/psa/admin/bin/httpdmng --reconfigure-domain domain.com

Posted in Linux Administration | Tagged | Leave a comment

Creating subdomain in Plesk

To have the server point to the subdomain instead of the domain when the url has “www” prefix then do the following:

Create /srv/www/vhosts/<domain>/subdomains/<subdomain>/conf/vhost.conf

Insert ServerAlias www.<subdomain>

Posted in Apache2 | Tagged , , | Leave a comment