So you think you want a website.

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.

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

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

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];
}