Tuesday, April 16, 2013

How to Compile the Latest FFmpeg with x264 and libvpx on CentOS 6

Compiling FFmpeg with high-performance H.264 (libx264) and VP8/VP9 (libvpx) encoding support on CentOS 6 often encounters dependency version collisions and compilation errors if older library packages remain installed on the host.

Environment: CentOS 6.x • FFmpeg • x264 • libvpx • faac

1. Removing Conflicting RPM Packages

Before compiling from source, remove older distribution codec libraries to prevent undefined reference linker errors like libx264.c: undefined reference to 'x264_encoder_open_130':

yum remove libvpx libogg libvorbis libtheora libx264 x264 x264-devel x264-libs ffmpeg -y

2. Patching and Compiling faac 1.28

If building the faac AAC encoder, a syntax error occurs in mpeg4ip.h: error: new declaration 'char* strcasestr(const char*, const char*)'. Remove line 126 from ./common/mp4v2/mpeg4ip.h before building:

sed -i '/strcasestr/d' common/mp4v2/mpeg4ip.h
./configure && make && make install

3. Compiling x264 and libvpx

# Build x264
cd x264
./configure --enable-static --enable-shared
make && make install

# Build libvpx
git clone https://chromium.googlesource.com/webm/libvpx
cd libvpx
./configure
make && make install
ldconfig

Once libraries are installed into /usr/local, configure FFmpeg with --enable-gpl --enable-libx264 --enable-libvpx for a fully modern encoding stack.

Wednesday, March 6, 2013

How to Compile and Install Wine 1.5 from Source on Debian Squeeze

Debian 6 (Squeeze) repositories originally froze Wine at version 1.0.1, an outdated release lacking DirectX enhancements and modern Windows API compatibility. Because official WineHQ .deb binaries were not available for Squeeze, compiling Wine 1.5 directly from source is the cleanest path to modernization.

Platform: Debian 6.0 (Squeeze) • Wine 1.5.25 Source Build

1. Install Build Dependencies

Use apt-get build-dep to fetch all required development headers:

apt-get update
apt-get build-dep wine -y

2. Download and Compile Wine

Fetch the source tarball and compile cleanly:

cd /usr/src
wget http://downloads.sourceforge.net/project/wine/Source/wine-1.5.25.tar.bz2
tar -jxf wine-1.5.25.tar.bz2
cd wine-1.5.25

./configure
make
make install

Verify installation:

wine --version

Monday, December 24, 2012

Linux Server Performance Tuning: Reducing Disk I/O and System Load

When optimizing a high-traffic dedicated Linux server, disk I/O bottlenecks are often the primary cause of sluggish response times and elevated load averages. Here are several practical server-tuning techniques I applied to a heavily loaded production server, resulting in a dramatic reduction in disk I/O and much faster throughput.

Key Optimizations: RAM-backed /tmp mount • Dedicated SSD for MySQL data • FastCGI process management with Nginx + PHP-FPM

1. Mount /tmp as a Ramdisk (tmpfs)

Many web stacks heavily utilize /tmp for transient disk writes:

  • PHP Sessions: Default PHP configurations store active session files in /tmp (session.save_path).
  • MySQL Temporary Tables: Heavy queries with extensive JOIN or GROUP BY clauses frequently write temporary on-disk tables to /tmp (verify your path using mysqladmin variables | grep tmpdir).

Mounting /tmp directly into RAM eliminates spinning disk access for these operations. Add the following entry to your /etc/fstab:

none /tmp tmpfs nr_inodes=200k,mode=01777,nosuid,nodev 0 0

Remount or apply without rebooting:

mount -o remount /tmp

2. Isolate MySQL Datadir to High-Performance Storage (SSD)

Moving the MySQL database directory (/var/lib/mysql) to dedicated high-speed SSD storage removes the database write bottleneck and dramatically lowers IO wait times (%iowait) during peak traffic.

3. Adopt Nginx with PHP-FPM

Switching from Apache's traditional prefork MPM / mod_php handler to Nginx + PHP-FPM significantly cuts memory footprint per connection, handles concurrency gracefully, and frees up system resources for database caching.

Sunday, December 23, 2012

Hardening Web Servers: Nginx Symlink Protection and PHP-FPM Chroot Jails

Securing shared hosting environments and multi-tenant web servers requires preventing unauthorized symlink traversals and isolating application processes. Here are two powerful security features in Nginx and PHP-FPM that significantly harden your stack against cross-account directory traversal attacks.

Security Highlights: Prevent unauthorized symlink following in Nginx • Isolate execution pools in dedicated chroot jails with required pseudo-devices

1. Restricting Symlink Traversal in Nginx

By default, Nginx follows symbolic links without verifying ownership. The disable_symlinks directive allows you to strictly control link traversal:

# Allowed options: off | on | if_not_owner
disable_symlinks if_not_owner;

When set to if_not_owner, Nginx verifies that the symlink and the target file/directory belong to the same owner, effectively blocking unauthorized access to system files or other users' web roots.

2. PHP-FPM Chroot Jails

To provide true isolation, you can lock each PHP-FPM worker pool into its own chroot directory. A quick way to bootstrap a clean environment is by extracting a minimal OS template (such as an OpenVZ minimal template matching your host distribution) into the jail root.

Creating Essential Device Nodes in the Jail

For PHP and system libraries to function correctly (especially DNS resolution, random entropy, and error logging), create the necessary character devices inside the jail directory:

cd /path/to/jail
mkdir -p dev etc usr/share/zoneinfo

mknod -m 666 dev/null c 1 3
mknod -m 666 dev/zero c 1 5
mknod -m 666 dev/random c 1 8
mknod -m 666 dev/urandom c 1 9

Also copy /etc/resolv.conf and /etc/hosts into the jail's etc/ folder so PHP can perform external network queries and DNS resolution.

Friday, December 14, 2012

How to Install Wine with MS Visual C++ and Visual Basic Runtimes on Linux

Running specialized Windows desktop utilities (such as download managers like Orbit Downloader, HiDownload, or Net Transport) on Linux often requires essential Microsoft Visual C++ and Visual Basic runtime libraries that are not packaged by default in vanilla Wine.

Prerequisites: Wine installed via EPEL (CentOS / RHEL) or standard distribution repositories (Ubuntu / Debian).

Step-by-Step Installation

1. Install Cabextract

The cabextract utility is required by Winetricks to unpack Microsoft cabinet files:

# On Debian / Ubuntu:
sudo apt-get install cabextract -y

# On CentOS / RHEL (requires EPEL):
sudo yum install cabextract -y

2. Download and Run Winetricks

Fetch the official winetricks script and install the required core fonts, Visual C++ 6.0, and Visual Basic 6.0 runtimes:

wget https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks
chmod +x winetricks

sh winetricks corefonts vcrun6 vb6run

Once the runtime components are installed into your ~/.wine prefix, your Windows applications will initialize without missing DLL or runtime errors.

Thursday, September 6, 2012

How to Compile and Configure XCache 2.x on CentOS 6 for PHP Optimization

While Memcached is widely recommended for web caching, opcode caches like XCache often deliver significantly better speed improvements and lower load averages for PHP-driven CMS platforms like Joomla on high-traffic servers.

Environment: CentOS 6.x • PHP 5.x • XCache 2.0.1

1. Compile XCache from Source

Install the PHP development headers and compile the XCache module with the optimizer enabled:

yum install php-devel -y
cd /usr/src
wget http://xcache.lighttpd.net/pub/Releases/2.0.1/xcache-2.0.1.tar.gz
tar -zxf xcache-2.0.1.tar.gz
cd xcache-2.0.1
phpize --clean && phpize
./configure --enable-xcache --enable-xcache-optimizer
chown -R nobody /usr/src/xcache-2.0.1
sudo -u nobody make
make install

2. Configure /etc/php.d/xcache.ini

Create the XCache configuration file. Adjust the zend_extension path depending on whether your architecture is 64-bit (/usr/lib64/php/modules/xcache.so) or 32-bit (/usr/lib/php/modules/xcache.so):

cat << 'EOF' > /etc/php.d/xcache.ini
[xcache-common]
zend_extension=/usr/lib64/php/modules/xcache.so

[xcache.admin]
xcache.admin.enable_auth = Off

[xcache]
xcache.shm_scheme        = "mmap"
xcache.size              = 64M
xcache.count             = 1
xcache.slots             = 8K
xcache.ttl               = 0
xcache.gc_interval       = 0
xcache.var_size          = 32M
xcache.var_count         = 1
xcache.var_slots         = 8K
xcache.var_ttl           = 0
xcache.var_maxttl        = 0
xcache.var_gc_interval   = 300
xcache.readonly_protection = Off
xcache.mmap_path         = "/dev/zero"
xcache.coredump_directory = ""
xcache.experimental      = Off
xcache.cacher            = On
xcache.stat              = On
xcache.optimizer         = On

[xcache.coverager]
xcache.coverager         = Off
xcache.coveragedump_directory = ""
EOF

3. Enable the Web Administration Panel

Copy the administrative GUI into your web root to monitor memory usage and cache hit rates:

cp -R admin /var/www/html/xcache-admin
service httpd restart

You can access the admin dashboard at http://your-server-ip/xcache-admin/index.php to monitor real-time hit ratios.

Tuesday, September 4, 2012

How to Losslessly Optimize JPG, PNG, and GIF Images on Linux Using littleutils

Reducing image file sizes without sacrificing visual quality is one of the highest-impact optimizations for production websites. The littleutils package provides a collection of fast, lightweight command-line utilities—including opt-png, opt-jpg, and opt-gif—that losslessly compress images for faster web delivery.

Supported Utilities: opt-png (via pngcrush) • opt-jpg • opt-gif (via gifsicle)

1. Installing Required Prerequisites (CentOS / RHEL)

Install the necessary build tools and image compression libraries:

yum groupinstall "Development Tools" -y
yum install libpng-devel libjpeg-turbo-devel gifsicle -y

Compiling pngcrush:

cd /usr/src
wget https://sourceforge.net/projects/pmt/files/pngcrush/1.8.10/pngcrush-1.8.10.tar.gz
tar -zxf pngcrush-1.8.10.tar.gz
cd pngcrush-1.8.10
make
cp pngcrush /usr/local/bin/

2. Compiling littleutils

Download and build the littleutils suite:

cd /usr/src
wget http://downloads.sourceforge.net/project/littleutils/littleutils-source/1.0.27/littleutils-1.0.27.tar.bz2
tar -jxf littleutils-1.0.27.tar.bz2
cd littleutils-1.0.27
./configure --prefix=/usr/local
make
make install
make install-extra

3. Usage Examples

Optimize individual files or batch-compress entire image directories in place:

# Optimize a single PNG image losslessly
opt-png image.png

# Optimize a single JPEG image
opt-jpg photo.jpg

# Optimize all images in a directory
find /var/www/html/images/ -type f -name "*.png" -exec opt-png {} +
find /var/www/html/images/ -type f -name "*.jpg" -exec opt-jpg {} +

How Google Antigravity Solved the Mysterious NVIDIA Sleep Reboot on My Dell Inspiron 7567 (Ubuntu Linux)

If you run modern Ubuntu or Linux on a Dell Inspiron 15 Gaming (7567) or a similar 7th-gen Intel laptop paired with an NVIDIA GeForce GTX ...