WordPress on OSX (10.6.8), Apache, PHP & htaccess

I’ve just managed to get OSX 10.6.8 to work with mod_rewrite and .htaccess to be able to let WordPress rewrite it’s URLs. Here is what I did.

I installed WordPress to my homefolder so I’ll access it using http://localhost/~ola/wordpress. Apache is configured to use a split config in OSX so to change the directives for the home folder you change the file /private/etc/apache2/users/Ola.conf. I changed AllowOverride None to AllowOverride All and restarted Apache.

I got a 403 Permission denied message. I checked the Apache error log /var/log/apache2/error_log. It said: [Mon Nov 28 16:30:47 2011] [error] [client 127.0.0.1] Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /Users/Ola/Sites/slipstream/wp-admin/options-permalink.php, referer: http://localhost/~ola/slipstream/wp-admin/options-permalink.php

I added the Options directive FollowSymLinks to /private/etc/apache2/users/Ola.conf, restarted Apache and it worked fine.

I’m only using this config as a development box so I’m not sure if it has any security implications. If you have any knowledge about this just let me know.

Using Motion webcam software to capture an image every 30 seconds

Sometimes I use a webcam to capture images that I then use for time lapse videos. Other times I use my old Canon camera with CHDK and an interalometer script.

I have been trying to find a simple and robust webcam tool for this for years but all packages are too complicated and anoying. I just want to take an image every 30 seconds and be done with it. No HTTP server. No fancy scheduling. Nothing more than getting my images from the camera.

In Windows I have tried webcamXP and that’s pretty good. In Linux I have been running Motion. It’s a full featured motion detection package. Capable of much more than I want.

I adjusted the config file for Motion to only save one image every 30 seconds. Just as I want it.

My Motion config file (~/.motion/motion.conf)

# Motion is a webcam software that is designed for doing motion detection.
# I made the most simple config I could to disabled all motion detection
# features. Instead I just use it to take one picuture every 30 seconds.
# It's configured for giving the hightest quality possible with a
#   046d:0992 Logitech, Inc. QuickCam Communicate Deluxe
#
# Visit the web site for more information about Motion
#   http://www.lavrsen.dk/foswiki/bin/view/Main/WebHome

snapshot_interval 30
width 1280
height 960
quality 95
text_right ""
target_dir /home/ola/webcam/capture
snapshot_filename %Y-%m-%d/%Y%m%d-%H%M%S

process_id_file /var/run/motion/motion.pid
output_normal off
v4l2_palette 1
framerate 2

Multiple user profiles for Google Chrome

Recently I wanted to set up multiple profiles in Google Chrome. One for my personal browsing and one for my work. This way I don’t need to sign in and out from my different google, twitter, flickr and facebook accounts.

There is no GUI for this and it involves running some command line but it’s not too hard.

You should run all commands on one line and make sure to change the paths to your user name and profile.

Windows 7 / Vista

First you make a copy of your current default profile. You can do it either in Windows Explorer on on the command line.

xcopy "C:UsersOlaAppDataLocalGoogleChromeUser DataDefault" "C:UsersOlaAppDataLocalGoogleChromeUser DataOla" /e /i /h

Then you reset your new profile

C:UsersOlaAppDataLocalGoogleChromeApplicationchrome.exe --user-data-dir="C:UsersOlaAppDataLocalGoogleChromeUser DataOla" -first-run

Then you create a new shortcut on your desktop to launch your new profile

C:UsersOlaAppDataLocalGoogleChromeApplicationchrome.exe --user-data-dir="C:UsersOlaAppDataLocalGoogleChromeUser DataOla"

Ubuntu 10.10 (Linux)

Copy default profile

cp -r /home/ola/.config/google-chrome/Default/ /home/ola/.config/google-chrome/Ola

Reset your new profile

/opt/google/chrome/google-chrome --user-data-dir="/home/ola/.config/google-chrome/Ola" -first-run

And add a new Launcher (shortcut)

/opt/google/chrome/google-chrome --user-data-dir="/home/ola/.config/google-chrome/Ola" -first-run

That’s all there is to it.

 

Making screencasts for Youtube with CamStudio

Yesterday I needed to find a simple and robust solutions for recording a screencast. It turned out to be not as easy as I thought.

To get a similar workflow as with my other video editing I wanted it to work like this:

  1. Record a 1280 x 720 section from my screen to a high quality format
  2. Open and edit the recorded file in Sony Vegas Platinum 8
  3. Render it from Vegas to a lossless format
  4. Re-render it using HandBrake
  5. Upload the file to Youtube

Record with CamStudio

I started out with the latest beta of CamStudio. It a nice, simple and easy tool that does what I need.

My first attempt was to save an AVI file with the included Microsoft Video 1 codec. The quality was pretty low so I tried to use the CamStudioCodec (from their web site). I got a nice looking AVI. However Vegas didn’t really like this file. It worked, but it was very slow.

Then I tried to use the Huffyuv codec that I had installed recently when I optimized my HDV workflow. It created a BEAUTIFUL HUGE file that I could work with in Vegas. I edited the file, normalized the audio and rendered the video almost exactly the same way as I render all my other videos (described in my HDV workflow). I just lowered the resolution from 1440 x 1080 to 1280 x 720.

Re-render and upload to Youtube

I opened the file in HandBrake and selected the High Profile. I exported the file the same way as in my normal HDV workflow. It created a good looking file. I uploaded it to Youtube. Everything went smooth. Until I looked at the video on Youtube. It came out gray. No video at all. I made a test upload to Vimeo. No problems. I tried with different codecs and settings. Both in Handbrake, Vegas and CamStudio. All came out gray on Youtube.

I tried really hard to understand why this didn’t work but I couldn’t get it to work so I resorted to Avidemux. I opened the file in Avidemux. Selected the MPEG-4 ASP (Xvid) codec for video and MP3 for audio (I increased the quality on both). I exported the file and boom. It worked fine on Youtube.

I’m not sure what went wrong. Or why. And I ended up yet another tool in my belt. But I almost reached my goal of having similar workflows so I’m pleased.

WordPress development environment – Aptana, Virtualbox and Google Code

At work we always have a pretty hefty development environment. At home I’ve never had any dedicated environment for my web development. It’s both a relief and something I miss.

Today I’ll try to set up a WordPress development environment that’s a bit more robust than my old setup where I download the file I need to change from my website to my desktop, change it, upload it and refresh the browser.

The idea is to:

Setup Google Code

I registered mypersonalblog on Google Code. For now I’ll probably mostly use the SVN features so you can swap out Google Code for any other repository.

I created a wp-themes folder in trunk where I’ll put one folder for each theme I use.

I download the theme I want to use from WordPress Themes. I add -ol to the end of the theme folder to not confuse the themes with the original folder names. Then I check it in. This is done to easily be able to track my changes compared to the version I started out from later. Both to be able to see what I have done but also to easily be able to merge updated theme versions further down the road.

I change the styles.css file and add some information. Here is an example from the  Simplr-ol style.css file.

THEME NAME: Simplr-ol
THEME URI: http://code.google.com/p/mypersonalblog/ (Simplr http://www.plaintxt.org/themes/simplr/)
DESCRIPTION: My customizations to Simplr; "The original minimalist one-column, content-centered theme for WordPress. A different type of theme. For WordPress 2.6.x."
VERSION: 4.6.1-0.1
AUTHOR: Ola Lindberg (Simplr by Scott Allan Wallick)
AUTHOR URI: /wp/ (Simplr http://scottwallick.com/)
TAGS: variable width, fixed width, one column, widgets, theme options, options page, white, orange, blue, microformats, hatom, hcard

If any theme diverges a lot from the original theme I’ll maybe come up with a new name and upload it to WordPress Themes. For now I think it’s good enough to have them all in one Google Code repository.

Setup VirtualBox, Ubuntu, Apache and WordPress

I installed VirtualBox, created an Ubuntu appliance and installed Ubuntu 9.10 desktop. I installed the guest add-ons and Apache. I changed the VirtualBox network to Bridge mode so it get’s its own IP address.

Screenshot from the Network Adapters in VirtualBox. Open it from Devices / Network Adapters...

Update 101118: I recently wanted to make this setup on another computer (using a wireless network card) where I couldn’t get the Bridged Adapter to work. I searched around a bit and it and it seemed like some people had similar issues. Instead I configured VirtualBox to use two network cards. One using NAT (giving internet access) and one using Host-only Adapter.

2 nic setup. The first using NAT providing internet access from my guest
2 nic setup. The second card using Host-only Adapter to be accessible through my Host system.

With this setup you should access you guest os from your host os with the IP address your 2nd network card gets (in Windows).

I created an Apache Virtual Host and installed WordPress to that folder. The production URL is /wp/ and for the local URL I use http://o/blog. I added the IP for my virtual Ubuntu to the name o i my hosts file. Now I can surf to http://o/blog.

My virtual host is configured like this

	ServerName o
	DocumentRoot /home/ola/shared/web/ola
	#Only put the log file like this in the web root on a local server
	CustomLog /home/ola/shared/web/ola/ola-access.log combined

Share files between my workstation and the virtual Ubuntu server

To share files in VirtualBox I use SharedFolders. The folder on my Windows workstation where I checked out the repository is D:CodingMyPersonalBlog and it’s mapped to the name MyPersonalBlog in Ubuntu.

The VirtualBox Shared Folder dialog. Open it via Devices / Shared Folders...

To mount the folder MyPersonalBlog to /home/ola/MyPersonalBlog in Ubuntu you run the following from an Ubuntu terminal

sudo mount -t vboxsf mypersonalblog /home/ola/MyPersonalBlog

Make sure that the files are visible in you Ubuntu server by running ls -la in the folder.

Note! You need to run this every time you login or you can create a script and make it auto run.

ola@ubuntudevserver:~/MyPersonalBlog/wp-themes$ ls -la
total 28
drwxrwxrwx 1 root root 4096 2010-03-27 11:08 .
drwxrwxrwx 1 root root 4096 2010-01-01 19:09 ..
drwxrwxrwx 1 root root 4096 2009-12-29 11:45 AutoFocus-ol
drwxrwxrwx 1 root root 4096 2010-03-27 11:12 room-34-baseline-ol
drwxrwxrwx 1 root root 4096 2009-12-29 11:13 Simplr-ol
drwxrwxrwx 1 root root 4096 2010-03-27 11:13 .svn
drwxrwxrwx 1 root root 4096 2009-12-29 10:58 veryplaintxt-ol

The last thing to do is to tell WordPress that the themes exists. I do that by creating soft links in the theme folders

ola@ubuntudevserver:~/www/olalindberg.com/wp/wp-content/themes$ ls -la
total 24
drwxrwxrwx 5 www-data www-data 4096 2010-03-27 11:48 .
drwxrwxrwx 6 www-data www-data 4096 2010-03-27 11:20 ..
drwxrwxrwx 2 www-data www-data 4096 2009-12-19 00:22 classic
drwxrwxrwx 3 www-data www-data 4096 2009-12-19 00:22 default
-rw-r--r-- 1 www-data www-data   30 2010-03-27 11:01 index.php
lrwxrwxrwx 1 ola      ola        55 2010-03-27 11:48 room-34-baseline-ol -> /home/ola/MyPersonalBlog/wp-themes/room-34-baseline-ol/
drwxr-xr-x 3 www-data www-data 4096 2009-12-29 10:42 simplr
lrwxrwxrwx 1 ola      ola        45 2010-03-27 11:06 Simplr-ol -> /home/ola/MyPersonalBlog/wp-themes/Simplr-ol/

Now I can enable the themes in the WordPress admin panel.

The WordPress theme administration page

Note! If WordPress can’t see the themes look at the permissions for the shared folder. I set mine to 0777 since it’s a local setup.

Import all posts from the production setup

I use the build in WordPress feature to export all posts and pages to an XML-file. I import that file to my local setup. I include all attachments. Some minutes later I have all my posts in my local development environment.

If I need to re-import all posts I use the plugin Bulk Delete to empty my current local database. Then I empty the Media Library in the WordPress admin panel. One tip is to increase the number Media items per page via the Screen Options.

Setup Aptana

I installed Aptana, created a project file and added all my theme files to it. I have never used Aptana before so it’s a test. We’ll see how it goes.

Combine Time Lapses with standard DV – Avidemux and Sony Vegas

I’ve just gone trough some hoops to import a time lapse video made in Avidemux into my standard DV project in Sony Vegas. My first issue was to find a suitable video format and the second to get the size of the time lapse video to match the size of the DV format. I’ll go through all steps in an example project below. I’ll use a time lapse with 14 stills and a DV project (PAL, 720×576, 4:3) with one clip.

Sequence the filenames
Avidemux is a bit picky that the file names of the images are in a sequence. I use ReNamer to automatically serialize the images.

I use ReNamer to serialize file names
I use ReNamer to serialize file names

Making the time lapse video in Avidemux
Even though Sony Vegas can import still images I prefer Avidemux for my time lapses.

Open the first image in Avidemux and make sure all frames are visible in the video. Since I’m going to export the video to Sony Vegas I want to use a format that preserves as much quality as possible. I chose Huffyuv.

Select the frame rate you want. I choose 5 fps.

My time lapse images are in 640 x 480 px and my DV stream is in 720 x 576. I’ll resize the images to 768 x 576 px, then I crop 24 px on each side to get a 720 x 576 px image.

Scale the time lapse images in Avidemux
Scale the time lapse images in Avidemux

Save your time lapse video to avi.

To be able to play the video (in Windows Media Player) I had to install a codec for Huffyuv. I installed the latest ffdshow and selected to install Huffyuv only. I also had to enable Huffyuv in ffdshows VFW configuration utility.

Enable the correct codec
Compare the black border in the preview window with the next screenshot

Now you should be able to play the file in Windows Media Player and it’s time to import the video to Sony Vegas!

Import to Sony Vegas and fix the size problem
I start by just adding my two files to Vegas and preview them. I can see a black border around my time lapse file. I fiddeled around quite a while with this. I tried to resize the time lapse in Event Pan/Crop -tool but could only get that to work if I dissabled Maintain aspect ration.

Compare the black border in the preview window with the next screenshot
Compare the black border in the preview window with the next screenshot
See the black border on the left and right hand side in the preview window. Time lapse video has wrong pixel aspect ratio.
See the black border on the left and right hand side in the preview window. Time lapse video has wrong pixel aspect ratio.

Finally I found out that the pixel aspect ratio differs from my DV file and my time lapse file. On the DV file it’s set to 1,0926 (PAL DV) and on the time lapse it’s set to 1,0000 (Square). I changed it by right clicking on the media, select properties and it’s in the media tab.

Media properties for DV file
Media properties for DV file
Media properties for time lapse file
Media properties for time lapse file

You are done!

Big thanks fo LoRd_Mulder and DarkZell666 in the Avidemux forum for helping me out!

Script to cleanup Windows hidden attributes and AlbumArtSmall.jpg

I wanted to remove the hidden files attributes and delete some types of files so I created the following bat-file.

attrib -R -A -S -H D:Music* /S /D
del /S /P D:Music*AlbumArtSmall.jpg D:Music*desktop.ini

(Don’t ask me why /S /D should be last on the line when using attrib and first when using del, but the manual said so.)

The first line removes all read only, archive, system and hidden -attributes on all files, folders and subfolders in folder D:Music.

The second line removes all files named AlbumArtSmall.jpg and desktop.ini from the folder D:Music and all it’s subfolders. The /P argument asks for confirmation so if you are sure you can remove it.

Firefox hides tabs and fails

I while ago I introduced a friend to Firefox. I didn’t want to push it but just show it and I hoped it would stick. After some weeks I asked if she liked it and she said it was nice but that she missed the tabs that IE had. I was amazed… Firefox were years before IE with tabs but still it fails… Look at the screen shot from Firefox 3. Nothing tells you the interface is tabbed.

Firefox fails to show how to open new tabs. Internet Explorer leads the way!
Firefox fails to show how to open new tabs. Internet Explorer leads the way!

Luckily Firefox 3.5 seems to address the issue. Firefox 3.5 also makes it even clearer than Internet Explorer with a + in the new tab button. Way to go Firefox!

Firefox 3.5 introduces new tab button!
Firefox 3.5 introduces new tab button!

Easy way to convert videos using FFmpeg!

Update: I used FFmpeg for some conversions but I just found out Avidemux and it seems promising! Trying it right away!

Every once in a while I get my hands on a video file that I can’t play. Today when I wanted to watch a bouldering movie it failed. Not sure why. Maybe becuase my WLAN wasn’t fast enough to stream the huge HD file?

I looked around and found no nice tools to convert the movies. Either it was some shareware, adware or I just couldn’t find the download link on the ugly web site… I reverted and decided to try to use the command line tool FFmpeg to encode my videos to mpeg and be able to play them. It worked so good I’m amazed!

In Ubuntu FFmpeg is included in the distribution and is easy to install via Synaptic or Apt (sudo apt-get install ffmpeg). In Windows you can use these builds.

To make the conversion I used the following: ffmpeg -i OriginalVideo.mp4 -ab 128k -b 2000k EncodedVideo.mpg

Tip: If you are testing different settings for FFmpeg add -t 60 to encode only the first minute of the video.

FFmpeg is capable of creating videos with different codecs as well, but I didn’t need that currently so that will be a later exercise!

Portable backup solution for Windows

I have been thinking about creating an easy solution to backup some files from different computers to thumb drives. I wanted a solution that was portable (so I could run it from the thumb drive) and easy to configure (maximum update one path to copy from and one to copy to).

I decided to give Robocopy (that I use for complete backups) a try. The portable requirement was solved by copying the file Robocopy.exe from the folder C:WindowsSystem32 (in Windows Vista) to my thumb drive. And the easy to configure requirement was solved by creating a Backup.bat file on the thumb drive with the following content:

SET source="D:Code"
SET destination="./CodeBackup"
SET logfile="./Backuplog.log"

SET copyMode=/MIR /XF desktop.ini
SET options=/R:0 /W:0 /LOG+:%logfile% /NFL /NDL

Robocopy.exe %source% %destination% %copyMode% %options%
pause

It copies the folder Code from my D: drive to the folder CodeBackup in the root folder on the thumb drive.

I popped out the thumb drive and stuck it in a Windows XP computer that didn’t have Robocopy installed. I ran the bat file and it didn’t work. It seems like you need to have different versions of Robocopy for it to run in Vista and XP so I downloaded the Windows Server 2003 Resource Kit which includes a Robocopy version that workes in XP. To be able to run robocopy on both Vista and XP I renamed the files to RobocopyXP32.exe and RobocopyVista32.exe. Then I updated the Backup.bat file to point to the XP version when I’m doing the backups from XP and the Vista version when doing backups from Vista. It seems to work fine and is an easy enough solution!

Write Your Own WXR File to Migrate Custom CMS to WordPress

I have been using a custom build CMS that’s really basic for a tiny site for some years. It has around 200 posts so it’s not a huge site but too much too migrate to a new host by hand. I have been using WordPress for some other sites and I really like it so I decided to look into migrating the data from my current custom CMS to WordPress (and host it on wordpress.com). I also wanted to replace some low resolution images with the same images but in higher quality (if possible automatically).

I decided to try to export all posts on my old site to a RSS file that I then convert to a WordPress WXR file (which is a RSS file with some extra tags). I couldn’t find any specification for the WXR file but it’s really simple so I’ll just write down some notes.

The first part is the XML specification and blog description. It should look something like this

  
http://localhost/~ola/wp
	The Car Numberplate Game
Sat, 27 Sep 2008 16:08:57 +0000
	WordpressImportFileGenerator 0.1
	en
	1.0
	http://platespotting.wordpress.com
	http://platespotting.wordpress.com
	photo< ![CDATA[photo]]>
	plate< ![CDATA[plate]]>
	uncategorized< ![CDATA[Uncategorized]]>
	photo< ![CDATA[photo]]>
	plate< ![CDATA[plate]]>

Then each blog post, page or attachment is wrapped in tags



Screenshot: Softa.nu sand pit
Sat, 16 Aug 2008 21:19:15 +0000 < ![CDATA[admin]]> < ![CDATA[photo]]> < ![CDATA[plate]]> < ![CDATA[photo]]> < ![CDATA[photo]]> < ![CDATA[plate]]> < ![CDATA[plate]]>
Screenshot: Softa.nu sand pit
< ![CDATA[ A house in our neighbourhood caught fire so we went to look and on our way I found 181. Enjoy!]]> 190 2008-08-16 23:19:15 2008-08-16 21:19:15 open open 181 publish 0 0 post location nacka, stockholm googlemapurl http://googlemapuprl.com/testurl
Tody we found a sand-pit
Sun, 21 Sep 2008 16:28:12 +0000 < ![CDATA[admin]]> < ![CDATA[Uncategorized]]> http://localhost/~ola/wp/wp-content/uploads/2008/09/181_080816.jpg < ![CDATA[]]> 191 2008-09-21 18:28:12 2008-09-21 16:28:12 open open 181_080816 inherit 190 0 attachment http://localhost/~ola/wp/wp-content/uploads/2008/09/181_080816.jpg _wp_attached_file /home/ola/public_html/wp/wp-content/uploads/2008/09/181_080816.jpg _wp_attachment_metadata a:6:{s:5:"width";i:2816;s:6:"height";i:2112;s:14:"hwstring_small";s:23:"height='96' width='128'";s:4:"file";s:66:"/home/ola/public_html/wp/wp-content/uploads/2008/09/181_080816.jpg";s:5:"sizes";a:2:{s:9:"thumbnail";a:3:{s:4:"file";s:22:"181_080816-150x150.jpg";s:5:"width";i:150;s:6:"height";i:150;}s:6:"medium";a:3:{s:4:"file";s:22:"181_080816-300x225.jpg";s:5:"width";i:300;s:6:"height";i:225;}}s:10:"image_meta";a:10:{s:8:"aperture";d:2.600000000000000088817841970012523233890533447265625;s:6:"credit";s:0:"";s:6:"camera";s:20:"Canon PowerShot A540";s:7:"caption";s:0:"";s:17:"created_timestamp";i:1218917746;s:9:"copyright";s:0:"";s:12:"focal_length";d:5.79999999999999982236431605997495353221893310546875;s:3:"iso";i:0;s:13:"shutter_speed";d:0.0166666666666666664353702032030923874117434024810791015625;s:5:"title";s:0:"";}}

Along with all item tags comes the the history for each post but since I didn’t have any history in my old CMS so I exclude it.

To create WXR XML from my standard RSS XML I decided to build a quick .NET program (download the source code) that just reads all fields from the RSS file and then converts them to their corresponding fields in WXR. You’ll need to customize the tool but the class WordPressWxrItem.cs might be a good start…

Vista and Incremental backups

I usually use Rsync for my incremental backups but since I moved to Vista it’s a bit of pain to get it working. I tried to install it using both Cygwin and DeltaCopy but couldn’t get it to copy international chars (i.e. åäö) via either Samba or SSH. So I looked into a tool called robocopy which is included in Vista (you can get it for XP as well). It worked fine and was easy to use.

To mirror a folder from one folder to another I put the following to a bat file (all on one row):

robocopy "D:Pictures"
"MyOtherComputerBackupPictures" /MIR

I did some different bat files for all folders I wanted to backup. At last I created one bat file that calls all the other. It looks like:

call BackupPictures.bat
call BackupCode.bat

There are loads of settings to customize your backups. For example to avoid copying desktop.ini files add /XF desktop.ini just after /MIR in the above example. Look into the robocopy help for more configuration options.