Tag Archives: linux

CEntos 6.7 Migrating from mysql-server/mysql-community-server into latest MariaDB

Ok, first you should install yum-replace plugin if you haven’t already have it.

yum install yum-plugin-replace

Get MariaDB packages repo from MariaDB repos builder here
MariaDB repo builder
You’ll get some repo config text that you can save to /etc/yum.repos.d/MariaDb.repo like these:

# MariaDB 10.1 CentOS repository list - created 2016-04-17 23:39 UTC
# http://mariadb.org/mariadb/repositories/
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos6-amd64

Do update your repo chache

yum update

If you’re installing mysql-server from CentOS 6.7 default repo, you should do this:

yum replace mysql-libs --replace-with=MariaDB-common

If you’re installing mysql server from webtatic repo (mysql55w-server), you should do this:

yum replace mysql55w-libs --replace-with=MariaDB-common

If you’re installing from MySQL Community repository, do this:

yum replace mysql-community-common --replace-with=MariaDB-common

Just answer with ‘Y’ if the yum replace command show you some conflicts.
Next, just install all MariaDB related packages:

yum install MariaDB-*

Start MariaDB:

/etc/init.d/mysql start

Confirm that you’re using MariaDB:

[root@www ~]# mysql --version
mysql  Ver 15.1 Distrib 10.1.13-MariaDB, for Linux (x86_64) using readline 5.1

Don’t worry, if you have successfully installing MariaDB over MySQL:

  1. your web app that use MySQL will not broken, no need to change anything
  2. your data will stay intact (no data loss)
  3. use MySQL commands as usual (such as: mysql -u root -p)
  4. the MariaDB config is still in /etc/my.cnf

In short, business as usual!

Play DASH video and DASH audio at the same time using VLC

VLC playing DASH video and DASH audio at the same time

As you may know, you can download youtube video using http://vrank.org/. The advantage of http://vrank.org/ over http://ytconv.net/ is that vrank allow you to download the video in their original format supplied by youtube. The one we will discuss is about DASH video and DASH audio formats. They are high quality video and audio formats but it has drawback: when you download a video in DASH video format you can’t hear any sound AND when you download in DASH audio format, you can’t see any video (obviously!).

DASH video and DASH audio formats option in vrank.org

DASH video and DASH audio formats option in vrank.org

Why? Well, the simple answer is: google/youtube separate the video into two stream: video and audio. So, when you are streaming a youtube video (using browser) in high quality format (720p and up), you actually download/stream from two different files.

Now, how can you play these two files (DASH video and DASH audio) at the same time? We will use VLC to do this!

  • Let’s assume you already downloaded the two files (DASH audio and video)
  • Open VLC
  • Access Menu: Media –> Open Multiple Files…
VLC: Media --> Open Multiple Files...

VLC: Media –> Open Multiple Files…

  • A new empty “Open Media” window will be opened, click on that “Add” button then browse and select your first file (could be DASH video or DASH audio file, not in particular order)
VLC: Open Media window

VLC: Open Media window

  • Check/click/activate “Show more options” checkbox
VLC: show more options checkbox

VLC: show more options checkbox

  • Check/click/activate “Play another media synchronously …” then click on “Browse…” button
VLC: play other media synchronously

VLC: play other media synchronously

  • A new empty “Open Media” window will be opened. Click “Add“, browse to your second files (either DASH audio or DASH video depended on your first opened file). Then click “Select” button (the button will become active/clickable after you choose your second file), this second “Open Media” window will be automatically closed.
VLS: a new empty "Open Media" window

VLS: a new empty “Open Media” window

  • Now, you’ll have the two files chosen and listed on the first “Open Media” window. You may click “Play” button.
VLC: two files is selected

VLC: two files is selected

VLC will play those two files synchronously, you may check it via VLC menu: Tools –> Codec Information, there will be two stream played together.

VLC playing DASH video and DASH audio at the same time

VLC playing DASH video and DASH audio at the same time


Save bandwidth, block image hot linking

Image hot-linking is (simply put): other site is showing your image that still on your server. This can cause problem for bandwidth limited website, they steal your bandwidth! Also, this doesn’t make visitor from that notorious site to come to your site.¬† More visitor for them, more bandwidth lost for you. We will handle this issue using htaccess.

Remember that to use .htaccess fully (including this tips), you have to activate Apache mod_rewrite.

In our case, we will allow only few sites that directly show/link our image. Other sites that have no permission will show an error/no leech image. This is the full .htaccess code:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} ^facebookexternalhit.*$ [OR]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?ahowto.net [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mp32u.net [NC]
RewriteCond %{HTTP_REFERER} !^.*google.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^.*bing.com/.*$ [NC]
RewriteCond %{REQUEST_URI}  !^/images/no_leech.jpg
RewriteRule \.(jpe?g|png|gif)$ http://www.ahowto.net/images/no_leech.jpg [L]


The explanation:

  • (line 1) Activate rule only if mod_rewrite is activated
  • (line 4) we don’t allow Facebook bot to steal our image. Comment (#) this line if you want to allow Facebook to grab image from your site (this is used by Facebook to create thumbnail image whenever FB users posting your website¬† URL)
  • (line 6-9) allow only few sites to direct link/hot link our image: ahowto.net, mp32u.net, google.com and bing.com
  • (line 10) don’t apply the rule for “no leech” image that will be served to bandwidth leecher/stealer. Don’t forget this line, or you’ll get forever loop that eventually stress your webserver.
  • (line 11) Serve the leecher with our error/no leech image. I suggest you to use more informative image, such as image that contain messages “visit my site to view the image”
example no_leech image

just an example that might annoy bandwidth stealer

Special case for Wordpress

Yes, I know that there are few “anti-leech/anti-hot-linkplugins out there, but make sure they have the correct htaccess code placement. Make sure the placement is before main wordpress htaccess default code. So, your wordpress blog htaccess code would be like this:

# BEGIN Hotlink Protection

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} ^facebookexternalhit.*$ [OR]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?ahowto.net [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mp32u.net [NC]
RewriteCond %{HTTP_REFERER} !^.*google.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^.*bing.com/.*$ [NC]
RewriteCond %{REQUEST_URI}  !^/images/no_leech.jpg
RewriteRule \.(jpe?g|png|gif)$ http://www.ahowto.net/images/no_leech.jpg [L]

# END Hotlink Protection

# BEGIN WordPress

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

# END WordPress


[debian] apt command to search which packages that provide certain file/library

Suppose you want to compile an application that need some library file such as libcurl.so but you don’t know the exact packages name. Sure, you can guess by using apt-cache search but the result might not be pleasant. (apt-cache search result when combined with file name will –usally– return empty result).
Here, I’ll show you other alternative to apt-cache search to search packages name who provide certain files/libraries.

  • Install apt-file package:


apt-get install apt-file
  • before using apt-file, you should update the database first (you need internet connection to do this):
apt-file update
  • wait until all package databases from repository downloaded. Now you can use it:
apt-file --package-only search libcurl.so

that command will search which packages from repository that provide libcurl.so file. Use –package-only to only package name, without this option, the result will also include file name and directory name inside packages (which –in my opinion– quite distracting). Oh, almost forgot, apt-file can be used by non-root users.
man apt-file for more complete usage!

[debian] apt-get install specific version of package

When you’re adding additional repositories beside the default in your /etc/apt/sources.list, Debian will provide more than one version of package where available. You can use “apt-cache policy package-name” to check the package’s available version. For example, you want to check available ffmpeg version on your repositories, you can use this command:

apt-cache policy ffmpeg

If you add additional repositories other than default, you may have several version of ffmpeg. This one is the output example on my server (I add debian-multimedia and backports repository beside the default):

root@nw:~# apt-cache policy ffmpeg
  Installed: 4:0.7.2-1~bpo60+1
  Candidate: 5:0.7.11-0.1
  Version table:
     5:0.7.11-0.1 0
        500 http://ftp.uni-kl.de/debian-multimedia/ stable/main i386 Packages
 *** 4:0.7.2-1~bpo60+1 0
        100 http://backports.debian.org/debian-backports/ squeeze-backports/main i386 Packages
        100 /var/lib/dpkg/status
     4:0.5.6-3 0
        500 http://ftp.us.debian.org/debian/ squeeze/main i386 Packages
        500 http://security.debian.org/ squeeze/updates/main i386 Packages

Those lines above show you which ffmpeg version is already installed and which one is available on other repository.
Suppose you want to install ffmpeg version 5:0.7.11-0.1 from debian-multimedia repository, you can use this command:

apt-get install ffmpeg=5:0.7.11-0.1

Notice that I put “=” and the version number [omitting the last number (0)] after the package name. That apt-get command will install ffmpeg from debian-multimedia and removing the one from backports that already installed.
When a package have some configuration file (such as Apache with it’s apache2.conf), apt-get will ask you whether to keep your current configuration or use the new version (overwrite the old one).