So you think you want a website.

May 15th, 2020

I have been helping some people set up websites recently and thought it would be good to explain the basic elements to putting up a website.

Domain registration.
This is done by GoDaddy, Namecheap, etc. It is where you pick your domain name. You can have multiple domain names for your site. That’s especially useful if your company has a long name, but you want an easier to remember website name. So if your name, is Old Towne Bike Shop and Brew, you might want to also register BikeAndBrew, Note that domain names are not case sensitive, so you can use caps like WellGolly.com to make them more readable. Be careful when you pick you name so that there isn’t something bad in the middle. My brother-in-law got a license plate for his Wild Horse Ranch but could only use 8 letters. WILDHORS just doesn’t cut it. Likewise, Dr Goode, Physical Therapist shouldn’t pick, GoodeTheRapist.com.

DNS – Domain Name Service
This is where you point the domain name to a specific IP address. Every device on the internet that communicates to the outside world has an IP address. The modem in your house has an IP address that is assigned by your Internet Service Provider (ISP). When you visit a website, you send along your IP address. When the website responds, it sends information to your IP address and your router then sends it to the device in your house or office that requested the information. Same thing happens with your phone when you are out and about. The IP address can change but you don’t want your websites address to change.

So when you buy a domain you need to point it to a fixed IP address so the world knows how to find you. You get that from whoever provides your server. Then you tell the DNS where to find the IP associated with your domains. My server 173.255.194.220. You can reach my server at this address and it sends you to the default site. There are many websites on my server and the webserver that I use (Apache2) sees that WellGolly.com is being asked for and redirects traffic to a folder on the hard drive.

You can use your registrar for DNS but I use the server provider—Linode.

Server
You can have GoDaddy host your website if you want. Lots of people I work with do that. Or you can have your own PC. I used to do that but now it is much cheaper to use the cloud. I share a machine with others but to me it looks like I have the machine all to myself. Some of my domains are at Linode and some are at Digital Ocean. Large companies use Amazon AWS, Google, or Microsoft. There are many many alternatives for all budgets and loads.

SSL Certificate
The lock button on the website means that traffic is encrypted from my server to your computer. It assures that the traffic is not messed with and no one knows what you were reading. All they know is that you visited a site. You used to have to pay a lot for SSL certificates but now you can get them from Cloudflare or Certbot for free. I use Certbot. This doesn’t verify that you are a legitimate company, just that the traffic is encrypted. Banks and big retailers use other services that also verify the identity of the company.

The actual website.
I use a combination of code and WordPress for my sites. The nice thing about WordPress is that I can set up people to use it and they can’t do anything else on the server.

You can get all five of these services as a bundle from lots of companies—GoDaddy, Squarespace, Wix, WordPress, etc.

WordPress site health
I am running the server on Ubuntu 18.04.4 LTS which means that I can update it regularly until 2023 and nothing will break. There is a new Long Term Service version that just became available and I am testing it on one of my servers. It updates PHP but I don’t need any new features so I haven’t updated it on this server yet.

On one of the sites that I host the user was concerned that the WordPress Health Check flagged imagick PHP module as a recommended performance improvement. Apparently one of the plug-ins that they are using for uploading images works better with it. I installed it from the command line using sudo apt-get install php-imagick.

It also noted that there were plug-ins that weren’t updated. I don’t have automatic updates enabled (I actually don’t know how to do that.) but you can update the plugins by looking for the red number next to the Plugins tab.

They also got a few Critical Issues. The REST API encountered and error and Could not complete loopback request. These errors are due to either a problem with a plug-in or conflict between plug-ins. If the site works, just ignore them. Otherwise, disable plug-ins until the error goes away and then figure out how to fix it.

Site Metrics
If you want to use Google to track the site, there are plug-ins that let you do it or you can copy the code and I can out it on the site. One benefit of using Google for tracking is that you know they have indexed your page.

You can Google how to do it, this page seems reasonable.

Matomo also has a plug-in that avoids having Google spy on all of your traffic.

Updating WordPress from the dashboard.

May 3rd, 2020

I have a bunch of old WordPress installs that I manage. I have been updating them from the command line and updating plug-ins by dragging them from my desktop to the plugins folder using Cyberduck. There is an easier way but it requires a few tweaks to your install.

First you need to change the ownership of each file to www-data. I also change the group to the users group.


sudo chown -R www-data .
sudo chgrp -R user .

Then you need to add a line to the wp-config.php file. I added it to the last line of the file.


/* Sets up direct method for updating without FTP */
define('FS_METHOD','direct'); 

Now anyone with a dashboard login can update the site.

Update from Ubuntu 18.04 to 20.04

May 3rd, 2020

I decided to let the update process overwrite any config files that I had edited, knowing that I had a few that might need updating.

There was one issue with Apache2 where the newest version of PHP wasn’t linked in the config files for Apache. The problem was that there were two the load files—one for 7.2 and one for 7.4. I deleted the one for 7.2 and renamed the one for 7.4 then reloaded the modules and restarted Apache. That seems to have worked.


sudo rm /etc/apache2/mods-available/php7.2.load

mv /etc/apache2/mods-available/php7.2.conf /etc/apache2/mods-available/php7.4.conf
sudo a2enmod php7.4

Mail stopped working, but that’s because Dovecot didn’t know where to find the SSL certificates from Let’s Encrypt and where to put the mail. I followed the directions in a previous post and it works now.

Randomizing a PHP Array

March 19th, 2020

I wrote this before it occurred to me to see if MariaDB could randomize the output. It can, with ORDER BY RAND();.

PHP has a shuffle function that can randomize one array, but I have a bunch that need to have the same random order.


// Create an array of numbers
$randomArray = range(0,$numWords-1); 
shuffle($randomArray); 

// Create empty target arrays     
$word = []; $sounds = []; $phrase = []; $sentence = [];

for ( $i = 0; $i < $numWords; $i++ ) {
  // Use the numbers in the random array to swap elements.
  $random = $randomArray[$i];
  $word[$i] = $word_S[$random];
  $sounds[$i] = $sounds_S[$random];
  $phrase[$i] = $phrase_S[$random];
  $sentence[$i] = $sentence_S[$random];
}

Updating sites—PHP Notes

March 9th, 2020

As I mentioned in the previous posts, I’m using W3Schools to review HTML, CSS, and PHP in order to create some exercises. Here are a few things that I didn’t know about PHP or want to remind myself about.

When sending users to specific pages I often use numbers to indicate which page they should go to. Spambots will frequently put in random junk so I do some tests before I process the request. PHP has some odd behaviour with some of the functions. For example,


// Invalid calculation will return a NaN value
$x = acos(8);
echo is_nan($x);     --> 1
echo var_dump($x);   --> float(NAN)
echo is_null($x);    --> expect 0 but get a blank line, so only works on numbers—not NAN
echo is_finite($x);  --> blank line, so only works on numbers—not NAN

echo is_finite("Hello");     --> Warning: is_finite() expects parameter to be a float
echo is_finite(10);          --> 1
echo is_infinite(10);        --> expect 0 but get a blank line
echo is_infinite(10e1111);   --> 1

// $hello not defined
echo var_dump($hello);       --> NULL
echo is_nan($hello);         --> blank line
echo is_null($hello);        --> 1
echo is_finite($hello);      --> 1
echo is_infinite($hello);    --> expect 0 but get a blank line
echo is_int($hello);         --> expect 0 but get a blank line

var_dump(is_numeric($hello)); --> bool(true) 
is_numeric($hello);           --> expect 0 but get a blank line

I never gave constants much thought when developing web pages, but i’m thinking that they might come in handy when making interactive games. If I access the database and grab a bunch of data that will be displayed but won’t change, it should go into a constant array which is then accessible to any function on the page. Note that both constant arrays and variables are referenced by their name without a $ before the name.


define("cars", [
    "Alfa Romeo",
    "BMW",
    "Toyota"
]);
echo cars[0];  --> Alfa Romeo

function arrayDisplay() {
  foreach (cars as $value) {
        echo "$value ";
    }
}
arrayDisplay();  --> Alfa Romeo BMW Toyota

If you use a variable array, the array isn’t available to functions.


$cars = array(
    "Alfa Romeo",
    "BMW",
    "Toyota"
);
var_dump($cars);  -->  array(3) { [0]=> string(10) "Alfa Romeo" [1]=> string(3) "BMW" [2]=> string(6) "Toyota" }

function arrayDisplay() {
  foreach ($cars as $value) {
        echo "$value ";
    }
}
arrayDisplay(); -- > Warning: Invalid argument supplied for foreach() … 

Well Golly


Atheism Plus

Buy from Amazon