Archive for the ‘Coding’ Category

PHP Warning

Wednesday, May 11th, 2016

I’ve been getting this warning when I open PhpMyAdmin and since it doesn’t affect anything, I haven’t bothered to fix it.

PHP Warning:  is_readable(): open_basedir restriction in effect. File(js/codemirror/lib/codemirror.js) is not within the allowed path(s): (/usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/) in /usr/share/phpmyadmin/js/get_scripts.js.php on line 31

Today I had some time, so I looked at what might be causing it. By grepping on part of the error message,


I found four files with that text, and more importantly, it was prefixed with
‘php_admin_value open_basedir’.
They were:


I tried adding ‘/usr/share/javascript/’ to the first one and restarting Apache, but that did’t work. Then I added it to the sites-available file and the did the trick.

Converting my site to https

Wednesday, May 4th, 2016

I already use https with an SSL certificate for my orders, but given the rumblings from Google, I thought it would be nice to make sure the whole site uses secure links and definitely uses https links when I am connecting to pages where I collect customer input. Although, as we’ll see below, since I redirect the whole site to https, it doesn’t matter if I explicitly use https links to pages that receive customer data.

The first thing I did was to check for places in the text where I have hard coded a link to the site. These are mostly from manuals for apps that I copied from the app. A few are from links to manuals that were copied from the URL field and not cleaned up. All I need to do is remove the website portion and they will resolve as https links. There are also a few from redirects and they just need an ‘s’ added. The code I used is:

grep -r --exclude=\*.{png,jpg,pdf,pdf,odt,ods,svg,exe,dmg,psd, indd} "http://www.wellgolly"

Note that I have a bunch of pdf files and graphics files as well as the master LibreOffice and Photoshop files that I don’t want to search. Using this list excludes them for me. Your list may be different.

There are still a bunch of links that are not https and to see what they are, I changed the search slightly to print the file name and the part of the line that matches the search term. The option ‘o’ shows the part of the line that matches the search pattern. Not particularly useful if the pattern is ‘http:’ but more informative if the pattern is ‘http:.*’. There are lots of these, probably not worth changing now, but something to keep in mind when updating that portion of the site.

After I did this I noticed that the -I option excludes binary files. This is much shorter.

grep -roI "http:.*"

One more step and you are done. It took a while to find this and I should have looked on the Apache site first, but I didn’t. The preferred way to redirect your site is not with mod_rewrite, which is what most of the pages that turn up in a search suggest, but with a redirect directive inside your virtual host. Since I only have one website of many that I am converting, this solution works for me. I simply commented out my Document Root line and added a permanent redirect to the SSL section.

#DocumentRoot /www/WG/wellgolly
Redirect permanent /

Restart Apache and it works.

You can test your server at SSL Labs:

Once you have it up and running, open all of your pages and see if you get the secure lock at the top of the page. If you missed any links to content that is displayed on your page—images, Facebook like buttons, etc. then it won’t be locked. I like to use Chrome for testing since the lock is bright green. Links to things outside of your site can still be http.

Once thing that I was concerned about was that the links to Yahoo’s Pure CSS files are not https. It doesn’t affect the browser’s reporting the the page is secure but it won’t load the styles either. I copied them to my server and now they load. I don’t know if it is a Safari security feature or if it is from Ghostery.

A couple of things to note. My SSL certificate only covers the www portion of the domain. So things like will not redirect to https. This change only affects the website so if you are adding SSL to your site, you might want to change your mail delivery as well to use the certificate.

Fix hyphenation in WordPress themes

Wednesday, November 18th, 2015

A new blog that I installed using the TwentyFifteen theme has annoying hyphenation on the posts. I found an easy fix online. Open the style.css file and insert this at the end.

   -webkit-hyphens: none;
   -moz-hyphens:    none;
   -ms-hyphens:     none;
   hyphens:         none;

for loops in bash

Sunday, November 8th, 2015

I don’t do much shell scripting, but every once in a while I use it to automate things. I was playing around with bash today and thought this might interest others.

Define an array variable
$ servers=(server purple yellow dan);
$ echo $servers

Redefine it.
$ servers=(firstserver server purple yellow dan);
$ echo $servers

That’s not what I want. So how do we access the values? Let’s try a for loop.
$ for name in $servers; do echo $name; done;
$ echo $servers

Well that didn’t do it. Let’s try to access the second value with array notation.
$ for name in $servers; do echo $servers[1]; done;

If you look carefully at this you’ll notice that what is happening is that you are concatenating the return value from $server with [1]. Try it again with this line.

$ for name in $servers; do echo $servers[a]; done;

And again.
$ for name in $servers; do echo $servers.a; done;

As long as you use a character that is not a valid part of a variable name, you get concatenation.
e.g. don’t use an alphanumeric.
$ for name in $servers; do echo $serversabc; done;

There is no variable called serverabc, so you get a blank line.

It turns out that bash has weird syntax for working with variables.
$ echo ${servers[2]}

Add another value.
$ servers[5]=finalvalue
$ echo ${servers[5]}

So how about we separate out the loop variable like this?
$ for name in $servers; do echo $servers${name}; done;

Well, we’re getting warmer.
$ for name in $servers; do echo $name; done;

This is getting frustrating. Let’s back up and try just listing a bunch of stuff in a list.
$ for name in firstserver server purple yellow dan finalvalue; do echo $name; done;

So we can make a for loop iterate through items, but the normal way of accessing elements of an array doesn’t work in bash. It turns out that you need special syntax.

$ echo ${servers[@]}
firstserver server purple yellow finalvalue finalvalue

And to loop through everything like we wanted to do at the start.
$ for name in ${servers[@]}; do echo $name; done;
final value

That wasn’t so hard was it?

MySQL won’t reboot

Sunday, October 11th, 2015

After the 100% full hard disk problem I couldn’t get MySQL to restart. I looked at the error logs and found these lines.

151010 16:51:18 [ERROR] /usr/sbin/mysqld: Table './SS_connellsville/alerts' is marked as crashed and should be repaired
151010 16:51:18 [Warning] Checking table:   './SS_connellsville/alerts'
151010 16:51:56 [ERROR] /usr/sbin/mysqld: Table './SS_greensburg/values_RSSI_3' is marked as crashed and should be repaired
151010 16:51:56 [Warning] Checking table:   './SS_greensburg/values_RSSI_3'
151010 16:51:58 [ERROR] /usr/sbin/mysqld: Table './master/node_groups' is marked as crashed and should be repaired
151010 16:51:58 [Warning] Checking table:   './master/node_groups'

A stackoverflow post recommended using mysqlcheck. It must be used when the mysqld server is running. I couldn’t see how to set it to just repair the databases that were causing problems, but I figured that it wouldn’t hurt to run it on all of them. I was a bit concerned that it would run into problems when the cron jobs ran, but I set it running anyway. It changed the record count on all of the databases and ran for many hours. At least six, but I stopped monitoring and let it run overnight. I stopped MySQL and did a restart and it started without errors.

mysqlcheck --repair --use-frm --all-databases

Well Golly

Atheism Plus

Buy from Amazon