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.

WordPress media files failing to upload with "HTTP error" message

Posted October 5th, 2015 in WordPress

If the maximum post/file size limits aren't set high enough for your PHP & webserver, you might get an "HTTP error" message when attempting to upload large files. This post looks at how to solve the problem, if you have access to the server's settings.

The problem

The problem occurs when you upload a large media file in WordPress using the default drag n drop / select files selector. The files appear to upload nice and fine, but after getting to 100% it doesn't "crunch" the media files and then show the edit link, and you get an "HTTP error" message under the "Upload New Media" heading.

Unfortunately the error message doesn't tell you what the problem is.

If you use the "browser uploader" instead, you should see the actual server error message. You should also be able to see the error message in the server logs, assuming you have access to them.

If the server error is "413 Request Entity Too Large", it means either PHP hasn't been set up to allow large enough files and/or the web server itself won't allow large enough client requests.

The solution for 413 Request Entity Too Large

In the PHP configuration, you need to make sure the following have large enough values, e.g. 10MB in all following examples:

post_max_size = 10M upload_max_filesize = 10M

And in your Nginx config that the following is the same value:

client_max_body_size 10m;

or Apache:

LimitRequestBody 10485760 # 10MB

If your website is not on a server you can manage yourself, you'll need to ask your hosting provider to implement the settings for you.

Other problems & solutions

There may be other reasons for the upload failing, but this post specifically looks at the 413 Request Entity Too Large issue. By using the "browser uploader" instead, you should hopefully get an error message which tells you the actual error, so you can diagnose and fix it.

Menu items disappear when saving in WordPress

Posted September 16th, 2015 in WordPress

We recently moved a large WordPress website from one server to another. It has a reasonable size menu and we never had any problems saving it on the old server, but the first time we tried to update the menu on the new server, a large number of the items disappeared and the menu stopped showing on the website.


You need to increase PHP's max_input_vars setting from its default to something bigger. If you do not control the server your website is on, speak to your hosting provider.

Longer answer

The form in the WordPress CMS that is used to set up the menu contains hundreds / thousands of input items. By default, the PHP configuration only allows 1000 input variables to be passed from into the script, so any beyond that are ignored.

This means any form elements beyond the 1000 limit will be silently ignored, and any menu items beyond it will get lost, and the "theme locations" checkboxes at the very bottom of the menu editor will also be ignored, making the menu effectively disappear from the website frontend.

Fortunately in my case I'd experienced something very similar with forms in Magento so had a pretty good idea what the problem was. I asked the server managers to increase PHP's max_input_vars setting from the default 1000 to 10,000 and it fixed the problem.

As noted in the tl;dr section above, if you don't manage your server yourself or are using shared hosting, then you'll need to ask the providers if they can change this setting.

How many menu items?

When I did some research in this issue, I saw some calculations that people had done that seemed to suggest you could have up to 100 menu items before it became an issue, but for us it was 48, so I think a lot of it may come down to the WP version and your own site's configuration / set up.

Why wasn't it an issue on the previous server?

It wasn't an issue for me on the previous server, because it was one I managed myself and already had a much higher max_input_vars setting than the default, due to the same issue with Magento.

WordPress version

The WordPress version we were using was 4.2. This is likely to be an issue in all WordPress versions, but hopefully some day in the future, they'll make it that you can't accidentally nuke your menu by replacing it with only the data passed from the form.

Suppress the "skipping the data of table mysql.event" message

Posted September 12th, 2015 in MySql (Updated September 13th, 2015)

When using the mysqldump command to make a back of the mysql database, you might get the message "Warning: Skipping the data of table mysql.event. Specify the --events option explicitly". This post shows how to suppress this message.

How to suppress the message

How to suppress it is given in the message: simply add --events to the command. If you were doing this, for example:

mysqldump -u root -p mysql > mysql.sql

simply add --events like this:

mysqldump --events -u root -p mysql > mysql.sql

Easy! This is useful if you are doing automated backups and do want to see error messages, but not this particular one every time a backup is done.

Other databases

Note that when using the same command & flag on other databases, you'll see this output for each database you dump:

-- Dumping events for database '[database]'

So if the other databases do not have events, and you want to prevent this output from being displayed, then don't use the --events flag for those dumps.

How to get rid of Adobe Photoshop CC 2015's welcome screen

Posted August 26th, 2015 in Applications

Adobe Photoshop CC 2015 has a really annoying welcome screen that pops up every time you start it up and takes ages to load the content, but it's not obvious how to make it not show again if you're on a Mac.

So how to get rid of it?

Because I'm on a Mac with a trackpad and with the default scrollbar preferences (which is to not show the scrollbar until you start multi finger scrolling) it's not obvious that you can scroll the welcome screen.

So mouse over, scroll down to the end and you'll find an option labelled "Don't Show Welcome Screen Again". Check that and it shouldn't come back again.

See the screenshot below, which has the welcome screen scrolled all the way to the bottom:

adobe photoshop cc 2015 welcome screen

And yes, you can get it back again if you really want by going to Help -> Welcome. Just remember you need to re-tick that box again if you don't want it back again.

Show the headers only for a request with cURL

Posted August 24th, 2015 in Linux/Unix/BSD

cURL is an extremely useful command line tool for making HTTP requests and can be used for diagnosing errors, downloading content and so. But what if you just want to see the response headers to see, for example, if a page is doing the right sort of redirect?


To do a HEAD request and show the headers:

curl -I [url]

To do a GET request and show the headers only:

curl -sD - -o /dev/null

Using the -v verbose flag:

curl -s -v -o /dev/null

Using the -I or --head arguments to do a HEAD request

The simplest solution is to use -I (capital i) or --head to do a HEAD request like so:

$ curl -I
HTTP/1.1 200 OK
Server: nginx/1.6.3
Date: Sun, 23 Aug 2015 21:31:49 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
$ curl -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.3
Date: Sun, 23 Aug 2015 21:31:53 GMT
Content-Type: text/html
Content-Length: 184
Connection: keep-alive

The first example is for a page that returns content with a 200 HTTP response code, and the second a 301 redirect and the location to redirect to.

How to get the headers for a regular GET request

Th -I flag is useful, but sometimes web pages return a different response depending if you make a regular GET request compared with a HEAD request.

Calling curl with the URL on its own will dump the HTML to the command line (curl and calling it with the -o flag allows you to dump the HTML to a file instead (curl -o /tmp/index.html

Using the -D or --dump-header will dump the headers to a file, but you can pass - as the filename to dump them to the comment line. You can then use -o /dev/null to not show the HTML, or alternatively an actual filename to save the HTML to if you want.

And finally, when dumping the HTML to a file, curl shows a progress bar, which can be supressed with the -s flag.

Putting this all together, this command will show the headers only: 

curl -s -D - -o /dev/null

And you can combine the -s & -D flags together like this:

curl -sD - -o /dev/null

After all, here's the response:

HTTP/1.1 200 OK
Server: nginx/1.6.3
Date: Sun, 23 Aug 2015 21:43:58 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding

Using the verbose flag instead

And a final option is to substitute the -v flag for -D, which will show both the request headers and response headers and show any errors etc:

$ curl -s -v -o /dev/null
*   Trying
* Connected to ( port 80 (#0)
> GET / HTTP/1.1
> Host:
> User-Agent: curl/7.43.0
> Accept: */*
< HTTP/1.1 200 OK
< Server: nginx/1.6.3
< Date: Sun, 23 Aug 2015 21:44:45 GMT
< Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Vary: Accept-Encoding
{ [2688 bytes data]
* Connection #0 to host left intact

curl error [globbing] bad range specification

Posted June 26th, 2015 in Linux/Unix/BSD

When testing some website redirects with curl from the command line, I got the error message "curl: (3) [globbing] bad range specification in column 120"

Escape [ and ] or use -g or --globoff

An example URL that will cause the error is this:

curl "[]=123"

Either escape the square brackets like this:

curl "\[\]=123"

or use --globoff like this:

curl --globoff "[]=123"

or the shorter -g like this:

curl --g "[]=123"

ERROR 1115 (42000) : Unknown character set: 'utf8mb4' in mysql

Posted June 25th, 2015 in MySql

When attempting to load a database dumped with mysqldump into an older MySQL database, I got the error message ERROR 1115 (42000) : Unknown character set: 'utf8mb4' in mysql.

What's utf8mb4?

utf8mb4 is a utf8 character set, which was added to MySQL in version 5.3.3, that fully supports unicode. Read this post by Mathias Bynens for more information about the difference between to the two character sets with MySQL.

How do I solve the problem?

If you dumped a table/database that supports utf8mb4 then you need to load it back into a MySQL database that is at least version 5.3.3. If you try to do it in an older version, you're going to get the error message I gave in the opening paragraph.

A quick and dirty solution, not recommended

There is a way to workaround this, but I strongly advise not to, as you may cause data loss and/or other unexpected consequences. In my case, I was simply trying to benchmark database queries running across different servers with the same database, so it didn't really matter too much if some utf8 characters got saved incorrectly or other content modified.

Let's say you dumped the database like this:

mysqldump -u [username] -p [database] > database.sql

You can then run "sed" against it to change all the instances of utf8mb4 to utf8 like this:

sed s/utf8mb4/utf8/g database.sql > database.sed.sql

It'll run pretty fast; doing this on a 500MB file only took maybe 10 seconds on the server I was doing it on. Note that it will replace all instances of utf8mb4 with utf8. So, for example, if I'd dumped the table containing this post then all instances in the content would also have changed.

You can probably modify the sed expression to work out all the various ways the character set is set in the file and run those, avoiding modifying anything else, but you still may have issues with character encoding being broken - just a final warning :)

A better solution?

If you have a better solution, feel free to add it in the comments.

Importing YouTube into WordPress from another CMS

Posted June 17th, 2015 in PHP and WordPress

I've been involved in converting a custom CMS to WordPress and we imported the content (mostly) successfully into WordPress, but the YouTube videos wouldn't embed, even when stripping out the iframe and just leaving the YouTube URL in the content.

How it normally works

You would normally just copy and paste a YouTube URL into WordPress and it will automatically do all the clever stuff to add whatever tags are necessary to embed it into the page. Then you'd save it and, hey presto, it all works like magic.

But when importing and the YouTube video is in an iframe

If you assign HTML to post_content and save it using wp_update_post(), it completely strips out the iframe, and won't even leave the YouTube URL there. Whoops.

But when importing and the post_content contains HTML

If you strip out the iframe and just leave the YouTube URL, for example like this:

$content = preg_replace('~<iframe.*"(https?://*)(\?rel=0)?".*</iframe>~U', '\1', $content);

but there's other HTML in post_content, then WordPress doesn't seem to want to do its magic with YouTube URLs. Whoops.

I found that if you enclose the YouTube URL with [embed] ... [/embed] then it works. I have seen suggestions to do [youtube=...], but that didn't work for me.

So, revising the above regular expression to this:

$content = preg_replace('~<iframe.*"(https?://*)(\?rel=0)?".*</iframe>~U', '[embed]\1[/embed]', $content);

did the trick for me.

I hope it works for you too!

How to do a tick/check and a cross in Excel

Posted May 11th, 2015 in Applications

There are several fonts which let you easily type a tick/check or cross into a cell in Excel, or use in any other application; or you can use unicode.

Using fonts

Use the Marlett or Webdings fonts, and use "r" for a cross and "a" for a check or tick.

Using unicode

There are a few checkmarks and crosses that can be used with unicode too.

U+2714 is "heavy check mark"

U+2718 is "heavy ballot x"

This page at Wikipedia shows how to put unicode into a document:

Xamarin Android Player to simulate Android devices

Posted May 7th, 2015 in Applications

Five years ago, I bought a Mac Mini so I could use the iOS Simulator (and then quickly "upgraded" to a more powerful MacBook Pro when I realised I far preferred OS X to Windows) but struggled to find a decent equivalent for Android devices. After a quick Google today I found the Xamarin Android Player, which does the trick nicely.

Xamarin Android Player

Download it from here:

There are versions for both Windows & OS X. I've only tried the OS X version. You download and install it, and then there's a list of downloadable devices. At the present time, these are:

  • Nexus 4 KitKat, Lollipop & Jelly Bean - 768x1280
  • Nexus 5 KitKat & Lollipop - 1080x1920
  • Nexus 7 KitKat, & Jelly Bean - 800x1280
  • Nexus 10 KitKat - 1600x2560 (i.e. 800x1280)
  • Nexus S KitKat - 480x800

I'm not sure how or if you can add other images.

The only annoyance I have found so far is that the virtual device will only use DNS for domain lookups, and won't look at your local hosts file (whereas the iOS Simulator will use the hosts file first, and DNS lookups next).