Chris Hope's LAMP Blog - The Electric Toolbox
Linux Apache MySQL and PHP articles by Chris Hope
This is Chris Hope's blog for Linux, Apache, MySQL and PHP (known as LAMP) and Javascript/jQuery. I started this website several years ago with articles about web programming, Linux and Windows tips and tricks, howtos etc.
The ten most recent articles can be found below in their entirety. Navigating the sections in the right navigation (under Categories) will bring up all the other posts, and you can also use the search box at the top of the page to find what you might be looking for.
Remove a saved password with Google Chrome
Posted February 25th, 2013 in Applications (Updated February 25th, 2013)
If you have saved a password for a website in Google's Chrome you can easily enough remove that password (or all saved passwords) if you no longer want it saved on your computer. This post shows how to do this with easy to follow screenshots.
Post history
This post has been fully re-written with new screenshots due to interface changes made with Google Chrome since my original post was written on 17 Jan 2010. This post is accurate as of Chrome version 25 on 25 Feb 2013.
How to remove a saved password in Google Chrome
Click the triple bar icon which appears to the right of the address bar as shown by the first red arrow in the screenshot below; this is similar to the icon that appears in mobile apps. Then select the "Settings" menu option which is highlighted with the second red arrow.
Note that on a Mac you can also get to the settings via Chrome menu -> Preferences or Cmd+,

The preferences will open in a new tab. Scroll down to the bottom and click the link labelled "Show Advanced Settings". Scroll down and locate the "Passwords and Forms" section and click the "Manage saved passwords" link as shown in the screenshot below.

This will open a little popup window containing a list of saved passwords as shown in the final screenshot below. It will be blank at first and may take a little while to load, so be patient. Note that I have blacked out the website address for my own saved passwords. Normally you would see a website address where the black lines are.

To remove a single password, mouse over the one you want to remove and then click the X button that will appear next to it. This is shown in the above example where the first password has a grey background and the password is in a box with "Show" and "X" buttons. It may take a few seconds for the password to delete from the list, so again be patient.
You can also search for a password on a specific website using the "Search passwords" text box.
View a saved password
Finally, if you would like to see what the saved password is, click the row of the one you would like to see and click the "Show" button that will appear. This will show the password and the title on the button will change to "Hide" which you can use again to hide the password.
Clear all passwords at once
There no longer appears to be a way to clear all saved passwords in one go from this dialog, but it can be done by closing this dialog, clcking the "Clear browsing data" button in the "Privacy" section, making sure only "Clear saved passwords" is checked and then clicking the "Clear browsing data" button.
I will follow this post up with another one showing how to do this with screenshots later this week.
RewriteRule redirect without the query string
Posted February 22nd, 2013 in Apache
When redirecting all requests from one domain name to another one when the URL structure has changed, you'll ideally want to craft redirects from the old scheme to the new one. Sometimes this is too complex or messy, and it's easiest to just redirect everything to the new domain's homepage. If they have query strings at the end of the URL then Apache's RedirectMatch and RewriteRule with automatically include the query string in the redirect location. This post shows how to solve this.
The problem
We wanted all requests from old.example.com to go to new.example.com. This can be achieved easily like this in Apache:
<virtualhost *:80>
ServerName old.example.com
RedirectMatch permanent (.*) http://new.example.com/
</virtualhost>
or like this with a rewrite rule:
<virtualhost *:80>
ServerName old.example.com
RewriteEngine On
RewriteRule .* http://new.example.com/ [R=301]
</virtualhost>
The only problem was that the old domain we were redirecting from had stuff like this (this is a nice example, there were some pretty nasty URLs on the old website):
http://old.example.com/afa.asp?idWebPage=50549
Using either of the above examples, this will redirect to:
http://new.example.com/?idWebPage=50549
While this may not cause any issues with the new domain/website, it's not really ideal. We don't want the ?idWebPage=50549 bit at the end.
The solution
The solution is rediculously easy. Simply add the ? after the rewrite rule target like so:
<virtualhost *:80>
ServerName old.example.com
RewriteEngine On
RewriteRule .* http://new.example.com/? [R=301]
</virtualhost>
http://old.example.com/afa.asp?idWebPage=50549 will now do a permanent redirect to http://new.example.com/ but it won't put ?idWebPage=50549 at the end, nor will it put ? at the end.
How to clear the DNS cache on Mac OSX
Posted February 19th, 2013 in OSX
DNS lookups are cached so that subsequent lookups for the same host don't require querying an external DNS server again until the TTL expires. Sometimes you need to clear the cache, for example if you've changed a DNS record, and this post shows how to do it on Mac OSX.
Clear the cache using Terminal
The following command works from Max OSX 10.5 Leopard and above (at the time of writing this post it works on the 10.8 Mountain Lion which is the current version) to flush the DNS cache.
Open up Terminal, which is under Applications -> Utilities (or use Spotlight or other lauching apps to start it) and enter the following command:
dscacheutil -flushcache
You won't get any feedback from the command; just another command line directly afterwards
Note that this will clear the dns cache of your computer only; any records currently in the DNS server you are using will remain. For example, if your router has a caching DNS server then it won't be flushed and will still retain records until the TTL expires.
It also won't flush the cache of your browser (if it has one) and may require a browser restart.
Edit or disable the customer registration email in Lemonstand
Posted February 12th, 2013 in LemonStand
When a customer registers their details on a Lemonstand ecommerce website, an email is sent to confirm the registration using the shop:registration_confirmation template. This post shows where to go to edit the email message or prevent it from being sent.
Editing the shop:registration_confirmation template
In the Lemonstand admin area, click "Email Templates" under "System > Settings".
This page shows you a list of email templates used by the system and you can edit any of them from here, modifying the subject, message body and the email address it's sent from.
To edit the shop:registration_confirmation template simply click it, make your changes and then click the "Save" button under the form. You can send a test message to yourself to see what it looks like before saving it if you wish.
There are a bunch of placeholders that can go in the email and these are shown in the right column sidebar next to the edit form.
Here's a screenshot of this form:

Disabling the shop:registration_confirmation template
There doesn't appear to be a way of disabling the email from being sent, other than to delete the template. I did search on the Lemonstand codebase for shop:registration_confirmation and found this section of code in the modules/shop/models/shop_customer.php file:
public function send_registration_confirmation()
{
$template = System_EmailTemplate::create()->find_by_code('shop:registration_confirmation');
if ($template)
{
$message = $this->set_customer_email_vars($template->content);
$template->send_to_customer($this, $message);
}
}
What it's doing is to query the database for the template. If the template exists, then it sends the email; if it doesn't, then it doesn't do anything.
So to disable the registration confirmation email in Lemonstand, delete the email template. Unfortunately you can't simply click the delete button on the edit form, because the system will not let you delete it and will show this error message: "This template is used by the Shop module".
To delete the template, run the following SQL query:
DELETE FROM system_email_templates WHERE code = "shop:registration_confirmation"
If you do decide to delete this template, it would pay to keep a copy of the content of the email in case you want to restore it at some later time. The following SQL query can be run to restore the email to its default setting in case you have deleted it and need to restore it:
INSERT INTO `system_email_templates` (`code`, `subject`, `content`, `description`, `is_system`, `reply_to_mode`, `reply_to_address`) VALUES
('shop:registration_confirmation', 'Confirmation', '<p>Dear {customer_name}!</p>\n<p>Thank you for registering. Please use the following email and password to login:<br /> email: {customer_email}<br /> password: {customer_password}</p>', 'This message is sent to a customer after successful registration.', NULL, 'default', NULL);
New Zealand Government websites to switch to Silverstripe
Posted February 8th, 2013 in SilverStripe
New Zealand Government websites will switch to Silverstripe, the free, open-source CMS/framework from Wellington company Silverstripe under an "all-of-government" contract.
Common Web Platform / Platform as a Service
Silverstripe have been selected by the Department of Internal Affairs to build the Common Web Platform for the New Zealand public sector.
To do this, they will build a Platform as a Service version of SilverStripe CMS targeted specifically at the needs of the New Zealand public sector.
Over time, this will replace the almost 50 different CMS systems various government departments and agencies use.
Further reading
"Huge coup for local software firm" news article at stuff.co.nz
"Common Web Platform" blog post at silverstripe.com
"Wellington co. wins contract for single government web platform" news article at nbr.co.nz
"Ask me anything: Sam Minnée", a question and answer session at nbr.co.nz with the Silverstripe CEO.
Hide the Spotlight Menu Icon in Mac OS X
Posted February 5th, 2013 in OSX
In the past I've looked at how to disable Spotlight indexing on Mac OSX, but that still leaves the (now unnecessary) Spotlight icon in the menu icon area. This post shows how to hide the Spotlight icon from the menu area on Mac OSX.
Hide the Spotlight icon
The nice thing is that hiding the icon doesn't stop Spotlight from working so you can use this technique to reduce menu bar clutter. If you have disabled Spotlight then it means you can remove this now uncessary icon.
Open up Terminal (it's under Applications -> Utilities -> Terminal) and run the following command:
sudo chmod 600 /System/Library/CoreServices/Search.bundle/Contents/MacOS/Search
You will be prompted for your password; this is the same as the password you use to log into your Mac. Note that you do need to be an administator of your Mac to be able to do this. If you aren't, then it won't work.
Now run this command to refresh the menu bar:
killall SystemUIServer
The icon will now be gone.
Show the Spotlight icon
Should you need to restore the icon, run the following commands in Terminal:
sudo chmod 755 /System/Library/CoreServices/Search.bundle/Contents/MacOS/Search killall SystemUIServer
Now the icon will be back again.
How to switch off app auto-updates in Google Play Store
Posted February 1st, 2013 in Applications
Auto-updates from Google's Play Store can be a quick way to fill up internal phone storage on an Android phone when you don't have much. This post looks at an issue I had with an older phone with little internal storage and how to disable auto-updates in the Play Store.
Background story
I have an Android Phone that's a couple of years old, running Android 2.2.1. It has very little internal memory so storage space is at a premium* and I don't want it to update apps that a) I don't use and b) can only be stored in the internal phone storage.
(* Yes, I have a decent sized SD card on board, but the factory installed apps won't let me move them off the phone memory onto the SD card).
The other day, I reinstalled an app that I use every day (it was misbehaving and the uninstall and reinstall seemed to fix it) and ticked the box to allow automatic updating in Google's Play Store. I thought this meant it would only automatically update this particular app, but apparently it meant that all apps would auto update.
This morning my phone decided to update all of its apps which, as you can guess, meant my phone ran out of internal storage. I don't use most of the factory installed apps and there doesn't seem to be any way to remove them, but it's possible to uninstall updates made to them to free up some space. The only catch is they'd auto update again in the future.
How to switch off app auto-updates
1. Start up Google's Play Store
2. Hit the menu button
3. Select Settings
4. Uncheck the auto-update apps option
Done!
Clear a 301 redirect from Google Chrome
Posted December 27th, 2012 in Applications
Google Chrome caches 301 redirects for a long time. When typing in a URL that you've previously visited that had a 301 redirect on it, it takes you to the redirected location without checking the server again. This could be argued as expected behavior, because it is a permanent redirection after all, but this post shows how you can remove a specific URL from the 301 cache in Chrome.
The reason for doing this
When doing development on a website you can often cock up configuration settings etc (especially with htaccess RewriteRules) which might cause a 301 redirect that you don't really want. This happened to me today and I ended up not being able to get back to the original URL because Chrome kept showing me the redirected location.
I didn't want to clear my entire browsing history, so tried to remove individual URLs from the browser history, and also clearing the browser's history for the last hour, but neither of those worked, and nor did restarting the browser. So I did the following trick instead...
Remove a single 301 redirect in Google Chrome
The redirect cock-up in the configuration was making requests from the homepage at e.g. http://example.com/ go to http://example.com/?q=/&q=/&q=/&q=/&q=/&q=/&q=/&q=/&q=/&q=/&q=/&q=/&q=/&q=/&q=/&q=/&q=/&q=/&q=/&q=/
After fixing your configuration (if you've had a similar issue to mine), view the source of the page you actually want with this url (again using the example.com homepage as the example):
view-source:example.com/
Don't hit enter after typing in the URL. Use Cmd+R on a Mac or Ctrl+F5 on Windows (F5 on its own may also work on Windows, and possibly Ctrl+R - I don't normally use Windows to know).
This will load the source of the page into the browser and clear out that 301, so when you view it normally with the view-source part it should all work OK without the redirect. It might take a couple of goes (it did for me when I tried to replicate the error when writing this post).
SQL Server Express 2008 did not install successfully
Posted December 18th, 2012 in Microsoft SQL Server
While attempting to install Visual Web Developer Express 2010 SP1 on Windows 2003 Server I got the error message "SQL Server Express 2008 R2 - This product did not install successfully."
How to check the installation error
I don't actually need SQL Sever Express for the work I needed to do, so it was a little annoying that it had to be installed anyway, but there was no obvious reason it had failed, and the rest of the software wouldn't install without it.
After the second (failed) attempt to install Visual Web Developer Express, I paid a little more attention to the results screen and saw that there's a link to the error log for each failed item.
Click the error log link, and it will open in Notepad, which should shed some light on the error.
Not a strong enough password...
In my case, the installation error was because the "sa" user password I had entered earlier on in the installation process wasn't strong enough...
You would think that instead of downloading and then failing to install the software, it could have prompted me for a stronger password instead of accepting it and attempting to continue. Or just let me have my weak password :)
This may not be the reason for your error; if it is then good; if not, make sure you check the error log to see if it sheds any light on the reason for an unsuccessful installation.
Master Mobile Web Apps with jQuery Mobile 3rd Edition
Posted November 19th, 2012 in Javascript
My friends over at elated.com have recently released the 3rd edition of their "Master Mobile Web Apps with jQuery Mobile" e-book. I had a brief read of one of the earlier editions and it's a great book and I'll be using it as a reference at some point in the future. In the meantime, here's some info about the book and where to buy it from.
Master Mobile Web Apps with jQuery Mobile
We're delighted to announce that the third edition of our eBook, "Master Mobile Web Apps with jQuery Mobile", is now out!
The third edition is fully updated for jQuery Mobile 1.1 and 1.2, including all the data attribute changes, API changes and other improvements to the framework since 1.0. Some of the great new features covered in the book include:
- Vastly improved toolbars and transitions
- A brand new popup widget
- Mini form elements
- A new, more customizable loading spinner
- Slider and listview improvements, and
- An improved ThemeRoller tool.
We've also updated the CityChums app in Chapter 13 for PhoneGap 2.1, Xcode 4.5 and the new 4-inch Retina display on the iPhone 5, and we've tweaked it so it runs more smoothly.
If you've yet to indulge your secret passion to learn about mobile web development, you can buy your copy now at: http://store.elated.com/
Inside, you'll learn how to:
- Get up and running quickly with the jQuery Mobile framework
- Build pages, buttons, toolbars, dialogs, popups, forms and interactive list views - using nothing but HTML
- Theme your apps to give them a unique look and feel
- Integrate your own JavaScript code with the jQuery Mobile API
- Create a fully-functioning, multi-user task manager app using jQuery Mobile, PHP and MySQL
- Use jQuery Mobile with PhoneGap to build native apps.
Reviews and Praise
The third edition is already getting some great reviews, such as this one from Doron Katz:
http://doronkatz.com/review-of-master-mobile-web-apps-with-jquery-mobile-matt-doyle/
Other praise for "Master Mobile Web Apps with jQuery Mobile":
"A very detailed, well-written eBook."
-- Todd Parker, jQuery Mobile Project Lead
"Matt has written an amazing book that can quickly bring any developer up to speed with jQuery Mobile."
-- Darren Clark, Technical Director at Webling Interactive
"This book is a great technical resource... I highly recommend it if you're looking for an in-depth look at the ins and outs of jQuery Mobile."
-- Jonathon Christopher, Monday by Noon
This ebook's a real winner and just $19. Grab your copy today at: http://store.elated.com/
