Installing Mod_Python

Posted by Nessa | Tags: ,, | Posted on November 11, 2007


Update: These instructions may be outdated for most people. I’ve posted newer instructions on my collaborated sister site:

I figured I’d put this out here because it’s come up quite recently with people who are using Apache 1.3.x. If you haven’t gotten the balls to upgrade to Apache 2.x yet, you can still install mod_python…just not as easily. This simple walk through is for Apache 1.x and 2.x.

First, you need to determine what version of Python you are running. To check, type ‘python -V‘ at the command line. If you are running Apache 1.3.x, you should use mod_python version 2.7.11. For Apache 2.2.x, use 3.3.1.

1. Download the Python sources for the version of Python that you have installed, the run a configure and make (no install) just to compile them. If you are running Apache 1.3, you should add –without-threads to your configure line.

2. Once you have this, follow these steps to compile mod_python:

cd /usr/src
tar -xvzf mod_python-2.7.11.tgz
cd mod_python-2.7.11

./configure –with-apxs=/usr/local/apache/bin/apxs –with-python=/usr/src/Python2.5.5

The –with-python path should reflect the location of the sources you downloaded and compiled earlier.

3. If you are on Apache 1.3, you now need to perform the steps below. If not, skip to step 4:

pico src/Makefile

Locate the ‘CFLAGS’ line, and add the -DEAPI switch so it looks like this:


Then add -lutil to the LIBS line like so:

LIBS=-lm /usr/src/Python-2.5.1/libpython2.5.a -lutil

4. Run the make and make install.

5. Now edit httpd.conf and create your handlers. This will tell Apache which file extensions to interpret through mod_python. If you have mod_rewrite installed and enabled, users can override this in their .htaccess files:

LoadModule python_module libexec/
AddModule mod_python.c
AddHandler mod_python .psp .py

How to Make Your System Admin Mad by Creating Huge-Ass Files

Posted by Nessa | Tags: ,, | Posted on October 31, 2007


So If you’ve ever woke up in the morning and asked yourself…”Hmm, how can I make my system admin’s job harder to the point where they get mad and shut down my server?” Well, lucky for you I can answer that question. All you have to do is use the ‘dd‘ command to write a 120gb file to an 80gb hard drive. That’s a winner.

By ‘dd’ I’m not talking about my bra size, people. It’s sad, but we recently had an over-curious customer try to see what would happen if the hard drive filled up on his dedicated server. You know what happens when you flush a clogged toilet? Yea….

So here’s the command:

dd if=/dev/zero of=test bs=1024 count=125829120

This command will write a 120gb file directly to the disk. ‘of’ specifies the name of the output file, while ‘bs’ represents the size of a block and ‘count’ is how many blocks to create. Really, it’s a dangerous thing to do if you don’t know what you’re doing. Generally the only time I do this is when I’m testing large file support for servers and PHP.  Nevertheless, the sheer curiosity of ignorant users is enough for me to pull the power plug on a server.

Which Programming Language is For You?

Posted by Nessa | Tags: ,,,, | Posted on October 30, 2007


Working with a webhosting company I get asked all the time — which programming language is better? It’s obvious that I’m more bias towards PHP, but there are other great languages out there that may be more suitable for certain people creating certain sites. I’ve decided to write a nutshell comparison on the most common languages, so you can decide for yourself.


My preferred language, PHP, is the most popular and widely-used dynamic programming language on the Internet. As a result, it’s increasingly become easy to learn (I have 4 brain cells and even I could do it) and can be run on virtually any operating system. It’s popularity has resulted in the availability of thundreds of contributions, modules, and addons for PHP to increase its functionality and integration with other software. It’s also free to download and easy to install (for most people), and is the most common in CMS’s and prebundled website software.

The major downside to PHP is that it’s so popular that security holes are being found all the time. Its very nature requires some configuration changes and restrictions in order to boost security.


Perl is one of the oldest and most successful languages to date. With thousands of modules that can be added, it can pretty much do anything. While it’s currently not as popular as PHP, it’s more efficient for server management in its double use as a shell scripting language. It’s also open-source and compatible for most all OS’s. The only real downside is that it’s not as quick and easy to learn, and even the simplest tasks can take more programming and lines of code to accomplish. Also, the camel logo is fugly.


I’ll try to be nice about this one. Really, I’m not an ASP fan mainly because it’s proprietary to Windows and IIS. That being said, I’m sure you can figure how secure and reliable it is. It’s not as actively maintained by its developers (Microsoft) so major bugs have been known to linger for months — unacceptable for busy webmasters trying to manage professional websites. While ASP, .net, and VBScript (aka the ASP family) are all “free”, if you want any of the fancy addons or modules for them you’ll be owing Microsoft a nice little licensing fee. On a positive note, Chilisoft has made is possible to port ASP over to Linux, so it’s no longer 100% platform dependent.


Java Server Pages (developed by Sun) is more similar to the ASP framework, but targeted towards Java fanatics. Out of all the programming languages I’ve studied in school, JSP is probably my least favorite. Not only is it hard to learn, but there’s no such thing as simplicity with it. However, it’s very powerful software and is platform-independent, as long as you have a Java Environment for it to run in. Tomcat (an Apache Project) is the most common servlet container for JSP. But, Java takes up a lot of memory and JSP servers are very difficult to maintain and administer for non-experts.


Ruby is one of the newer programming language to hit the web developer market, and it’s actually quite close in concept to PHP except that it’s 100% object-oriented, and very clean because you don’t need as much punctuation. It’s also very beginner-friendly, and is growing in popularity. The main disadvantage to Ruby is that it’s difficult to troubleshoot runtime errors because its reluctance to declare variables before their use. And being that it’s a newer language, there are definitely less resources available and not as many applications currently employing Ruby as a framework. However, it is cross-platform compatible, easy to install, and even easier to learn.


I really don’t know a whole lot about Python other than that expert programmers claim that it’s such a strong language. I personally think it’s crap…my one shot at Python and I find out that it’s very whitespace/tab sensitive, so one extra space can ruin your program. Coming from PHP I don’t find that very appealing…I personally think it’s a mistake, and that its developers just call it a ‘programming guideline’ since they can’t figure out how to fix it. Really, there’s no huge benefit in using Python other than for your Google sitemaps, so all I’m going to say is steer clear.


I put this at the bottom of the list because I don’t really consider it a programming language, but it is the more predominate and widely used language that all the others revolve around. I do think it’s important that every programmer become an expert in HTML before going dynamic with their coding. While other languages rely on HTML for output, it’s very common for sites to be purely HTML and nothing else. However, HTML is a static language with no dynamic capabilities in itself whatsoever, so it’s somewhat boring on its own


In a category all its own, there are several client-side languages that augment the others. Client side languages no require any server-side software to be installed, just a browser capable of interpreting them. CSS (Cascading Style Sheets) is a language primarily used in formatting and creating a uniform and repetitive style for use across multiple pages. JavaScript is a mini-java language used to create mild effects for a website, like popup windows and form validation. I also consider it to be very insecure, so it should be used sparingly. AJAX is a newer JavaScript framework that is more appealing to the eye and lets you create those special effects that you see on many web 2.0 sites…things like refresh-less page loading.

Mass-Moving cPanel Accounts

Posted by Nessa | Tags: , | Posted on October 22, 2007


If you’ve ever needed to move a ton of cPanel accounts from one server to another, you probably know the following:

  1. The multiple account move feature in WHM fails miserably
  2. It takes forever to do them one by one, esp. when you have other things to do

I figure the best way to mass-move accounts is by listing all the accounts in a file, then using a simple bash script to repetitively package all the accounts to they can be moved to another server.

First, you need to create a file (like users.txt) to list all the users you wish to move. If you’re only doing a few you can just go ahead and list the users in there manually, but if you’re doing like a whole server, you can get all the users in one file like so:

ls /var/cpanel/users > users.txt

You’ll then need to manually edit the users file and remove the ‘.’ and ”..’ entries, and any others that should not be included. The users.txt file should also be in a format like this:


Next, you may want to set up an SSH key between servers so all the cpmove files and be transferred automatically. If you don’t know how to do this, here is a simple and straight-through tutorial.

Create a bash script called ‘’ with the following lines:

#! /bin/bash
for i in `cat users.txt`; do /scripts/pkgacct $i; done
scp -r /home/cpmove* root@server:/home
echo "Account backups done" > email.txt
mail -vv -s "Account backups done" < email.txt

This will run cPanel backups up all the accounts listed in users.txt, scp them over to the new server, then email you when it’s done. Note that if you do not have SSH keys installed, you will have to manually type in the new server’s password when the script is ready to transfer the accounts over.

The on the new server you can use the same script and users.txt file, just change it around:

#! /bin/bash
for i in `cat users.txt`; do /scripts/restorepkg $i; done

This will restore all the user accounts that you copied over. From there, you’re all done!
One simple note: I’m not a shell programmer so I’m sure there are a lot better ways to accomplish this..if so, you can post them in a comment. The downside of using this method to move accounts is that all of the accounts are backed up in order so if you have a hundred some users, the backup files might be sitting on the server for hours until they are moved and restored, so you’ll want to make sure that your users are not making changes to their sites during the move process. Also, since the backup files are stored on the server it’s a good idea to figure out how much disk space you are going to need to avoid going over. You may be able to modify the script to do groups of 10-20 then delete the cpmove files if disk space is a concern.

PCLinux OS is Kind of Sexy

Posted by Nessa | Tags: , | Posted on October 18, 2007


I recently became pretty fond of Ubuntu when I installed it on my work computer after dealing with daily crashes of Windows XP Pro. I find it to be a lot easier to manage, though it sucks that some software is still not compatible with Unix and installing a wireless network card is about as hard as finding a 34D push-up bra at Victoria’s Secret. I mean, it’s a lingerie store…you’d think they’d have a bigger push-up bra. Maybe I want my boobs to peek out of my shirt every once in a while…or maybe I’ll decide to turn tricks someday and need a good “come get me” outfit. I also just realized that this is the third time today I went off on a tangent about boobs.

So anyways, out comes PCLinuxOS which is a new OS determined to be the bridge between Linux and Windows, targeted towards beginner Unix-ers who aren’t quite ready to kick Microsoft to the curb. It’s not quite the Gnome desktop, but rather a Windows Vista-inspired interface powered by a Linux core. I think it’s a good idea and will probably help the world see that Windows is officially the dead rat in the soup, by converting end users over to Linux. Best off, it’s completely free and can be downloaded here.
I don’t have any plans in the near future to use PCLinuxOS since I’ve become very content with Ubuntu, but If you’re a beginner to Unix you might want to give this one a look and let me know how it works.

Using PHP to Display Version Info – Part II

Posted by Nessa | Tags: ,,, | Posted on October 17, 2007


Earlier I showed some examples of commands you can use to pull software versions into a simple PHP script. In the next example I’ll show how to do the distro and kernel versions. I’m sure that there’s a much simpler way to do this (i.e. a simple cat command on the /proc/version file), but I figured I’d use a more advanced example in the form of a function. I did the distro as a variable to show how easy this is:

function kernelinfo () {
$buf = exec( 'cat /proc/version');
if ( $buf == "ERROR" ) {
$result = "N.A.";
} else {
if (preg_match('/version (.*?) /', $buf, $ar_buf)) {
$result = $ar_buf[1];

if (preg_match('/SMP/', $buf)) {
$result .= ' (SMP)';
return $result;

$distro = exec('cat /etc/redhat-release');

$kernel = kernelinfo();

echo $distro;

echo "<html><br></html>";

echo $kernel;


This will show a result of the following, obviously various depending on your platform:

CentOS release 4.5 (Final)
2.6.9-023stab033.9-enterprise (SMP)

Keep in mind that this script (as the last) requires the ability to pass shell commands through PHP. So, you would need to be able to the exec function, or replace it with system, passthru, escapeshellcmd, or shell_exec if those are allowed in your php.ini configuration. Also, if you run PHP as an Apache module, this will not work if you have open_basedir protection enabled.

Using PHP to Display Version Info

Posted by Nessa | Tags: ,,,,,, | Posted on October 15, 2007


I’ve been working on this application for work that does some simple server reporting, part of which involves displaying the versions of major software running on the machines. The importance of this to me personally is that since we have over 30 shared servers hosting multiple customers, we are continually moving websites between servers. Some of our older generation servers are still running MySQL 4.0 and PHP 4.3, so I need to be aware of this to make sure that customers are being moved to servers with compatible versions. It’s also good in tracking and planning upgrades.

I find it best to use the exec() function since it’s not blocked by most hosts. However, if you are on a shared host it’s very likely that certain PHP functions are disallowed in the php.ini. In that case you may be able to subsitute exec with system, passthru, escapeshellcmd, or shell_exec…unless those are blocked too. Then I guess you’re out of luck.

Start by creating some variables to store ordinary shell commands. If you wanted to find the php version from command line, you would usually type:

php -v

This will give a huge chunk of crap that you really don’t need if you’re making a simple version display script. In this case, you can use grep, awk, sed, and cut to trim down the output into a one-liner:

php -v |grep built |awk {‘print $2′}

The awk command prints out columns, so in the above example I’m printing out the second column of the line that contains the word ‘built’. Once the desired output is figured out, you simply assign it to a variable passed through exec() or a similar function:

$phpver = exec("php -v |grep built |awk {'print $2'}");

Then you can call the variable $phpver anywhere in your script:

echo "PHP Version: $phpver";

You can probably go through and figure out the commands to show other software versions on your server. In my script I’m showing the perl, php, mysql, apache, python, cpanel, and ruby versions. Here are the commands I used:


$perlver = exec("perl -v |grep linux |awk {'print $4'}|sed -e 's/v//'");
$phpver = exec("php -v |grep built |awk {'print $2'}");
$mysqlver = exec("mysql -V |awk {'print $5'} | sed -e 's/,//'");
$apachever = exec("apachectl -v |grep version |awk {'print $3 $4'}|sed -e 's/Apache\///'");
$pythonver = exec("python -V 2>&1 | sed -e 's/Python //'");
$cpanelver = exec("cat /usr/local/cpanel/version");
$rubyver = exec("ruby -v |awk {'print $2'}"); ?>

Then I just echoed out all the variables to display my version numbers:

See here .


Posted by Nessa | Tags: , | Posted on August 28, 2007


I kinda wish I paid attention in class when the professor was talking about CIDR notations and shit…because it would have come in handy tonight. But being that I’m lazy I did some looking around and found that there’s a perl module out there that will convert an IP range to CIDR for you with a simple 4-line script. You’ll need to install the Net::CIDR module for this to work
If you’re on cPanel just type:

# /scripts/perlinstaller Net::CIDR

Here’s the script:


use Net::CIDR;

$range = shift;

print (join(“\n”, Net::CIDR::range2cidr(“$range”)) . “\n” );


root@vps [~]# perl

Size Matters with PHP

Posted by Nessa | Tags: ,,, | Posted on August 27, 2007


I figured this might be helpful to post since it seems to be a fairly common issue poking up about PHP’s limits in regard to file size. It’s no secret to fellow programmers that PHP is incapable of readily handling files over 2gb on the typical 32-bit system, but others are easily aggravated with a greeting of errors that look like this:

PHP Warning: ……. failed to open stream: File too large in ……..

Generally I’d say that if you’re trying to get PHP to man-handle huge files you’d need to have one badass server that can take that kind of abuse. Before you go about trying to compile PHP with large file support, you may want to consider passing the ‘split’ command through the system or passthru functions to break your massive files into smaller bits so PHP can handle them. If you’re the type that has to go about everything the hard way, then I guess that’s why you visited my site.
To compile PHP with large file support, you need to add a simple compiler flag preceding your configure statement. This should look as so:

# CFLAGS=”-D_FILE_OFFSET_BITS=64″ ./configure –with-modules-that-i-use

Then your make && make install and (if all goes without error) you should now be able to work with large files with PHP.

Too bad nothing’s really straight forward, eh? Apache itself has a filesize limit too (even up to 2.2.4) so don’t waste your time trying to get your newly-compiled PHP installation to work with Apache. When I was first trying to work this out I figured that it’s best to have two PHP installations, one for Apache and the other just for the CLI.

To do this, create yourself a phpinfo file and copy the configure line, removing the single quotes from around each flag. Two things you’ll want to change though:

  • Remove the ”–with-apxs2=/usr/local/apache/bin/apxs‘ (or similar) flag to keep the installer from compiling against Apache
  • Change your –prefix to a different location. I used ”–prefix=/usr/php-lfs’ .

When the installation is done, make it easier on yourself by creating some symlinks to the new binary:

ln -s /usr/php-lfs/bin/php /usr/bin/php5

ln -s /usr/php-lfs/bin/php /usr/local/bin/php5

This way you have your LFS-compiled PHP version in /usr/bin/php5 to use for your scripts. To call them, you’d use:

php5 /path/to/script or /usr/bin/php5 /path/to/script

What if you actually want to call the script from a browser? Well, you still can’t load a large file in the browser itself, but you can process it through a script to have a process run on the server:

<?php passthru('/usr/bin/php5 myscript.php'); ?>

And that should pretty much do it.

b2Evolution SMTP Patch

Posted by Nessa | Tags: , | Posted on August 8, 2007


Update (4/21/09) – This plugin is obsolete and is probably never going to be updated…use at your own risk!

I was debating whether or not to publish this since I wrote it mainly to target our customers, but I figured it might help someone who needs it.

Many hosting companies block PHP mail coming from the user ‘nobody’, which is a default if your host runs PHP as an Apache module. At the time of my writing, b2evolution does not support STMP, so I created a simple patch that will allow you to use phpMailer to send mail through SMTP instead of the send_mail() function that b2 uses.

Download b2evo_phpMailer-1.03.tar.gz (76k)


  • b2evolution 1.9.x or higher (tested with 1.9.3, but may work with other versions)
  • php 4.3.1 or higher (required by b2)
  • Valid SMTP server


The instructions are specifically outlined in the readme.txt file within the archive, but it’s basically as simple as:

  1. Edit the ‘settings.php’ file in htsrv/phpmailer
  2. Upload the patched files to their corresponding locations on your webserver

And yea…that’s it.


- This script was tested on a Linux platform running on cPanel, so the actual email setting and port numbers could be different on your server. If you are unsure about this, please ask your host.

- phpMailer does not explicity support SSL or TLS connections yet, so neither does this patch. You can essentially connect through any port as long as 1) your server runs SMTP on it and 2) it doesn’t require SSL or TLS.

I am not affiliated with b2evolution, so please do not contact me with questions about the software that do not pertain to the usage of this patch. This patch was mainly written to make b2evolution functional on some of our servers that block php mailing, and is not meant to be a major project. That being said, if you’re having difficulty getting my patch to work with your installation I would love to know about it, but please do not make your expectations too high. I have a life too =)