How to install telnet client in Windows 7

The Traditional Windows Install

By default Windows 7 does not have the telnet client available, but you can fix that by the normal “add and remove windows components route”…

  1. Start > Control Panel > Programs > Turn Windows features on or off
  2. Check the box next to Telnet Client

A Better and MUCH Faster Way

Let’s face it, if you’re looking for telnet in Windows you’re probably not excited about navigating the GUI (especially that many steps down the rabbit hole) to install a command line client. Worse yet, you’re probably already on the command line and you just typed “telnet someserver ” only to find out…

'telnet' is not recognized as an
internal or external command,
operable program or batch file.

Since you are already there, try this…

1
 pkgmgr /iu:"TelnetClient"

Give it a moment after you hit enter then try telnet again. You should be good to go.

You can read more here… 
http://technet.microsoft.com/en-us/library/cc771275(WS.10).aspx.
One caviet however, they say “When the command prompt appears again, the installation is complete.” In my experience, there is more going on in the background and you have to wait a few more seconds.

Posted in telnet, terminal, Windows 7 Tagged , , , ,

Subversion security issues – .svn directory has your source code in it

Stop Publishing Your Source!

Well, unless you’re working on an Open Source project that is.
Many of the developers I have worked with on web based apps use a working copy for development purposes or even for staging servers (as opposed to exporting from Subversion.) The problem with this is that little .svn directory has lots of information in it. Including copies of the checked out version of your code. So someone that is creative can actually see the source if you do not protect that directory. What to do?

System-wide Lockdown in http.config

If you have the access, this is the way you want to go. Lock down the server and life will be good.

1
2
3
4
5
6
7
8
9
$ sudo vi /etc/httpd/conf/httpd.conf
...
# somewhere (preferibly in a logical place
# near other directory tags) add...
<Directory ~ ".*\.svn">
    Order allow,deny
    Deny from all
    Satisfy All
</Directory>

.htaccess level

Personally I would do this even if you change the server config, but that’s just me, I’m just paranoid.

1
2
3
4
5
6
7
$ cd httpdocs
# or public_html or whatever your
# web accessible root directory is
$ echo '
        RewriteEngine on
        RewriteRule ^(.*/)?\.svn/ - [F,L]
'
>> .htaccess

Now help out the rest of your team

One last step, check that .htaccess file into subversion and you’ll protect everyones’ installations.

Posted in Code Snippets, Command Line, Server Administration, Source Control, Subversion, Web Servers Tagged , , , , , , , , , , ,

Subversion Update: Can’t move .svn/tmp/entries to .svn/entries: Operation not permitted

Just one little change to check in before the day is over, but my working copy needs to be updated first. Then I get this little gem of an error “Can’t move .svn/tmp/entries to .svn/entries: Operation not permitted”. It is not always entries, but one file or another in the .svn directory has become locked. Or more specifically has had the “user immutable” flag set. Not sure exactly what process has done this, but as a normal user the file is effectively locked from moving it. Which is exactly what Subversion is trying to do. But from the command line you can easily remove the flag

1
2
cd /home/me/svnworkingdir
chflags -Rv nouchg .
chflags
Chnge File Flags command line utility

-R recursive, -v Verbose (tells you which files changed)

To find out more…

1
man chflags

Posted in Source Control Tagged , , , , ,

MySQL: Cannot load from mysql.proc. The table is probably corrupted

Ok this one sounds pretty scary, but more than likely you just upgraded MySQL didn’t you? Did you run mysql_upgrade?

Ok lets back up a bit. I just upgraded to MySQL 5.5.x using yum and a third party repo but when I tried to create a new function I got “Cannot load from mysql.proc. The table is probably corrupted” which is not the kind of message you want to receive on a Friday afternoon especially when it’s talking about a mysql.* table. Fortunately I was able to remain calm (primarily thanks to automated nightly backups) and think things through (primarily thanks to the quad iced latte on my desk).

The yum upgrade (or any other package manager I’m assuming) is not going to convert your tables for any changes that may be needed. That would be potentially changing your data which, in most cases would be poor form for the packages. Given peoples’ fly-by-the-seat-of-your-pants approach to upgrades, and the fact that backups usually only happen after things start to go wrong, you really want to keep that roll back path as much as possible.

From the command line you want to run mysql_upgrade, which works very much like any of the MySQL command line utilities to check every database and table (assuming the user has access) for compatibility problems, and attempt to fix them.

1
2
3
4
5
6
7
8
$ mysql_upgrade -u someAdminUserLotsOPrivs -p
Enter password:
Looking for 'mysql' as: mysql
(...)
SomeDabase.MyTable                         OK
SomeDabase.YourTable                       OK
SomeDabase.SomeonesTable                   OK
(etc...)

You can read more here http://dev.mysql.com/doc/refman/5.5/en/mysql-upgrade.html

Posted in Database Administration, MySQL, Server Administration Tagged , , , , , ,

Find out what process is listening on a particular port on a Linux server

I was recently trying to debug an app that had gone rouge on a server because of a PHP upgrade. It was a web based application listening on a particular port and after the upgrade it just returned 500 server errors. A quick scan of the Apache logs, and even a deeper grep of them returned no matching errors so I realized, although the application was using PHP it was using another process to serve the pages. The urls of the application had the port 8443, so I knew whatever was serving it up was listening on that port.

Enter netstat

By default netstat tries to give you a human readable list of services. But with the -n flag you can see the numeric ports. You’ll also need to add -l (show listening ports) or -a (show all ports) since the listening ports are not included by default. -p will include the process id and the “program” that is listening which is what we really want. Grep is a nice way to narrow things down after that…

1
2
3
$ netstat -nlp | grep 8443
tcp        0      0 0.0.0.0:8443          0.0.0.0:*
           LISTEN      1234/lighttpd

Posted in Command Line, grep, Server Administration, Web Servers Tagged , , , , , , ,

Find all .htaccess files with a particular php configuration setting

After some testing on a server with a strange setup I needed to find all of the .htaccess files that might contain a particular php configuration directive. The pattern was unique enough that I would have probably just done a recursive grep for it in any other circumstance. But by default “grep -R someSearchString *” would ignore dot files like .htaccess, and on a bigger server this could have grep looking through a lot of files when I knew I only wanted to search .htaccess files. “grep -R someSearchString .*” would be just bad since it would recurse into the ‘..’ directory, so you would end up searching your whole harddrive.

The solution? “find”

1
2
3
$ cd /home
$ sudo find ./ -iname ".htaccess" -exec grep -H some_php_config {} \;
./someuser/httpdocs/.htaccess: some_php_config some_value

Sudo runs the command as root, since I’m looking in everyones’ home directories. find is the command that is actually looking for the files. Then it passes the matches to grep. The -H flag on grep gives you the name of the files, without it you would just get the matching lines from the files, but no indication which files they were in.

Just find all .htaccess files

In some cases it’s just nice to be able to find all of the .htaccess files

1
2
3
4
$ sudo find ./ -iname ".htaccess" -exec echo {} \;
./someuser/httpdocs/config/.htaccess
./someuser/httpdocs/.htaccess
./someuser/httpdocs/.htaccess

Posted in Command Line, find, grep, Linux, Server Administration, Web Servers Tagged , , , , , ,

List installed packages with yum

How do I find out which packages are already installed with yum.

The command you’re looking for is ‘yum list installed’ but you might want to combine it with grep or less because it’s most likely going to be a long list.

Look for php packages:

1
$ yum list installed | grep php

Just page the whole list:

1
$ yum list installed | less

Of course now that you know that, perhaps you want to know what packages are available to you:

1
$ yum list available | less

And of course you should check to see what needs to be updated on a regular basis:

1
yum list updates | less

Posted in Linux, Server Administration, Web Servers Tagged , , , , ,

Case Sensitive Comparisons in MySQL Where Clause

How can I make MySQL treat my query as case sensitive?

As with all good tools there’s more than one way to get the job done. Assuming you have access to change the structure of the table you have to think about the way you want to access the data by default. Is this something like a password that will always be case sensitive? (if it actually is a password, we should talk about not storing your passwords in plain text sometime.) Or is this something like a name that usually would be case insensitive but for whatever reason you want to make a case sensitive comparison?

Change the data to case sensitive permanently

Your first option is to alter the column to be case sensitive. Or in MySQL terms change the collation (or character set) to a case sensitive or “Binary” setting. Assuming the column is UTF8 you could do something like…

1
2
3
ALTER TABLE `MyTable` CHANGE `MyColumn`
  `MyColumn` VARCHAR( 3 ) BINARY
  CHARACTER SET utf8 COLLATE utf8_general_ci NULL;

Of course there are a variety of reasons this might be something you don’t want to make system wide. Not the least of which is the fact that a change like that would require a pretty extensive regression test in an existing system to make sure you don’t break something that was counting on the case insensitivity of that column.

One time case sensitive comparison in MySQL

The alternative is to just convert the column to binary inline. This will allow you to treat the row (or in the case of this example, the string) as case sensitive without altering the table structure.

1
2
3
4
5
6
7
8
9
10
mysql> SELECT
    ->     'a' = 'A' AS NormalCIEqual,
    ->     'a' = BINARY 'A' AS BinaryCS,
    ->     'a' = BINARY 'a' AS BinarySame;
+---------------+----------+------------+
| NormalCIEqual | BinaryCS | BinarySame |
+---------------+----------+------------+
|             1 |        0 |          1 |
+---------------+----------+------------+
1 ROW IN SET (0.00 sec)

This will also work with other types of comparisons…

1
2
3
4
5
6
7
8
9
mysql> SELECT
    ->     'a' LIKE 'A' AS NormalCILike,
    ->     'a' LIKE BINARY 'A' AS BinaryCS,
    ->     'a' LIKE BINARY 'a' AS BinarySame;

mysql> SELECT
    ->     'a' REGEXP 'A' AS NormalCIRegex,
    ->     'a' REGEXP BINARY 'A' AS BinaryCS,
    ->     'a' REGEXP BINARY 'a' AS BinarySame;

Posted in Code Snippets, Database, MySQL, SQL Tagged , ,

Cannot load Zend Extension Manager – it was built with configuration 1.2.0, whereas running engine is API220090626,NTS

After upgrading to PHP 5.3.x I’m receiving an error

1
2
3
4
5
$ php -v
Cannot load Zend Extension Manager
    - it was built with configuration 1.2.0,
    whereas running engine is API220090626,NTS
   ...

This is because you have Zend Optimizer installed which only works with PHP up to 5.2.x. You’ll want to comment out the Zend Optimizer configuration in your php.ini and then look into Zend Guard if you still need to work with “Zend Binary” code. Of course this presents another problem as scripts compiled with Zend Optimizer won’t work with Zend Guard. If you’re using third party “optimized” scripts and there is no Zend Guard version available or you want to continue to use Optimizer for other reasons you’ll probably want to move back to PHP 5.2.x.

Disabling Zend Optimizer

For me that meant commenting out the following lines in my php.ini

1
2
3
4
5
6
[Zend]
zend_extension_manager.optimizer=/usr/local/Zend/lib/Optimizer-3.3.9
zend_extension_manager.optimizer_ts=/usr/local/Zend/lib/Optimizer_TS-3.3.9
zend_optimizer.version=3.3.9
zend_extension=/usr/local/Zend/lib/ZendExtensionManager.so
zend_extension_ts=/usr/local/Zend/lib/ZendExtensionManager_TS.so

Posted in languages, PHP, Server Administration, Web Servers Tagged , , , , , ,

How do I Tell What Version of Linux I’m Running?

How do I tell which version of Linux is on my server?

There are a number of ways, there is a command line tool `lsb_release` used to check the distribution, and version

1
2
3
4
5
6
$ lsb_release -a
LSB Version:    :core-x.x-ia32:core-x.x-noarch:graphics-x.x-ia32
Distributor ID: Fedora
Description:    Fedora release 14 (Laughlin)
Release:    14
Codename:   Laughlin

Unfortunately it is not available on all systems, especially if your system is really out of date. But you can try the following…

1
2
$ cat /etc/*-release
CentOS release 5.4 (Final)

Or…

1
2
$ cat /etc/*-version
Slackware 11.0.0

Posted in Linux, Server Administration, Web Servers Tagged , , , , ,