Setting up WordPress on WAMPServer

After getting the web server part of WampServer working, I wanted to install the latest version of WordPress (version 3.8) and the FavePersonal theme by Alex King. I wanted to play with it before installing it on my regular website. I decided to search for some examples on installing WordPress on WampServer. The best one was on WPBeginner.com, but I still had to get some other information to complete the installation. When the post talked about using phpmyadmin to set up a MySQL database for the WordPress install, it did not mention at that point that the default username and password for phpmyadmin would be root and blank. I had to enter that information to be able to create the database for WordPress. The post did mention it later when talking about setting up the wp-config.php file.

When I reached the point where the WordPress application displayed a screen prompting me to create a configuration file, I went ahead and clicked on the “Create A Configuration File” button. The next screen appeared as shown in the post. I entered the information for the database name, username and password, and entered “localhost” for the database host. However, when I clicked the Submit button, the browser appeared to not be able to connect to the server. As I mentioned in an earlier post, I had to use “http://localhost:8080” for my WampServer install. I then entered localhost:8080 as the host name, but this was not successful, either. I finally decided to go ahead and create a configuration file by saving a copy of wp-config-sample.php as wp-config.php in the root directory of my WordPress directory (C:\wamp\www\mytestweblog for my install). Here are my entries:

[cc lang=”perl”]

// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define(‘DB_NAME’, ‘mytestwp_db’);

/** MySQL database username */
define(‘DB_USER’, ‘root’);

/** MySQL database password */
define(‘DB_PASSWORD’, ”);

/** MySQL hostname */
define(‘DB_HOST’, ‘localhost’);

[/cc]

After creating that file, I again went to http://localhost:8080/mytestweblog/, and was able to resume setup of my weblog per the post. I played around with the test weblog, and liked it enough to put it on my main weblog.

For WampServer installs where port 8080 has to be used, it seems that WordPress has problems with creating a configuration file. The user will probably need to create the file manually.

 

Correcting WAMPServer Apache problems

A long time ago, I had the WAMPServer application set up on a netbook and did some WordPress work on that setup. Since then, I have moved on to a full laptop, but had not used WAMPServer on that machine. I wanted a place to explore some different WordPress themes separate from my regular install, so I started on the WAMP install process.

I downloaded the current version at the time and clicked through the install steps, which were pretty straightforward. However, when I started WAMPServer and tried to enter “localhost” in the browser, I did not see the default PHP index page. After some searching in the WAMPServer forums, I found that if Skype is installed, that can tie up port 80. I tried unchecking the box for port 80 in Skype options in my installation, but still did not see anything when I entered localhost in the browser. Finally, per this Wampserver forum post, I saw that it should be possible to change the Apache port to port 8080 instead of 80. I edited httpd.conf (at C:\wamp\bin\apache\Apache2.4.4\conf in my install) and changed the port listening to 8080 as follows:

[cc lang=”perl”]
#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 8080
[/cc]

After that, http://localhost:8080 worked! The WAMPServer documentation should be updated to make it easier to correct this problem.

Rebooting My Weblog

I started my weblog a few years ago, and have done some writing here and for publication. However, I have let things slide, and have not been active in quite a while. In the past few months, I have become interested in the IndieWeb concept of publishing your content once and syndicating elsewhere (POSSE). I am also interested in doing some mobile development and finally have some time to explore both of these areas. With this being the first part of the year, I thought I would put my stake in the ground as to what my weblog focus will be:

Out of the Box – These types of posts will be to capture the first experience of using a tool, app, or technique. My hope is to capture the good, the bad, and the ugly, and provide feedback on the bad and ugly parts.

Narrate Your Work – Following Dave Winer’s post, I am going to work to document my steps as I try out new tools and apps.

I am also going to take heart in Matt Mullenweg’s post for the New Year where he talks about the intrinsic value of blogging, and write this weblog for myself and one other person (I will have to figure our who that person is!). Now, let’s get started!

Sort Your Data Using Javascript

Introduction

Javascript has basic sorting built into the language, but it also has the flexibility to do any kind of sorting you want. Read on and find out more about how you can customize your sorting tasks with Javascript.

Basic sorting

The Javascript array sort method performs an alphabetic sort of an array. Here are some examples:

[cc lang=”javascript”]
var wordList = new Array( “red”, “green”, “blue”);
wordList.sort();
[/cc]

Printing wordList gives the list {“blue, “green”, “red”} (see Example 1 web page).

[cc lang=”javascript”]
var wordList2 = new Array(“tiger”, “cat”, “dog”);
wordList2.sort();
[/cc]

Printing wordList2 gives the list “cat”, “dog”, “tiger” (see Example 2 web page).

Sorting using comparison functions

To perform sorting of an array using some other method besides alphabetical sorting, a comparison function must be passed to the sort method. This function can be included in the sort method as an unnamed function, or it can be a separate named function which can be called by the sort method. Here is an example of a template for a separate function:

[cc lang=”javascript”]
function numberTest (a, b) {

}
var numberList = {5, 4444, 333, 22222, 11};

numberList.sort(numberTest);
[/cc]

The sort method calls the function numberTest, working through all of the elements in the array. The arguments a and b in the function represent two elements in the array. The body of the function should return one of three values:

1. a goes before b = return a negative number
2. a goes after b = return a positive number
3. a is the same as b = return a zero

A simple comparison function for a numeric sort would be:

[cc lang=”javascript”]
function numberTest (a, b) {
return a – b;
}
[/cc]

This function will perform a numeric sort in increasing order. Printing the numberList array after sorting will display the following:

5 11 333 4444 22222 (see Example 3 web page).

To perform a numeric sort in decreasing order, the line within the function should be changed to the following:

[cc lang=”javascript”]
return b – a;
[/cc]

Printing the numberList array after sorting will display the following:

22222 4444 3333 11 5 (see Example 4 web page).

To perform a reverse alphabetic sort, the comparison function must explicitly return a -1, 0, or 1 depending on the alphabetic order. Returning the value of the direct comparison as for numeric sorting will not work. An example comparison function is shown below:

[cc lang=”javascript”]
function reverseAlphabeticTest(a, b) {
if (a < b) return 1; if (a > b) return -1;
return 0;
}
[/cc]

(see Example 5 web page).

Sorting lists of objects

Next, let us examine sorting an array of objects, where each object has two fields. A set of objects could be as follows:

[cc lang=”javascript”]
var testObject1 = {item: 5, note: “aaa”};
var testObject2 = {item: 4, note: “bbb”};
var testObject3 = {item: 3, note: “ccc”};
var testObject4 = {item: 2, note: “ddd”};
var testObject5 = {item: 1, note: “eee”};
[/cc]

These object can then be added to an array as follows:

[cc lang=”javascript”]
var testArray = new Array(); // Create a test array

// Add objects to testArray
testArray[testArray.length] = testObject1;
testArray[testArray.length] = testObject2;
testArray[testArray.length] = testObject3;
testArray[testArray.length] = testObject4;
testArray[testArray.length] = testObject5;
[/cc]

where the length property of the array is used as the index (it increases as more objects are added to the array).

The numeric sort comparison function used for examples 3 and 4 can be reused for sorting on any field in the object, but the field must be specified using a dot structure as shown below:

[cc lang=”javascript”]
function compareItems (a, b) {
return a.item – b.item;
}
testArray.sort(compareItems);
[/cc]

Printing the list of items and notes in the array after sorting gives the following:

Items: 1 2 3 4 5
Notes: eee ddd ccc bbb aaa
(see Example 6 web page).

As shown before, the order can be reversed by reversing the order of the elements in the comparison function.

Finally, let us look at how a comparison function can be more complex. This example will assume that Javascript is being used to read RSS feeds using the XMLHttpRequest function, and that the news items in the RSS feed need to be sorted by the pubDate element for use in a “River of News” RSS reader application. The application has already extracted the news items from RSS feeds as individual objects in an array with the following fields for each RSS item: title, link, description, pubDate, and guid. An example object could be as follows:

[cc lang=”javascript”]
var testObject1 = {title: “Star City”,
link: “http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp”,
description: “How do Americans get ready to work with Russians aboard the space station?”,
pubDate: “Tue, 03 Jun 2003 09:39:21 GMT”,
guid: “http://liftoff.msfc.nasa.gov/2003/06/03.html#item573”};
[/cc]

To perform a sort on pubDate, the text string describing the publication date of the item needs to be converted to a number for comparison. We can use the parse method included with the Javascript Date object to create the following comparison function:

[cc lang=”javascript”]
function comparepubDates(a, b) {
var pubDateValue1 = Date.parse(a.pubDate); // Get milliseconds for date/time string
var pubDateValue2 = Date.parse(b.pubDate); // Get milliseconds for date/time string
return pubDateValue1 – pubDateValue2;
}
[/cc]

This function will parse the pubDate field and convert the date string to a value in milliseconds, then use that value for the comparison to sort the objects.

(see Example 7 web page).

Summary

Javascript can sort arrays of data and arrays of objects in flexible ways. Use these examples to start sorting your data today!

References

RSS specification – hosted at Harvard University

Stack Overflow – discussion on sorting of Javascript objects