Browsing all articles in Plesk

Finding WordPress installs on a Linux Server

WordPress installs multiply like bunnies.  If you’ve got several WordPress domains hosted on a single server it’s easy to loose track of installed versions.  This one-line wonder will sniff out WordPress powered sites and grab their version number.  Drop it in a CRON that runs once a month and you’ll get regular reminders of what’s lurking out on your server.

WordPress installs contain the file version.php with the variable $wp_version. Find all the version.php files, grab the variable and you’re golden. Here’s the basic locate command:

locate /wp-includes/version.php | xargs grep '$wp_version ='

That’s nice enough, but we can get a bit better. The server I’m targeting stores all virtual hosts in the directory /var/www/vhosts. We can use the cut command to snip that from the display, sort the output by domain name and email the results.

locate /wp-includes/version.php | xargs grep '$wp_version =' | cut -d'/' -f5,6,7,8,10 | sort | mail -s "WordPress Installs on Server XYZ" your-email@yourdomain.com

You’ll get an email with results like this:

foobar.com/version.php:$wp_version = '3.0.1';
whatsit.com/version.php:$wp_version = '2.7.1';
whizzbang.com/version.php:$wp_version = '2.9.1';
widget.net/wp-includes/version.php:$wp_version = '2.9.1';

For extra credit you could sort by version number, but there’s no need to be an overachiever here. Quit while you’re ahead. The script uses locate, so make sure you run updatedb periodically.

Ubercart is a a popular shopping cart plug-in for the popular Drupal Content Management system. Parallel’s Plesk is a popular hosting control panel.

When configuring a Drupal-Ubercart install on a Plesk based host Ubercart requires the creation of a /keys directory that is outside of your document root (aka /httpdocs in Plesk ) To create a keys directory that does not generate open_basedir errors you’ll need to do the following

Log in as root and create or edit conf/vhost.conf and conf/vhost_ssl.conf as shown.

conf/vhost.conf:

<Directory /var/www/vhosts/YOUR-DOMAIN.COM/httpdocs/>
php_admin_value open_basedir "/var/www/vhosts/YOUR-DOMAIN.COM/httpdocs:/tmp:/var/www/vhosts/YOUR-DOMAIN.COM/keys"
</Directory>

conf/vhost_ssl.conf:

<Directory /var/www/vhosts/YOUR-DOMAIN.COM/httpdocs/>
php_admin_value open_basedir "/var/www/vhosts/YOUR-DOMAIN.COM/httpdocs:/tmp:/var/www/vhosts/YOUR-DOMAIN-HERE.COM/keys"
</Directory>

Note that Php_admin_value and all that follows should be on one line.

Then run (on CentOS – Ubuntu/Debian may be slightly different):

/usr/local/psa/admin/sbin/websrvmng -u --vhost-name=<domainname>

/etc/init.d/apache2 restart

After the restart Plesk will include the contents of your file in the apache config file. You can verify that it’s being included by checking httpd.include you should see a line similiar to:

Include /var/www/vhosts/mydomain.com/conf/vhost.conf

Feeling adventurous and want to add other apache directives in the .conf file ? Great, but HEED MY WARNING. If you mess up the syntax in either of the files apache may fail to restart — That would be why you needed to log in as root. Delete-Remove-Rename the .conf files, rerun websrvmng and start apache. No big deal if you’re on a development box, but, as always you would be wise to follow the 2-Beer rule when logging into production boxes as root.

Resources:

Ubercart Keys Documentation Page:
http://www.ubercart.org/docs/user/2731/credit_card_settings

Plesk forum and Knowledgebase posts:
http://forum.parallels.com/showthread.php?t=84211&highlight=vhost.conf+websrvmng
http://kb.parallels.com/en/5464
http://kb.parallels.com/en/432

You may want to check out Power Toys for Plesk from grafxsoftware.com http://www.grafxsoftware.com/product.php?id=172 which includes a vhost conf editing tool.

Of course you can avoid all this by having Aisle8, Inc. host your Drupal, Ubercart or OpenAtrium site. We can host it on a Plesk based server, or one of our trusty Aegir based boxes. Aegir eases the hosting and upgrading Drupal sites — Ain’t nothing else like it around.

I’ve learned the hard way that while directly altering Plesk’s database is almost never a good idea, the Plesk database ‘PSA’ holds a ton of useful information that’s not always readily exportable from the interface. Here are a couple of useful queries. The first simply exports a list of “standard hosted” domains. The second includes client information.

You’ll need to be logged in as root.

First, Get into MySQL and use the Plesk database, “psa”:

mysql -u admin -p`cat /etc/psa/.psa.shadow`;
use psa;

Query 1: List all the standard hosted domains, send the results to a csv file:

select name from domains where htype='vrt_hst' INTO OUTFILE '/tmp/domains.csv';

Query 2: Building on that, lets add client information and sort it to make it pretty:

select cname,name from domains, clients where cl_id = clients.id and htype='vrt_hst' order by cname,name INTO OUTFILE '/tmp/domains-client.csv';

Nothing earth shattering here, but it might save you 5 minutes.

Intro

Over the past few months I began to notice a steady erosion in available disk space on a server running the Parallels’ Plesk control panel. After some sleuthing I tracked it down to the management of mailboxes in combination with the “Mail Forward” and “Mail Group” functions on domains the “Mailbox quota” set to unlimited.

There are two basic issues:

  1. Users setup ‘redirects’ or ‘mail group’ functions and leave the account mailbox enabled, then never check the mailbox and delete the messages. (e.g. sales@somedomain.com forwards to bill@somedomain.com and jim@gmail.com, but nobody logs on to sales@ and deletes the message)
  2. Disabling the mailbox does not delete the existing files in the mailbox. All those mail files will just hang around forever, orphaned from the control panel.
Slogging around in the qmail directories looking for files is no fun. Here’s how I rid myself of these pesky disk-eaters. I took a two pronged approach:
  • Query the Plesk database to identify mail accounts with mailboxes that redirect.
  • Query the filesystem to find Mailbox directories that are large.

Query the Plesk Database

You’ll need shell access to your server. Login to your server, pop into mysql and use the Plesk database (PSA) using the following command:

mysql -u admin -p`cat /etc/psa/.psa.shadow`;
use psa;

Use the following query to select mailboxes that redirect:

select name,mail_name,redir_addr from mail, domains
where mail.dom_id = domains.id and postbox = 'true' and redirect = 'true';

Now you’ve got some ammunition. Exit out of mysql.

Finding Big Mailboxes

A ‘mailbox’ in qmail is simply a directory. Each undelivered message is a file in that directory. On my installation of Plesk qmail is installed in ‘/var/qmail/’ The mailbox for ‘jimbo@somedomain.com’ takes the form: ‘/var/qmail/somedomain.com/jimbo/Maildir/new’.

The command below uses ‘du’ to grab the size of all the directories in mailnames, grep filters out all but the ‘Maildir/new’ directory leaving us with a list of all our mailboxes and their size. Running them through sort in the manner shown orders them biggest to smallest. Just the way we want ‘em.

Log in as root and run the following:

du  /var/qmail/mailnames | grep 'Maildir/new' | sort -rnk1 > mboxsize.txt

Sample Output:

1047680 /var/qmail/mailnames/somedomain.com/karyon/Maildir/new
123820  /var/qmail/mailnames/somedomain.com/vickih/Maildir/new
94156   /var/qmail/mailnames/somedomain.com/info/Maildir/new
88368   /var/qmail/mailnames/somedomain.com/kathyh/Maildir/new

Delete those Suckers

Armed with all the mailboxes that forward and a list of the big offenders you wouldn’t think this would need much explanation, but after several weeks or months of collecting files you may find you have to many files in the directory to delete with a simple “rm * -f”. Apparently there are limits to the number of files you can delete at one time with a wildcard.

If you run into difficulties with rm give this a shot:

CD to the directory and run ‘ls -al’. Note that the name of your server is a string common to all files, replace MYSERVER below with the common string:

find . -name '*MYSERVER*' | xargs rm

In your gusto to clean things out remember that there are legitimate reasons to keep a mailbox turned on for forwarded accounts, (The boss may want to be able to review mail sent to sales@ to make sure that leads are being followed up on, etc.) and some users may just get incredible amounts of mail. With that in mind this should help you keep a lid on things. Once you’ve got things cleaned out you may be able to use quotas to help the problem from repeating.

PHOTOSTREAM

28-80In 3DDrive inDawgs!IMAG0302IMAG0206Blue Heaven TableGatorsRing Bell
Web hosting for webmasters
UA-15854484-1