Web Dev Blog

Looking for help with WordPress, Apache, Vim, Web Security and more. Here are a few tips.

Tag: ubuntu

WordPress Production and Development with Fiddler Proxy

A common problem with development, staging and production environments for WordPress projects is switching your browser between the environments. Traditionally the way to do this was with hosts file updates that redirect a domain name to the IP address of your development server. WordPress is setup with a specific domain name, so running on a subdomain or a development domain name can introduce problems into the site when you move from development to staging or production. In a perfect world your development and staging environments should be 100% identical to the production environment, that way there aren’t additional testing requirements to verify bugs haven’t been introduced in the migration process. Finally there is a convenient way around this by using a proxy.

The development environment in this situation is using the Roots Sage framework which comes gulp and browserwatch which runs on port 3000 by default, but it would be easy enough to setup a similar environment by running apache or nginx on a non-standard port in your development environment.

Fiddler is a free “web debugging proxy for any browser, system or platform”. It will run in the background and intercept all of the traffic between your browser and the Internet. One of the options it offers is a Host Remapping function (found under Tools>HOSTS). The great thing about the Host Remapping, for our purposes, is you can include port numbers in the remapping.

In this example, the development environment is running on an Ubuntu server on the local network. www.foo.com:3000 is redirected to the local IP address port 3000. When this is enabled, www.foo.com will route to the live production environment and www.foo.com:3000 will route to the dev environment. This allows you access to both environments simultaneously for comparison. WordPress works exactly the same in both environments.

fiddler-host-remapping-wordpress

A big advantage of this is you no longer have to edit your Windows Hosts file every time you want to switch back and forth.

To avoid confusion it might be good to integrate something like WP Local Toolbox which can give you some visual cues as to which server you are accessing without adding additional configuration problems.

Replacing Hard Drive under LVM in Ubuntu

Recently had a hard drive start acting strangely on my development server. It is a 2TB Seagate drive and it started causing errors in the logs, nothing major and it still worked. I put off ordering a new drive, a mistake, I know, but thought maybe it was just some kind of software issue.

Then the machine started getting slow. Really slow. So I ordered a new 3TB Toshiba drive. Finally received it and thought I would use Clonezilla to copy the drive. Created a live USB Linux flash drive with the Clonezilla image. Worked like a champ, but the cloning was going very slowly due to the problem with the drive, so I bailed. After some additional tinkering, and fixing grub because Clonezilla had modified it, I was able to boot back up and I realized that I was using LVM and this creates another problem.

I’m not sure if cloning and replacing the drive would have worked or not, but found some guides on replacing a drive in LVM.

Here is the one I used
http://www.microhowto.info/howto/replace_one_of_the_physical_volumes_in_an_lvm_volume_group.html

Basically you add the new drive to the LVM and then use pmove to migrate the content off the old drive. Honestly, I’m not sure yet how this is going to work, it’s been almost a day and a half and I’m at 45.8%. If it fails I have a backup, but it would be nice if this process works and everything moves.

Remove spaces from filenames on the Ubuntu Linux command line

I’ve been working on sizing a large number of images for a client to go into a WordPress photo gallery. I use a for loop to find all the files and use convert to size them to a good size for viewing on a website. The problem is the convert program doesn’t like file names with spaces in them. It seems like the easiest thing to do is remove the spaces from the file names with a Ubuntu command line script. This is easily accomplished with the rename comannd.

rename 'y/ /_/' *

This script will replace any spaces spaces in the filenames with underscores (_)