CartMetrix - Do you know yours?

8/31/2007

Quickly Copy MySQL Database to Remote Host

Copy an entire database:

mysqldump LOCAL_DBNAME | ssh USER@REMOTE_HOST mysql -p REMOTE_DBNAME

Copy a single table:

mysqldump LOCAL_DBNAME LOCAL_TABLE | ssh USER@REMOTE_HOST -p REMOTE_DBNAME REMOTE_TABLE

This shortcut only works if you can access the local DB without a password. If you have to login to both local and remote MySQL servers, the MySQL password prompts get mashed together. You could specify the password on the command line like

-pPASSWORD

but your shell may keep the password in its history so that anyone with access to your account could pick through your shell history and retrieve the password. Using the MySQL password prompt doesn’t do this.

Popularity: 100%

8/23/2007

PHP gethostbyname() and DNS

For PHP’s gethostbyname() to work properly, the server’s DNS must be properly configured with available nameservers in /etc/resolv.conf (on Linux boxes). Without a work domain name resolution kit, gethostbyname() returns the hostname supplied to the function.

Make sure /etc/resolv.conf contains several nameservers to query. The format is

nameserver xxx.xxx.xxx.xxx
nameserver yyy.yyy.yyy.yyy

Where xxx.xxx.xxx.xxx and yyy.yyy.yyy.yyy are the IP addresses of nameservers the host has permission to use.

OpenDNS is a free DNS service that allows public access to their nameservers at:

208.67.222.222
208.67.220.220

To use in /etc/resolv.conf use:

nameserver 208.67.222.222
nameserver 208.67.222.220

Using OpenDNS’s nameservers could even boost your server’s performance. Their goal is to provide some of the faster domain name resolvers on the internet for free.

Popularity: 37%

8/7/2007

SSH-Keygen For Public Key Authentication

ssh-keygen -t dsa -b 1024
[root@titan .ssh]# ssh-keygen -t dsa -b 1024
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
d2:32:02:4e:25:27:53:8f:c1:ab:80:02:0f:25:da:af root@host.domain.com

Then copy in any public keys into ~/.ssh/authorized_keys

Popularity: 38%

Lighttpd vs thttpd Update3

I have been asked several times recently about my original comparison of Lighttpd and thttpd and subsequent benchmarks for Lighttpd vs thttpd.

I do not have updated benchmarks for these two. However, Lighttpd is still under active development with the latest release Lighttpd 1.4.16 dated 7/24/07. The most recent thttpd release has a newest file date of 6/29/05 (I couldn’t find an official release date for thttpd 2.25b). I would surmise that the performance for Lighttpd would only have increased as it is still under active development. Without a new release, thttpd’s performance surely hasn’t changed since my benchmark.

Popularity: 33%

8/6/2007

Easily View PHP Errors on Yahoo Business Hosting

I don’t often use Yahoo Business Hosting, but every once and a while I have a client who is already hosting their sites there. With all large monolithic hosting companies there are caveats to using their systems… PHP especially.

Yahoo Hosting does not support .htaccess files and does not allow display of PHP error messages directly in the pages. These are all well and good for the obvious security reasons. Yahoo does allow the logging of PHP errors if you follow their directions to enable it.

Once you enable the scripts log, lock down the directory so you must have a password to access. It doesn’t quite make sense to put the logs in a live web directory. It is trivial for any script kiddie to call up the script log errors in their browser by manually keying in the URL. Yahoo Hosting should make a bigger point of emphasizing securing this directory when it shows how to enable the scripts log.

Unfortunately, without console access there is no easy way to follow the log as one would normally do with tail. Directly loading the log in a browser can return a very long page with the most important information (ie. the last error encountered) at the very bottom of the page. I created a simple script called phperrors.php to make following the log easier. The script provides easy access to the errors log by refreshing automatically every 30 seconds and displaying only the last lines of the log with the newest ones on top. The refresh time is configurable and can be disabled. The number of lines listed may be set in the refresh form. Plus, the script is completely self-contained in a single file.

Installation / Usage

  1. Enable scripts.log as directed above from Yahoo’s support.
  2. Upload this file to the root of your hosting account.
  3. For security, rename this file to a long (at least 6 characters) random name
    that only you know. Something like:

    zx89adsf8-phperrors.php

    Don’t use my example name. That kind of defeats the purpose. I have included code to generate a random filename to use for renaming the file.

  4. Load the page in your browser.
  5. Bookmark the URL so you can find it again.
  6. Refresh browser as needed or select automatic refresh and hit Go.
  7. To stop automatic refresh uncheck refresh box and hit Go.
  8. To adjust the refresh rate adjust the $refresh_seconds variable below.
  9. If you find this script useful, buy me a beer by dropping a couple of bucks in my tip jar.

I realize renaming the file may be a moot point being that Yahoo allows direct access to the scripts log for anyone, but perpetuating poor security is never acceptable in my book. Perhaps some day soon, Yahoo will better emphasize how to protect this directory from everyone but the account owner.

Download: phperrors.php

Popularity: 38%


damonparker.org is proudly powered by WordPress
Entries (RSS) and Comments (RSS).

copyright © 2002-2008 damonparker.org. all rights reserved.

Close
E-mail It