Life of a Geek Admin

The Daily adventures of a true geek administrator

Life of a Geek Admin - The Daily adventures of a true geek administrator

Install mod_perl on Apache 2.2 on Windows 7

To continue on with developing on Windows using Apache/MySQL/PHP I wanted to add mod_perl to the mix. For this post I chose to make it work on Apache 2.2 but it could possibly work on Apache 2.4 as well, but I have not tested they portion yet.

First piece of the puzzle is to download a version of Perl that supports the Module on Apache. In the past I have gone with ActiveState’s ActivePerl but lately I have been using Strawberry Perl due to changes in retrieving older releases.I settled on Perl 5.10 release.

Download Strawberry Perl 5.10.5 from http://strawberryperl.com/releases.html and click on strawberry-perl-5.10.1.5.msi under the Strawberry Perl May 2011 section.
Once downloaded just double-click to install it, you can change the default installation path or change it to your preference. Once the installation is completed then, open a command prompt to set the perl environment and reboot the system.

c:\> cd C:\strawberry

Run the command

c:\strawberry> perl\bin\perl.exe update_env.pl.bat

Next download and compile the mod_perl using ppm (Perl Package Manager)

ppm install http://cpan.uwinnipeg.ca/PPMPackages/10xx/mod_perl.ppd

The installation process will start. Once it compiles the module it will ask where to put it. This will be your Apache modules directory (ex:c:/Apache2/modules)

Close the command prompt and edit c:\Apache2\conf\httpd.conf
We must tell Apache to load the module and tell it where the perl Dll lives. You can add this to the bottom of the file.

LoadModule perl_module modules/mod_perl.so
LoadFile "C:/strawberry/perl/bin/perl510.dll"

Find the mime section and modify this

AddHandler cgi-script .cgi .plx .plex .pl

Now we need to enable and add a few items to allow perl to execute.

Look for the alias_module section and make sure the cgi-bin line is pointed to the correct location.

ScriptAlias /cgi-bin/ "c:/Apache2/cgi-bin/"

Next you will need to add ExecCGI in the Option section.

Options Indexes FollowSymLinks ExecCGI

Save the changes and restart Apache service. We are now ready to test to see if it displays a simple Perl Hello script.

You can copy the code and save it as test.pl in c:\apache2\htdocs or anther directory of your preference.

#!c:\strawberry\perl\bin\perl.exe
# ^^^ this must be the first line of the script! ^^^
# start code

use strict;
use CGI;
my $q = new CGI;

# print header and start the markup output

print $q->header( "text/html" ),$q->start_html( "hello from perl cgi!" );
print $q->h2("Hello Mark...");
print $q->end_html;
# end code

I hope this helps get Perl working in your Windows Apache install.

Booting OS X Snow Leopard in 32 bit mode

Recently ran into an issue on a MacBook Pro and programming a Logitech Harmony 900 remote with communication when uploading the new configuration. The Program would just prompt to plugin the remote to the USB and would never recognize it was plugged in. After doing a bit of digging in the forums found the issue was with the Mac OS X drivers from Logitech for Harmony Remote 7.7.0 were 32 bit only.

Currently the only solution is to boot OS X into 32 bit mode. While searching through Apple support I found the solution to reboot the system into 32 bit mode which resolved the issue.

You can use either of these methods:
Method 1: Startup key combination (for current startup only)

  •     If your Mac uses the 32-bit kernel by default, but supports the 64-bit kernel, you can start up using the 64-bit kernel by holding the 6 and 4 keys during startup.
  •     If your Mac uses the 64-bit kernel by default, you can start up with the 32-bit kernel by holding the 3 and 2 keys during startup.

Your Mac will revert to the default kernel the next time you reboot it. This is the method I chose as it is just for that session.

Method 2: On-disk setting (persistent)

To select the 64-bit kernel for the current startup disk, use the following command in Terminal:

sudo systemsetup -setkernelbootarchitecture x86_64

To select the 32-bit kernel for the current startup disk, use the following command in Terminal:

sudo systemsetup -setkernelbootarchitecture i386

Note: This setting is stored in the /Library/Preferences/SystemConfiguration/com.apple.Boot.plist file and will take effect every time you start up from this disk. If you start up from a different disk, the setting on that disk, or the hardware default, will take effect.
Additional Information

Keys held during startup (such as 3-2 or 6-4, method 1 above) will override the setting in com.apple.Boot.plist (method 2 above).

 

Perform In-Place file edit with VBScript

Recently had the need to search and replace a configuration file on a system. This was part of an installation of an older program that required a variable to be replace with the computername. Being that the systems were Windows of several different releases (2000, 2003 and 2008) I could not use Powershell to complete the task and went with vbscript as the tool of choice.

Here is what the script looks like. In this example I am editing the config.ini file and looking for WIN01 and replacing it with the computername.

Const ForReading = 1
Const ForWriting = 2
Const FileIn = "c:\oldasdirt\bin\config.ini"
Const FileOut = "c:\oldasdirt\bin\config.ini" 

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(FileIn, ForReading)
Set wshShell = WScript.CreateObject( "WScript.Shell" )

strComputer =wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "WIN01", strComputer)

Set objFile = objFSO.OpenTextFile(FileOut, ForWriting)
objFile.WriteLine strNewText
objFile.Close

The script can be broken done into several sections.

  • define constants
  • set objects
  • set variables
  • do the work
  • close it up

For define constants we need to define the file for Reading and Writing and also define the input and output file.

Const ForReading = 1
Const ForWriting = 2
Const FileIn = "path to input file"
Const FileOut = "path to output file"

There are three File input / output constants available as shown in the table below.

Constant Value Description
ForReading 1 Open a file for reading only. No writing to this file can take place.
ForWriting 2 Open a file for writing. If a file with the same name exists, its previous contents are overwritten.
ForAppending 8 Open a file and write to the end of the file.

For FileIn and FileOut we just need to put the location and name of the file we want to edit.

Next we need to set the file system object , set the File object and set the shell environment.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(FileIn, ForReading)
Set wshShell = WScript.CreateObject( "WScript.Shell" )

Now we want to create a variable called strComputer and get the Environment variable for %COMPUTERNAME%.

strComputer =wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )

Next we need to open the file we want to edit into memory and then create a variable for finding and replacing the replacement text.

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "WIN01", strComputer)

And finally, lets write the changes to the file.

Set objFile = objFSO.OpenTextFile(FileOut, ForWriting)
objFile.WriteLine strNewText
objFile.Close

And that’s all there is to editing a file in place with vbscript. Hope you find this useful to your situation.

 

VLC v2.0.1 Released

The all-in-one VLC (Video Lan Media Player) has released a bugfix version of the best free cross platform player available. You can download it from here.  This is my goto piece of software on Windows and Linux for playing all types of media. Many fixes available in this release.

Changes between 2.0.0 and 2.0.1:
——————————–

Access:
* fix and improve the CDDB information retrieval
* fix the samba module compilation
* fix UDP / RTP multicast stream reception on Mac OS X when using the 10.7 SDK
* multiple fixes for HLS support, notably on Win32 and for encryption
* multiple fixes for Bluray discs playback
* fix for DVD decryption on some RPC-I drives

Codecs:
* Support for MXPEG files
* limit auto-detected threads to 4 in avcodec module
* fix quicktime audio codecs in RTSP streams

Demuxers:
* Fix multi-file splitted RAR archive support
* Fix a crash when seeking in mka
* Improve MKV multi-video tracks support

Muxers:
* Fix ogm header creation

Audio filters:
* limit spatializer filter distortions
* Use fastest SinC algorithm for samplerate module

Audio output:
* Fix S/PDIF passthrough with ALSA.
* Remove flawed ALSA channels autodetection. The available ALSA channels MUST be configured now (stereo by default).
* Fix delay when changing the volume on Mac OS X

Video filters:
* Fix gradfun unloading on Windows platform

Mac OS X interface:
* allow to hide the playlist to get a small controller window
* allow to hide the sidebar
* disable Lion fullscreen mode by default, since its behavior is misleading – this fixes fullscreen video output on a secondary screen
* noticebly faster launch time
* correct a few visual glitches and accessibility support
* re-enable visual feedback on seek and volume changes
* improve track synchronization panel
* fix fontconfig cache dialog, closure of the interface and numerous crashes
* fix crop, aspect ratio handling, DVD (no menu) support and Open subtitle menu

Qt interface:
* allow a native seek slider instead of the blue one
* fixes in the playlist, the addons dialog, the menus, the main toolbar the open dialogs, preferences and customization dialogs
* fix for fontconfig cache dialog, when rebuilding ASS fonts

Skins interface:
* fix for menus display
* Addition of $R to display current playback speed
* documentation update

Web interface:
* fix mobiles display for remote control mode
* support for .drc and .3ga extensions

Service discovery:
* fix SAP discovery, where an item was added multiple times
* fix SAP discovery on Mac OS X when using the 10.7 SDK
* Update Jamendo selections

Miscellaneous:
* fix DBus crash
* fix build issues on BSD, Linux/PPC and Linux/Sparc
* fix a crash on VLM close

Security:
* Update libpng to 1.5.9 (CVE-2011-3026)
* Update freetype to 2.4.9 (CVE-2012-1126 up to CVE-2012-1144)
* Fix MMS stack overflow (SA-1201)
* Fix RealRTSP heap overflow (SA-1202)

Translations:
* Update of Czech, Spanish, Swedish, Turkish and Walloon translations

Multiple Desktops in Windows 7

Continuing with the quest to get more of the features I like from Linux into Windows I now embark on having multiple desktops in Windows. This is a standard feature in Gnome and KDE and is very nice. There have been several for Windows in the past that are pay for, but I why pay when you can find a free version or one you can at least contribute to the author if you like it.

As a Windows systems administrator I have had the luxury of using many of the great tools from Microsoft in the SysInternals Suite. So I decided to look there first to see if such a bird exists and bingo there lies Desktops v1.02. According to the site Desktops allows you to organize your applications on up to four virtual desktops. Read email on one, browse the web on the second, and do work in your productivity software on the third, without the clutter of the windows you’re not using. After you configure hotkeys for switching desktops, you can create and switch desktops either by clicking on the tray icon to open a desktop preview and switching window, or by using the hotkeys.

Desktops v1.02 can be found at http://technet.microsoft.com/en-us/sysinternals/cc817881, Or you could just download the entire SysInternals Suite.

Once you have downloaded and extracted SysInternals or Desktops, you can fire up Desktops by double-clicking on desktops.exe and you will be presented with settings for Desktops. At this point you can select the hot keys for switching between the desktops and if you want it to Run automatically at login. Default is Alt + numbers which is good for most, but you can also select.

  • Alt
  • Control
  • Shift
  • Windows

and in combination with..

  • Numbers
  • Function keys

Click ok when done with your selections and Desktops will now be in the notification area.

To create another desktop click on the notification area and select a desktop and it will be created and you can start customizing it. there are limitations to the tool but it has some usefulness.

According to SysInternals, desktops reliance on Windows desktop objects means that it cannot provide some of the functionality of other virtual desktop utilities, however. For example, Windows doesn’t provide a way to move a window from one desktop object to another, and because a separate Explorer process must run on each desktop to provide a taskbar and start menu, most tray applications are only visible on the first desktop. Further, there is no way to delete a desktop object, so Desktops does not provide a way to close a desktop, because that would result in orphaned windows and processes. The recommended way to exit Desktops is therefore to logoff.

Have fun and paly with Desktops. It has it’s uses and for free it is worth a look.

Install WordPress on Apache 2.4 on Windows

In following along with a previous post on installing Apache 2.4 PHP 5.4 and MySQL 5.5.21 on Windows, I will explain how to install WordPress 3.3.1. The installation is very easy to accomplish.

First download the latest version of WordPress from here, which at the time of this post it is 3.3.1. Next you will need to unzip the file to c:\apache24\htdocs\ on your system.

Next step is to create an empty database. To accomplish this task open a command prompt.Login to mysql and create the DB (wordpress) and create the user account and grant access.

$ mysql -u root -p
mysql> CREATE DATABASE `wordpress` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> CREATE USER 'wpadmin'@'localhost' IDENTIFIED BY 'P$ssw0rd!';
mysql> CREATE USER 'wpadmin'@'%' IDENTIFIED BY 'P$ssw0rd!';
mysql> GRANT ALL ON `wordpress` . * TO 'wpadmin>'@'localhost';
mysql> GRANT ALL ON `wordpress` . * TO 'wpadmin'@'%';
mysql> exit

Close the command prompt open Windows Explorer and open C:\Apache24\htdocs\wordpress\wp-config-sample.php with a text editor of your choice.  Find the following lines and change the database name to wordpress and your username and password for , which by default is root with no password.

// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define(‘DB_NAME’, ‘wordpress’);

/** MySQL database username */
define(‘DB_USER’, ‘wpadmin’);

/** MySQL database password */
define(‘DB_PASSWORD’,  'P$ssw0rd');

/** MySQL hostname */
define(‘DB_HOST’, ‘localhost’);

Save the file as wp-config.php.

Open your Internet browser and type in http://localhost/wordpress/wp-admin/install.php and everything from there should run smoothly to complete the installation.

Changing Windows Computer Description from a Command Prompt

By default the Windows OS installation doesn’t input a computer description. In most cases this is not an issues but, if you want to add one here’s how to do it. Typically the computer description is changed by using thew GUI in System > Advanced System Settings > Computer Description.

This same task can be completed on the command prompt with the net config command. the syntax is:

net config server /srvcomment:”Input my description”

example:

c:\> net config server /srvcomment:"My Super Fast Server"

You can verify the change by typing

c:\> net config server
Server Name                           \\win2008tst
Server Comment                        My Super Fast Server

Software version                      Windows Server 2008 R2 Enterprise

Server is active on
NetbiosSmb (win2008tst)

Server hidden                         No
Maximum Logged On Users               16777216
Maximum open files per session        16384

Idle session time (min)               15
The command completed successfully.

You can expand on this further by adding set command to prompt for a value or have it read from a file.

Reading value from a file

c:\> set /P cpdesc= <descpt.txt
c:\> net config server /srvcomment:"%cpdesc%"
c:\> set cpdesc=

Prompting for a Value

c:\> echo Enter a Computer Description and press enter
c:\> set /P cpdesc=
c:\> net config server /srvcomment:"%cpdesc%"
c:\> set cpdesc=

Reference: http://support.microsoft.com/kb/824386

How install Apache 2.4 PHP 5.4 and MySQL 5.5.21 on Windows 7

Recently decided to install a working Apache 2.4 / PHP 5.4.9 and MySQL 5.5 running locally on my Windows 7 laptop for web design, not using XAMPP or WAMP installation methods. Which are great but this round I wanted to match my Linux server.

Apache 2.4 Install

First download Apache 2.4 from http://www.apachelounge.com/download/ (httpd-2.4.1-win32.zip) Apache 2.4.1
with IPv6 apr-1.4.6 apr-util-1.4.1 apr-iconv-1.2.1 pcre-8.21 lua-5.1 libxml2-2.7.8 openssl-1.0.0g zlib-1.2.6. This release is supported by the PHP 5.4 install from windows.php.net for Apache 2.4.

Extract the zip and copy it to the root of C:\. This will be C:\Apache24 when it is all done.

Update 01-17-2013: The version of the php5apache2_4.dll must match the version of PHP you are installing. The link that was reference before has been changed and moved to http://www.apachelounge.com/download/additional/ for versions 5.4.9 and earlier. As of PHP 5.4.10 the module is now included in the Windows build.

PHP 5.4.9 and Earlier

Download PHP 5.4.9 VC9 x86 Thread Safe from http://windows.php.net/download/releases/archives/php-5.4.9-Win32-VC9-x86.zip . Extract and rename folder to php and move to C:\
Also, download php5apache2_4.dll-php-5.4-win32.zip (http://www.apachelounge.com/download/win32/modules-2.4/php5apache2_4.dll-php-5.4-win32.zip)
Runs with PHP 5.4 Thread Safe (TS), and only with Apache 2.4 Win32 VC9 or VC10.

PHP 5.4.10 and higher

Download PHP 5.4 VC9 x86 Thread Safe from http://windows.php.net/download/ . Extract and rename folder to php and move to C:\.

Update 01-17-2013: This next edit seems to cause issues with php5apache2_4.dll not found errors, so I have added two options for PHP 5.4.9 and earlier and PHP 5.4.10 and above. I want to thank all those who have brought this to my attention and I hope this helps out. Also, due to the addition of the php5apache2_4.dll being included in PHP 5.4.10 and above builds you no longer need to download the module separately.

PHP 5.4.9 and earlier Option 1

Extract php5apache2_4.dll-php-5.4-win32.zip and copy php5apache2_4.dll to the c:\php\ directory. This is needed to allow Apache to use PHP.  Edit Apache’s config file, c:\Apache24\conf\httpd.conf and add the following lines to the bottom of the file.

LoadModule php5_module "c:/php/php5apache2_4.dll"
AddHandler application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "C:/php"

While we are at it we can add index.php to Apache’s list just incase we want to have a starting page as php.

Find Directory index and add index.php

DirectoryIndex index.html index.php

Next we need to input a value  for ServerName variable. You will have to un-comment it. Save the changes to the config file. Next move to the Register Apache Service step.

PHP 5.4.9 and earlier Option 2

Extract php5apache2_4.dll-php-5.4-win32.zip and copy php5apache2_4.dll to the c:\php\ext directory. This is needed to allow Apache to use PHP.  Edit Apache’s config file, c:\Apache24\conf\httpd.conf and add the following lines to the bottom of the file.

LoadModule php5_module "c:/php/ext/php5apache2_4.dll"
AddHandler application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "C:/php"

While we are at it we can add index.php to Apache’s list just incase we want to have a starting page as php.

Find Directory index and add index.php

DirectoryIndex index.html index.php

Next we need to input a value  for ServerName variable. You will have to un-comment it. Save the changes to the config file. Next move to the Register Apache Service step.

PHP 5.4.10 and newer

Edit Apache’s config file, c:\Apache24\conf\httpd.conf and add the following lines to the bottom of the file.

LoadModule php5_module "c:/php/php5apache2_4.dll"
AddHandler application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "C:/php"

While we are at it we can add index.php to Apache’s list just incase we want to have a starting page as php.

Find Directory index and add index.php

DirectoryIndex index.html index.php

Next we need to input a value  for ServerName variable. You will have to un-comment it. Save the changes to the config file. Next move to the Register Apache Service step.

Register Apache Service

Now let’s register Apache as a service. Open a command prompt and type.

c:\apache24\bin\httpd -k install

If do not want Apache starting automatically at start-up/reboot:

GUI Way

  • START | RUN
  • Type in services.msc, hit Enter or click OK
  • Locate Apache2 service and double-click (or right-click for Properties)
  • Find the caption Startup type: (in the middle of the dialog box), use the pull-down and select Manual
  • Click OK

Command line

C:\> sc config Apache2.4 start= demand

Add

c:\Apache24; c:\Apache24\bin

to PATH in Environment variables. PATH ENVIRONMENT (System Properties | Advanced | Environment Variables | System variables | Path).
Example:
;c:\php;c:\apache24;c:\apache24\bin;

Now lets check Apache settings by issuing the command, c:\Apache24\bin\httpd -S

PHP Edits

Now we have to do a few edits to the php.ini file to tell it to load support for mysql and the location for the extensions. Since there is not a already set php.ini file we need to rename one of the two examples to php.ini.

Rename c:\php\php.ini-development to php.ini

Now let’s edit php.ini
Uncomment extension directory.

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "ext"

Uncomment mysql modules
extension=php_mysql.dll
extension=php_mysqli.dll

Save the changes and open a command prompt. Check to make sure it shows loaded modules.

C:\> php -m

So now we have Apache running and configured to use php. Lets create a file called info.php, save it and see if Apache parses the info correctly to display the results.

Open Notepad or your favorite Windows editor and type and save the following.

 <?php
phpinfo();
?>

Open your browser and type, localhost/info.php for the location and you should receive alot of information about PHP.

MySQL
Download and install mysql-5.5.21-win64.msi. Change installation directory to C:\MySQL\MySQL Server 5.5 instead of Program files as there could be permissions issues. Once the installation is completed you can let the configuration wizard run and setup the database server. The defaults will work just fine, but remember what you set the password to for root.

PHPMyAdmin
PHPMyAdmin is a very nice tool to use for administering your MySQL installation.
Download and install phpmyadmin-3.4.10.1-english.zip.
Extract the file and move to c:\apache24\htdocs. Rename directory to phpmyadmin.
Create a config directory under phpmyadmin. Open a browser and type localhost/phpmyadmin/setup/index.php to complete the installation.

At this point you should have a working Apache / PHP / MySQL installation running and ready for you to start developing !!!

Install GnuWin32 tools on Windows

Being a geek that uses many OS’s you always run into instances that you think, that would be great if I could do that on Windows, Linux or OSX.

The command line tools available with Linux are very handy and Windows is starting to get there with each release of Powershell, but personally I want them now and that is possible with several tools available. One such tool is GnuWin32.

The GnuWin project provides Win32-versions of GNU tools, or tools with a similar open source license. The ports are native ports, that is they rely only on libraries provided with any standard 32-bits MS-Windows operating system. Unlike CygWin or Msys, native ports do not rely on some kind of Unix emulation, so that there is no need to install additional emulation libraries. At present, all developments have been done under MS-Windows-XP, using the Mingw port of the GNU C and C++ (GCC) compilers. Utilities and libraries provided by GnuWin, are used and distributed with packages such as GNU Emacs and KDE-Windows.

SO let’s get started and download GetGnuWin32-0.6.3.exe and double-click to extract it to a folder on your system. Once you have it extracted open a command prompt and navigate to the extracted location and run download.bat. The process will connect and download all the GnuWin32 packages available and download them to the directory. You will be prompted several times and should accept the defaults.

Now lets install what has just been downloaded. While still at the command prompt type:

c:\Downloads\GetGnuWin32\> install c:\gnuwin32

This will install all the downloaded packages to c:\gnuwin32. I recommend using this directory for the main reason if you install under C:\Program Files you can be faced with NTFS permissions that will possibly inhibit proper operation. Be patient as this will take awhile to complete.

Now you are ready to use the tools, but there is one issue. If you type the command and not be in the c:\gnuwin32\bin directory or specify it in the command line you will get a command not found error. You can remedy this by adding c:\gnuwin32 to the path.

  • From the desktop, right-click My Computer and click Properties.
  • In the System Properties window, click on the Advanced tab.
  • In the Advanced section, click the Environment Variables button.
  • Finally, in the Environment Variables window (as shown below), highlight the Path variable in the Systems Variable section and click the Edit button. Add or modify the path lines with the paths you wish the computer to access. Each different directory is separated with a semicolon as shown below.

C:\Program Files;C:\gnuwin32\bin

Now test it by typing any one of the many commands at your disposal!!!

 

Switch to our mobile site