Chris Hope's LAMP Blog - The Electric ToolboxChris 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.

How to get to the Library folder in Apple OSX's FinderHow to get to the Library folder in Apple OSX's Finder

Posted April 14th, 2014 in OSX

You'll often come across articles and blog posts telling you to go to the Library folder on Apple's OSX but it's not visible in Finder. So how to get there?


When you click the "Go" menu option in Finder, hold down the Alt/Option key and the Library folder will appear in the list. Click it and Finder will open the Library.

Longer answer with screenshots

When you go to your home folder/directory in Finder, there's no Library listed there. Clicking the "Go" option in the app's menu doesn't show it either:

finder's go menu without the library option

All you need to do to show the library option is hold down the Alt / Option key on your keyboard and the Library option will appear:

finder's go menu with the library option

Now you can select Library and it will open in the currently selected Finder window.

How to always show the Library

If you always want to show the Library in Finder, then open up Terminal (it's found under Applications -> Utilities, or you should be able to bring it up in Spotlight searching for Terminal) and run the following command:

chflags nohidden ~/Library

This will now show the Library folder in Finder, although it still won't show it in that Go menu without holding down the Option key.

To make Library hidden again, do this in Terminal:

chflags hidden ~/Library

What to do if Astrill won't remember the passwordWhat to do if Astrill won't remember the password

Posted April 5th, 2014 in Applications

I use the Astrill VPN application on my Mac for a variety of reasons, and I couldn't work out why it would never remember the password, despite the "remember password" checkbox being checked. Here's the solution.


Don't copy and paste the password. Type it in. Then it will be remembered.

Longer answer

Astrill is VPN software that works on a variety of platforms, including DD-WRT routers, and can be set up to act as a gateway device for other devices such as the PlayStation gaming console from the desktop app for Windows, Mac and Linux.

Here's a screenshot of the desktop app's login screen running on a Mac:

astrill login screen

I've been using Astrill for about 15 months, and at some point early on changed my password. After I changed the password, I'd always have to enter it again whenever I logged in, despite the "remember password" box being checked. What a pain!

Because it's not an easy password to remember, I'd copy and paste it from a text document into the password field and then connect.

So today, I decided to find out why this was the case, and found this useful troubleshooting page on the Astrill wiki.

It turns out that if you copy and paste the password, it won't be remembered. If you type it in, then it will. So I typed the password in and, hey presto, Astrill now remembers the password. Hooray!

Wifi drops when plugging in MiniPort-DVI Monitor to MacBookPro Thunderbolt portWifi drops when plugging in MiniPort-DVI Monitor to MacBookPro Thunderbolt port

Posted April 4th, 2014 in OSX

We've just bought a new MacBookPro Retina 13" Late 2013 and when plugging in an external monitor to the thunderbolt port using a 3rd party mini display port to DVI adapter, the wifi drops away and the internet becomes more or less inaccessible.


Change the router's wifi channel to the lowest possible number, such as 1.


The problem with a little more detail

I was wondering why the internet was running so slowly, so tried to bring up the speedtest website. I figured perhaps there was an issue with the Wifi where the laptop was sitting, so unplugged all the cables to move it, and miraculously speeds returned.

As soon the monitor was plugged in, speeds would drop to nothing. As soon as it was unplugged, speeds would go back to normal. Trying a different monitor with a VGA adapter worked fine. Going back to the same monitor with DVI caused issues.

(I can't remember now if I tried VGA on the troublesome monitor or not, but guess now it must have had issues because I continued to use the different monitor.)

The solution with a little more detail

I found this thread at the Apple Support Communities where a lot of people were talking about issues with wifi and changing the channel to a lower number solved the problem. They also suggested using the 5 GHz channel, but my router doesn't support this.

This seemed a fairly unlikely solution to me, but I decided to try it anyway. The channel the router had been set to was 6, so I manually dropped it to 1. And it solved the issue; speedtests were now back to the normal levels with the monitor that had been having issues.

This is a weird problem with a weird solution. I hope it works for you too.

How to add access to webmaster tools in Google AppsHow to add access to webmaster tools in Google Apps

Posted March 20th, 2014 in Applications

I was attempting to activate a new domain alias in Google Apps only to be told "We are sorry, but you do not have access to Webmaster tool. Please log in to your Control Panel to enable Webmaster tool." It wasn't obviously clear how to do this, so this post shows the steps you need to do to enable webmaster tools should you have this error.

A note on the date

Please note, the screenshots below were taken on March 20th 2014 and the process for enabling the webmaster tools in Google Apps is accurate as of this date. However, user interfaces are always subject to change, so this may not be accurate in the future.

The step by step solution with screenshots

The error message makes it fairly clear what you need to do, but when you click back to the control panel / dashboard, there's nothing obvious to enable because there's no webmaster tools icon.

the error message

Go back to the dashboard and locate the icon that is labelled "Other Google Services". If it is not there with the other list of icons (e.g. Users, Company Profile & Billing in the screenshot below), click the "More Controls" option to find it.

selecting more controls

Now click "Other Google Services":

selecting other google services

Initially the list of other services is filtered to "top featured services", which does not include webmaster tools as an option. Click the X button to the right of the filter as highligted in the screennshot below.

removing the filter for top featured services

Now scroll down, check the box next to "Google Webmaster Tools" and then click the power button at the top of the list.

selecting google webmaster tools

You'll get a warning about turning it on for everyone; if you are happy to do this then click the "Turn ON for everyone" button. I'm not sure how you can enable it for only some users, but there's probably other options somewhere :)

turn on for everyone

Although it says the changes may take up to 24 hours to propagate for all users, the change worked immediately for the user I was logged in as, and I was able to continue with the domain verfication process for adding an email domain alias.

How to show the call log on a Sony Xperia Acro SHow to show the call log on a Sony Xperia Acro S

Posted March 18th, 2014 in Hardware & Gadgets

I have a Sony Xperia Acro S and couldn't work out how to view the call log to see the phone numbers of inbound and outbound calls. The online documentation didn't shed much light on it, saying to click the phone icon and the call log will be there, but it wasn't. Note that this tip probably works for most other Android phones too.

Instructions from the documentation

The online documentation can be found here. It says from your Home screen, tap the apps button (shown below) and then find and tap Phone. The call log view appears on the upper part of the screen.

xperia acros s apps buttonThe apps button

You've probably got the phone button on the apps bar at the bottom of all screens, or else on the home screen, so shouldn't have to dig your way through all the apps to find it :)

But where is the call log?

I don't know if it's something I'd managed to toggle off myself or if it's the default setting, but the call log wasn't showing for me.*

If the call log isn't showing, then all you need to do is touch the right button (which is highlighted in the photo below with the red arrow and circle) and then touch the "Show call log" item in the little popup menu that displays.

Once the call log is showing, touching the button again gives the options to "Hide call log" and "Clear call log". You can toggle between them at any time.

xperia acro s right button

* Footnote about randomly changing settings

I am a long distance runner and take my phone with me when I run. Until recently, I didn't have a screen lock set on my phone and would often find settings had changed, photos or videos were taken, and so on.

So it's quite possible that I'd unintentionally managed to switch off the call log from showing while out on a run one day! I've since added a screen lock, but still have to be careful because there doesn't appear to be any way to disable the emergency calls option...

Password protection with Apache but allow from a user agentPassword protection with Apache but allow from a user agent

Posted February 20th, 2014 in Apache

This post shows how to password protect a website with an Apache .htaccess file, but still allow access for a particular user-agent.


Allowing a process or browser access by their user-agent isn't really the most ideal solution: it's far better to allow access by IP address, but sometimes it's necessary if the IP address of the remote process/browser may change but the user-agent will remain the same.

Ideally this method shouldn't be used for something requiring high levels of security, but it can be useful if you need to, like I do, allow access to a payment provider's callback to let your website know the payment has succesfully been processed.


Add this to your .htaccess file, see below for what you need to substitute:

SetEnvIfNoCase User-Agent [UserAgentName] AllowedUserAgent
AuthUserFile /path/to/.htpasswd
AuthName "Restricted Access"
AuthType Basic
Order deny,allow
Deny from all
Require user [username]
Allow from env=AllowedUserAgent
Satisfy Any

Change [UserAgentName] to the name of the user agent. You can use pattern matching, so .*google.* would match a user agent with "google" anywhere in it.

Change /path/to/.htpasswd to the actual location of your password file.

Change [username] to the username(s) you want to allow access.

Real world example

I needed to test PxPay by Direct Payment Solutions (DPS), which uses what they call "fail-proof result notification (FPRN)". They specifically note that there should not be any conditional logic based on the originating IP address when the payment notification is made.

I can't really make any assumptions about the user-agent, but it always came through as PXL1 when I tested it, so this is what my .htaccess file looked like:

SetEnvIfNoCase User-Agent PXL1 DPS
AuthUserFile /path/to/.htpasswd
AuthName "Restricted Access"
AuthType Basic
Order deny,allow
Deny from all
Require user [username]
Allow from env=DPS
Satisfy Any

I have a number of other recipes and tips for password, IP address, etc protection with .htaccess in my Apache .htaccess recipes, tips and tricks post, so be sure to check them out.

Scroll Lock Key on a MacScroll Lock Key on a Mac

Posted February 14th, 2014 in OSX

I am the king of random shortcuts and always seem to hit keys when typing that have unexpected consequences, such as this morning when I was doing something in Excel and managed to trigger scroll lock. But there's no scroll lock on a Mac keyboard...

Excel and Scroll Lock

When scroll lock is on and you use the arrow keys to navigate around a spreadsheet in Excel, it scrolls the sheet instead of moves the active selection to another cell.

This can be annoying when you were in the middle of navigating around the spreadsheet with arrow keys and then suddenly the sheet starts moving instead. The problem is scroll lock is on, and you need to switch it off again.

Scroll Lock on a Mac Extended Keyboard

A PC keyboard has a scroll lock key, but a Mac one doesn't appear to. If you are using an Apple Extended Keyboard it does, and the super secret scroll lock key is... F14

I personally have the "Use all F1, F2, etc. keys as standard function keys" enabled in the system preferences, but found whether this was switched on or off that F14 on its own or FN+F14 would switch scroll lock on and off (on OSX Mavericks).

Scroll Lock on a MacBook Pro / MacBook Air / Wireless Keyboard

I don't have an answer for this one, because the keyboard only has function keys from 1 to 12. I've done a fair amount of Googling for a solution but none of the shortcuts people have suggested work.

Given there doesn't seem to be a scroll lock equivalent on these smaller keyboards, you're unlikely to be able to trigger scroll lock anyway, so hopefully don't have my random shortcut issue!

Mac mail queue commandsMac mail queue commands

Posted February 13th, 2014 in OSX

This post is a quick reference for some of the mail server commands for Apple Mac OSX: how to show the queue, flush it, delete everything, delete a particular message, etc.

View the log file

The log file is at /var/log/mail.log, so to view what's going on at the present time use "tail -f" as shown below. This monitors the file, and when new lines are added they'll be displayed as output in your terminal.

tail -f /var/log/mail.log

You'll see stuff like this:

Feb 13 13:13:27 MacBookPro.local postfix/master[46899]: daemon started -- version 2.9.4, configuration /etc/postfix
Feb 13 13:13:27 MacBookPro.local postfix/pickup[46900]: E0B382327BBF: uid=501 from=<chris>
Feb 13 13:13:27 MacBookPro.local postfix/cleanup[46902]: E0B382327BBF: message-id=<20140213001327.E0B382327BBF@MacBookPro.local>
Feb 13 13:13:27 MacBookPro.local postfix/qmgr[46901]: E0B382327BBF: from=<chris@MacBookPro.local>, size=3951, nrcpt=1 (queue active)
Feb 13 13:13:33 MacBookPro.local postfix/smtp[46904]: E0B382327BBF: to=<>,[]:25, delay=6.2, delays=0.53/0.03/2.9/2.7, dsn=2.0.0, status=sent (250 2.0.0 OK 1392250413 xk2si24186201pab.303 - gsmtp)
Feb 13 13:13:33 MacBookPro.local postfix/qmgr[46901]: E0B382327BBF: removed
Feb 13 13:14:27 MacBookPro.local postfix/master[46899]: master exit time has arrived

View the mail queue

To check what's currently in the mail queue, do this:

sudo mailq

And you'll see what's queued:

-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
57951232838B*    3977 Thu Feb 13 00:24:51  chris@MacBookPro.local
-- 4 Kbytes in 1 Request.

Flush the mail queue

If you want to flush the mail queue to attempt sending the messages again, do this:

sudo postfix flush

Delete a single message from the mail queue

You can delete a single message from the mail queue by noting its id when viewing the queue. In the example above, the id is 57951232838B. Delete this message like so:

sudo postsuper -v -d 57951232838C

When the message is deleted, you'll see this:

postsuper: Deleted: 1 message

If no messages are deleted, then nothing is output.

Note that if the mail server can't currently connect to the internet to deliver mail (for example your ISP has port 25 firewalled) you'll see messages like "postqueue: warning: Mail system is down -- accessing queue directly" in the log file and when you run mailq.

I've found when getting this paricular message that it's not possible to delete a single message by ID. Perhaps there's another way to do this, but I haven't found one yet, other than to delete all the messages from the queue, as shown next.

Delete all messages from the mail queue

To delete all messages from the mail queue, do this:

sudo postsuper -d ALL

If there's mail in the queue which was deleted, you'll see something like this:

postsuper: Deleted: 1 message

And if there was no mail currently queued, there will be no output from the command.

PHP upload_max_filesize and nginxPHP upload_max_filesize and nginx

Posted February 12th, 2014 in Nginx Web Server and PHP

I've recently set up a new server with PHP & Nginx using packages from dotdeb. The default upload_max_filesize and post_max_size for this setup with php-fpm is 2M. To adjust it, the Nginx config also needs a configuration change, otherwise you're still stuck with a smaller limit.

PHP config

On my install the PHP config file is at /etc/php5/fpm/php.ini but it may be somewhere else for you, depending on the distro and packages used.

Find and edit the post_max_size and upload_max_filesize options to suit, noting that post_max_size should be equal to or greater than upload_max_filesize. In my case, I set them both to 10MB like so:

post_max_size = 10M
upload_max_filesize = 10M

You'll then need to restart/reload the PHP process that's running. In my case this is php-fpm on Debian so you'd do it like this:

sudo service php5-fpm

Nginx config

By default, Nginx only allows 1MB to be sent as part of the request, so event the PHP default of 2MB is too big (never mind the 10MB I've just upped it to) and it will fail to allow this to upload. You'll see something like this in the Nginx error log:

2014/02/11 13:44:10 [error] 7523#0: *1750090 client intended to send too large body: 2075258 bytes, client:, server:, request: "POST /admin/files/upload/8458 HTTP/1.1", host: "", referrer: ""

Edit the main nginx.conf file (/etc/nginx/nginx.conf on the Debian install) and add this to the http { } section, setting the amount to the same (or greater) than that set in the PHP config:

client_max_body_size 10m;

Now reload Nginx so the new setting takes effect, on a Debian install, like this:

sudo service nginx reload

Note that you don't have to set it to 10MB as I have in this post; set it to an approriate value for you.

Facebook screws over pages, yet againFacebook screws over pages, yet again

Posted January 22nd, 2014 in Miscellaneous Postings

Facebook has for some time now been attempting to monetize posts from "Pages" and generally prevents too much Page content appearing in users' feeds, unless the Page is prepared to pay to boost their posts. In yet another news feed algorithm change, they've made it even harder for Pages to reach their users.

Facebook Press Release

Here's the Facebook press release about this update. Here's a particularly interesting snippet:

"the latest update to News Feed ranking treats text status updates from Pages as a different category to text status updates from friends. We are learning that posts from Pages behave differently to posts from friends and we are working to improve our ranking algorithms so that we do a better job of differentiating between the two types. This will help us show people more content they want to see. Page admins can expect a decrease in the distribution of their text status updates, but they may see some increases in engagement and distribution for other story types."

My opinion

Utter bullshit.

Facebook want Page owners to pay to reach their audience, while pretending that they can reach them without having to pay. I'm not quite sure why they feel the need for so much double-speak; why don't they just come out and tell Page admins they expect them to pay?!

If Facebook really did have the users' interests at heart, they'd let us see all posts from all pages in our news feeds. If we decide we no longer want to see a particular Page's posts, then we'd simply unlike them. Why else do we follow Pages, if not to get information and updates from them?

As an example, I really enjoy reading the Off The Leash comic, but Facebook is the only means for reading it. It used to appear in my news feed and now never does, so I have to remember to periodically go to the Page to read the last few days of posts.

But it all comes down to money. A friend said this on Facebook today:

"The root of the problem was the IPO. The company was valued at such an enormous number, despite having never produced revenues in line with that. Now their focus is on investors rather than users, they're constantly trying to find ways to increase revenue and this seems to only ever come at the expense of user experience."

As an owner of a couple of pages myself (for my New Zealand & Australian running websites) I have found it increasingly hard to reach my audience on Facebook. I found a loophole recently where writing a post with no links, but putting the link as a comment to the post, reached about half of my audience compared with a tenth when linking directly from the post, but they've plugged that now with this latest update.

Looking at it from their perspective, I will never spend money on Facebook marketing, so FB has no reason to care about me. But it still peeves me off, because I can't read stuff from Pages without having to visit all the individual pages all the time. Instead I keep seeing the same posts from friends appear at the top of my news feed because someone happend to comment on it a couple of weeks later...