Author: John Stewart Page 1 of 41

phpMyAdmin logo

WordPress migration tip

This is largely a note to myself, but I hope it will be useful for anyone else who helps to administer a Domain of One’s Own project.

I get a lot of requests from OU Create users to migrate a WordPress site from one user’s account to another or to create a forked version of a site.

The first part of this is relatively easy. Either download an existing backup of the site or go into the File Manager and create a zipped copy of the file structure for the site.

Next go into phpMyAdmin, select the database for the site and then export a copy.

Now, go to the cPanel for the new copy of the site. Make sure there is a domain/subdomain/or subdirectory ready to receive the files for the site. Upload and unzip the files.

The harder part is manually uploading the database. Go to MySQLDatabases and create a new DB and a new user. Assign the user to the DB and make sure to keep a copy of the password you set up for the user.

Now go back into the files for the new site. Open wp_config.php and update the lines that define the DB_NAME, DB_ USER, and DB_PASSWORD (usually something like lines 23-29 of that config file.

Last, you need to upload and update the DB. Go into phpMyAdmin, and you should see the DB you created a few minutes ago. Select this DB, and then import the copy of the DB from the old site. If successful, you should see all the tables and information from the old site.

Here’s the last bit that I learned today. There is a SQL command that will change every occurrence of the old URL for the site to the new URL for the site. I found this on a post at a site called WPBeaches.com:

UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');

In the site that I just migrated, that updated over a thousand values in the DB. As soon as I ran that, I was able to load the new forked copy of the site at its new URL.

*Edit: After initially writing this, I found one more thing that needs to be changed in the settings. Login to your WP dashboard and go to Settings->Media. There, you will likely need to change the path for where you want your media stored.

Last fun little tip. Go back to the cPanel, and click on WP like you’re going to install a fresh copy. There is a dropdown to the right of the ‘install this application’ button. One of the options there is “import existing install.” On the next screen, choose “From this account.” Then you will get a settings screen with a dropdown of domains, subdomains, etc. You can select the domain or subdomain where you just manually installed WP, and then click import. Now, you’re manually installed WP instance will show in your ‘myApps’ list from Installatron, and you can use the backup, cloning, delete, and auto-login features.

image depicting a 404 error web page

Checking the status for 5200 websites

OU Create

The University of Oklahoma offers all of its students, staff, and faculty their own web domains through the OU Create program. Anyone who wants to can sign up for a free subdomain (something like yourname.oucreate.com) or pay $12/year for a top-level domain (something like yourname.com). We provide 5GB of storage, tech support, and workshops to help people get started.

Once someone has registered for OU Create, they can use the Installatron tool that is built into the system to launch a one-click install of WordPress, Drupal, Omeka, and about 150 other web-apps. Right now our Installatron logs show a little more than 5200 active installations of WordPress, accounting for more than 80% of all the active registered domains. This does not include the inactive installations of people who have deleted their accounts or left the university and taken their websites with them.

I’ve been curious for a while as to the status of all of these sites. How many of these installations are actively being used? How many were used for a course at some point but have not been updated for a while? How many installations were set up but never really used? Are there any sites that are glitching, and do the users know about those glitches.

Checking Statuses

As an administrator, I can use the Installatron logs to see the URLs for all of the WordPress installations on a server. We have 5 servers, so I wrote a python script that will quickly pull that information from each server and compile it into one big list.

Next I wrote another python script (the link goes to GitHub gist and the code is also written below) that ingested that list of URLs, went to each URL, and returned the “HTTP status code” for the site. A status code of 200 means that the site loaded as expected. A status code of 301, meant that the URL redirected me to another page that then loaded. A status code of 400, 401, or 404 meant there was some sort of error loading the page. There were also pages where the system couldn’t find anything, so I told my script to record these as “no connection.”

import urllib3
import os
import csv

rows = []
http=urllib3.PoolManager()
#load the csv list of URLs to check
with open('urls.csv', 'r') as input:
    csv_reader = csv.reader(input)
    for blog in csv_reader:
        #check blogs in list for status
        try:
            #this get response will only retry a url 3 times, does not preload the site data, and records the status but does not load a redirect
            resp = http.request('GET', blog[0], retries=3, preload_content=False, redirect=False)
            line = [blog[0], resp.status]
            rows.append(line)
            resp.release_conn()
        #if there's a domain not found error, it will be caught by this except
        except:
            line = [blog[0], "no connection"]
            rows.append(line)

with open('urlStatus.csv', 'w') as output:
    csv_writer = csv.writer(output)
csv_writer.writerows(rows)

When I tested the script on a list of 50 URLs, it worked, but it took several minutes. When I tried to run it on all 5000+ URLs, it ran for over two hours with no end in site. Ultimately, I split the list up into five smaller lists, and ran the script simultaneously on each of the five lists. It worked, but I left it running overnight, so I’m not entirely sure how long it took. This morning I compiled the five output .csv files.

The end result was that 3800 sites loaded with no problem. An additional 1100 sites redirected once, and then loaded. I think many of these were simply making a minor edit to my URL by adding a “/” to the end, pushing me from something like mysite.oucreate.com/blog to mysite.oucreate.com/blog/.

Of the 23 sites that had 400 status errors, 9 were actually redirects, that the my system didn’t recognize for some reason. The other 14 have issues, and I’ll follow up with their owners to help them either fix the sites or delete them if they’re no longer using them.

The remaining 282 sites returned “no connection.” Many of these are smaller sites that were once installed as subdomains and subdirectories of main sites, but are no longer in use. Others are sites URLs that have expired. I’m going to follow up with the owners of these expired sites. Where they were intentionally allowed to expire, I can delete them from our system. Where they expired unintentionally and haven’t been noticed yet, we can see about re-registering them.

Once I get to a good place with these sites that returned 400 and 500, I’m going to run a third script to see how many of the sites that are working properly are in active use. If the site only has the Hello World blog post that comes with the software and the default theme, I will reach out to the owners to see if they want any help getting set up or want me to delete an unused account. After I get through all of these WordPress sites, I’ll go back to Installatron and run similar checks on the rest of the OU Create domains.

A History Course Site with Leaflet

I’ve been interested in using digital maps to in history projects for a while now. My first big project on this was Situating Chemistry. This is a research database of places where chemistry has been done. Each site can be linked to related people, documents, chemical processes, industries, etc.

A screen shot of the world map in the Situating Chemistry database featuring data about 18th century Paris
Map of chemical sites in Paris, overlaid onto a map of Paris from 1790. You can interact with this map at situatingchemistry.org/worldmap

I presented on Situating Chemistry at a couple of DH workshops at OU, and eventually convinced Prof. Janet Ward to incorporate a similar project into one of her history courses. This Spring, she taught a course on 1945 focusing on the events at the end of the war and some of the more immediate cultural changes.

For Dr. Ward’s class, each student was asked to complete three assignments:

  1. An analysis of a visual source including a painting or pamphlet or even physical object from 1945
  2. An analysis of a primary textual source from 1945
  3. And an analysis of a secondary history of 1945 or the war more generally

For each of these assignments, the students wrote a blog post on their own, free OU Create blogs.

I built a course hub that collected the students’ posts both in a menu and a map. Dr. Ward picked a map from the David Rumsey Map Collection and I embedded it into a WordPress site using the Leaflet Map plugin. Once the plugin was activated, I set up a home page for the site and then embedded the map using the Leaflet shortcode:

[leaflet-image source="https://1945.oucreate.com/wp-content/uploads/2019/03/8713007.jpg" height=550 width=100%]

This loads the custom map as an image and sets the size of the map in the display. Then I added pins to the map for each of the student’s blog posts:

[leaflet-marker y=0.06400615721940994 x=-0.14913830161094666]
Post Title
Post Text
Post author
Post link
[/leaflet-marker]

The leaflet-marker coordinates tells the system where to put the pin on the map. The Title, text, author, and link appears in the popup when you click on a pin for a given student project. Temidepelayo Ojekunle, the Office of Digital Learning student assistant, scanned the student’s posts for the course and put together a spreadsheet of titles, short summaries, authors, and links. Using the Leaflet-plugin’s tool for finding the coordinates, I then plotted each of the pins and copied over the information from the spreadsheet. The end result is this site:

Screenshot of the 1945 website depicting the site's main world map with pins for student projects.
Screen shot of the 1945 course website showing the pins linking to student projects.

I really like the idea of accessing the content of the site both through the menu and through the map. I’ve been looking for web elements that are more interesting than a list, and I really like how the map draws you in and lets you see the focal clusters of the course.

In the next version of this site, for a future class, I’d like to use a tool like MapTiler to create tiles for the map, so that you don’t lose resolution as you zoom in on sections. I’d also like to get a better understanding of Leaflet’s resources for using and creating pin icons. I might even move out of WordPress and just use straight HTML since the WordPress php heavy and unnecessary for this type of site. I also hand-coded all the Leaflet pins in this project using the short code, but compiling a geo-json from some sort of form would have been far more efficient.

Page 1 of 41

Powered by WordPress & Theme by Anders Norén

css.php