Tag Archive for 'Linux' Page 2 of 2



Speed up PHP with XCache on Gentoo Linux

XCache is a PHP opcode cacher created by the same developer who brought us Lighttpd. An opcode cacher significantly increases PHP’s performance by caching the compiled state of PHP code to avoid time-consuming recompilation each time a script is executed. There are a handful of great opcode cachers on the market currently, incuding APC and eAccelerator (here’s a more comprehensive list). APC is written by some of the developers of PHP and will be bundled with PHP6. eAccelerator has a long history and might be the most popular and widely supported opcode cacher. I chose XCache due to its reputation for superior performance (source) and its ability to take advantage of multi-core processors.

Setting up XCache on Gentoo Linux is dead simple.

Install XCache

emerge -va dev-php5/xcache

Configure XCache

nano /etc/php/cgi-php5/ext-active/xcache.ini

Edit anything you see fit. See this page for details.
Since Slicehost is running on twin dual-core processors, I changed “xcache.count” to 5 (n+1 where n is the number of processors) to take advantage of the Splitted Cache feature.

Restart PHP
I have PHP running as a FastCGI daemon, so I restart with

/etc/init.d/fcgi.php restart

Check phpinfo() to verify that XCache is loaded. You should see the following in the “Powered by Zend” box:

with XCache v1.2.1, Copyright (c) 2005-2007, by mOo

If you liked this post, please subscribe to my feed. Thanks for visiting!

Convert your Linux filesystem safely and easily (even on a VPS)

I was shocked to discover that converting one’s filesystem is simple as pie and totally safe. The process goes like this:

  1. Remove cruft from your system (optional)
  2. Reboot into a LiveCD environment (optional if the partition you want to convert can be mounted read-only without rebooting)
  3. Mount the partition you want to convert in read-only mode
  4. Copy the contents of the partition somewhere temporarily (ex. another partition, external drive, DVD, etc.)
  5. Unmount the copied partition
  6. Format the partition with your desired filesystem
  7. Mount the formatted partition and copy all the files back
  8. Edit /etc/fstab to reflect the new filesystem
  9. Reboot and profit

Thanks to Slicehost’s wonderful Rescue Mode with a 2GB Rescue Slice, I was able to use this method to convert my Gentoo VPS from ext3 to XFS. Here’s a step-by-step account. These steps were performed on a 256MB VPS at Slicehost. YMMV.
Continue reading ‘Convert your Linux filesystem safely and easily (even on a VPS)’

Slicehost’s Rescue Mode rocks; Gentoo’s Xen guest /proc /sys mounting bug

This is a tutorial / fan post for Slicehost’s Rescue Mode. Rescue Mode saved me from my own stupid mistakes and also a known Gentoo bug.

While fiddling around in my /etc/fstab file (added “data=writeback” to the mount options), I rendered my Gentoo VPS unbootable. Oh well, I just need to boot a LiveCD and fix my stupid fstab. Wait, this isn’t a physical Gentoo box in front of me, but a virtual server hosted miles away from me…

Ta da, Slicehost’s Rescue Mode to the, uhh, rescue. I log into SliceManager, go to the Rescue panel of my slice, and click “Enter Rescue Mode”. SliceManager gives me a temporary root password, and finishes building the Rescue Slice in a few minutes. Instant LiveCD-like rescue environment!

To fix my fstab, I SSH into my Rescue Slice with the temporary root password. The partition holding my regular slice is available as /dev/sda1 (and my swap partition is /dev/sda2 if I need that for some reason). I mount my regular slice,

mkdir /mnt/slice
mount /dev/sda1 /mnt/slice

fix my fstab file,

nano /mnt/slice/etc/fstab

and finally return to SliceManager and click “Exit Rescue Mode”. Problem solved. Slicehost’s Rescue Mode rocks!

Unfortunately, my VPS failed to boot again but with a different error. It died upon trying to mount /proc.

The "mount" command failed with error: proc already mounted

It turns out this is a known Gentoo bug when working with Xen. Apparently Gentoo Xen guests should not try to mount /proc and /sys. I don’t understand what triggered this problem or why I did not encounter it before.

So back I go into Rescue Mode to fix this by commenting out the section of /sbin/rc that attempts to mount /proc and /sys (if you only skip /proc mounting, the next bootup will die trying to mount /sys).

mkdir /mnt/slice
mount /dev/sda1 /mnt/slice
nano /mnt/slice/sbin/rc

Around line 217, comment out these chunks of code like so: (source)

#       check_statedir /proc
#
#       ebegin "Mounting proc at /proc"
#       if [[ ${RC_USE_FSTAB} = "yes" ]] ; then
#               mntcmd=$(get_mount_fstab /proc)
#       else
#               unset mntcmd
#       fi
#       try mount -n ${mntcmd:--t proc proc /proc -o noexec,nosuid,nodev}
#       eend $?

and a few lines later:

#       if [ "$(get_KV)" -ge "$(KV_to_int '2.6.0')" ] ; then
#               if [[ -d /sys ]] ; then
#                       ebegin "Mounting sysfs at /sys"
#                       if [[ ${RC_USE_FSTAB} = "yes" ]] ; then
#                               mntcmd=$(get_mount_fstab /sys)
#                       else
#                               unset mntcmd
#                       fi
#                       try mount -n ${mntcmd:--t sysfs sysfs /sys -o noexec,nosuid,nodev}
#                       eend $?
#               else
#                       ewarn "No /sys to mount sysfs needed in 2.6 and later kernels!"
#               fi
#       fi

That’s it. Happy rescuing. :)

Nginx with PHP as FastCGI on Gentoo Linux

Nginx (pronounced “Engine X”) is a high performance web server (and proxy server, but we will be using it as a web server here). In small VPS environments where memory is precious, Apache is at best overkill and uses memory that could be spent elsewhere (like MySQL query caching), at worst a terrible bottleneck that will consistently bring down your site under very moderate loads. If you are willing to live without .htaccess files and Apache-style mod_rewrite rules, Nginx is a great replacement that will lower memory usage and increase performance.

This is a draft. Comments, suggestions, corrections, improvements are very much welcome!

Continue reading ‘Nginx with PHP as FastCGI on Gentoo Linux’

Preparing Gentoo Linux for a minimalist web server

This is a first stab at a guide to preparing a minimalist web server running on Gentoo Linux, ideal for a small VPS. Don’t follow these instructions unless you know what you’re doing, ’cause I’m not sure I do. :P (Apologies for the lack of updates; I’ve been busy playing with this Gentoo web server amongst other things.)

This is a draft. Comments, suggestions, corrections, improvements are very much welcome!

Continue reading ‘Preparing Gentoo Linux for a minimalist web server’

Surfing anonymously with Tor and FoxyProxy is dead simple

Ever want to surf the web anonymously? Forget unreliable and sometimes illegal open proxies that are usually compromised or misconfigured servers. Forget web proxies that spam you with ad frames and pop-ups. Try Tor, an open-source anonymous peer-to-peer network. Using Tor and Firefox is extremely easy. More about Tor in this Wikipedia entry.

I tried the following steps in Arch Linux, but they should apply to any modern operating system. (By the way, Arch Linux is my favorite Linux distribution. I’ll likely write about it at some point.)

  • Install Tor using whatever appropriate package manager or installer. In Arch, I simply did “pacman -S tor“.
  • Windows users can get the installer.

  • Start Tor. In Arch, I did “/etc/rc.d/tor start“.
  • Install FoxyProxy for Firefox.
  • On first run, FoxyProxy will ask you some questions about Tor. Say you want to configure for Tor. Say you are running Tor without Privoxy (unless you know otherwise). Accept the default port for Tor. Voila.
  • Configure FoxProxy to use Tor for specific websites, or chose the “mode” where Tor is used for all websites. Make sure Tor is running.
  • Surf like a ninja. :)

To verify if your browser connections are anonymized by Tor, visit TorCheck. You can also visit any of the many sites which show you your IP address. If Tor is working, the IP address shown should be different from yours.

Windows users who need an even simpler method of using Tor should check out the XeroBank (xB) Browser. Read more about it at Wikipedia.

Be warned, don’t use Tor to do anything illegal. Tor has known weaknesses and does not guarantee your anonymity if someone wants to catch you badly enough.

If you’re interested in helping the Tor network grow, consider running a Tor relay.