How to install PHPMyAdmin on Windows Server 2008

At present if you install Wordpress as part of the Web Platform Installer it does not install PHPMyAdmin for you. Luckily this install is very easy to do.

Head over to http://www.phpmyadmin.net and download the latest installer to your server.

Once downloaded unzip the contents of the file and rename the folder to 'phpmyadmin'.

Copy this folder to your website containing Wordpress or php.

Open the file config.sample.inc.php into wordpad (notepad puts it all on one line) and enter in a new Blowfish_secret. It can be anything random like a password.

Next uncomment:

// $cfg['Servers'][$i]['controluser'] = 'pma';

// $cfg['Servers'][$i]['controlpass'] = 'pmapass';

and replace with the root database username and password or create a new mySQL user called pma and use those details here.

Now uncomment the Storage database and tables - just remove the leading // from each line.

Save and close the config file. Rename it to: 'config.inc.php'.

Copy the phpmyadmin folder and paste it into your website root level.

Go to the Examples folder and open the create_tables.sql file using notepad. Copy all the content in here.

Open your website in a browser and point to yourdomain.com/phpmyadmin

Login using your root database and password. Ignore all the error messages for the moment. Go to SQL and paste in the sql text you copied. Now click on Go.

Log out of phpmyadmin and log in using the database username and password you used when setting up your Wordpress/MySQL database for this project.

Everything should now be working as expected for you.

How to setup Wordpress on Windows Server 2008 with IIS 7

I recently had to install and setup a few Wordpress blogs onto Windows Server 2008. No biggy I thought. I'll just install Wordpress using the Web Platform Installer and away I go. Unfortunately it's never that easy! Below are the steps I took, the pitfalls I came up against and the solutions I have to getting Wordpress setup.

First up, setup your domain in IIS 7. For the purpose of this article I will assume that you have done this and are looking to setup Wordpress to this domain.

If you don't already have the Web Platform Installer setup on your server go over to http://www.microsoft.com/web/downloads/platform.aspx and download the installer.

Step 1: Install Wordpress

Once the installer has downloaded, run it from the server and when it starts go to 'Applications' on the top menu bar and select 'Wordpress' and click 'Add' and then 'Install'.

Step 2: Enter an admin account for MySQL

You will be asked to setup a root username and password for MySQL as part of the installation. Remember to write these details down somewhere as you will be using them later during the installation. The installer will now download Wordpress and setup PHP and MySQL for you.

Step 3: Enter the Wordpress location

Once the files are downloaded you will be asked to select where you want Wordpress installed. If you setup a domain already in IIS then simply select the domain from the drop down list. By default Wordpress will want to install in yourdomain.com/Wordpress - just remove the word Wordpress from the application textbox if you'd like your install to be on the root level or set it to another name if you'd like to be inside a folder eg to get yourdomain.com/blog just enter blog into the Wordpress application textbox.

Step 4: Lastly enter the database info for this install of Wordpress

Click on Continue and you will be asked to enter the database details. On this screen leave the dropdown on 'Create a new database' and enter in your root database user and password which you created at the start of this install. Now enter in your database username, password and database name you want for your project. The location of the database is usually 'localhost'.

NOTE: Make sure your password does not contain any special characters. If you enter a password with characters like !"£$%^&*() then you will have an issue where the website will not load for you when you go to view it later on. I think this is a bug as part of the web platform installer. I also had an issue if my username contained dots or dashes.

Once you're happy with the details click Done and Wordpress will be installed for you. You can click on the link to launch your website on localhost on the server to ensure everything is working as expected.

Potential Pit Fall: Wordpress installed ok but returns a blank / empty website

This happened to me if I use special characters in the database username/password/database name fields during the install. Delete the new Wordpress folder you created and start the above process again using simple text/number combinations to confirm this is your error.

Before your Wordpress site is ready for production you need to configure some settings in the wp-config.php file for Wordpress. This file is located in your website wordpress folder you setup during the installation.

Go to https://api.wordpress.org/secret-key/1.1/salt/ and copy the entire text that you receive. Go back to your wp-config.php file overwrite the empty values with these new values containing the keys. Now click save to close down the file.

Allow SEO friendly URL rewrite rules:

Create a new web.config file (if one does not already exist) and set it up with the following rewrite rules:

 

Aaaannnddd you're done!

Wordpress should now be working as expected for you! Read on if you'd like to customize the install to allow larger file uploads, add another installation or Wordpress or even add a mutlisite wordpress install.

Increase the file upload size for PHPMyAdmin/PHP

By default PHP gives you a pretty small 2mb limit for uploads. The good news is that this is a super easy thing to change. If you installed PHP in the default location then it should be located in C:\Program Files\PHP. Scroll down to php.ini and open it in notepad. Find the following and update them as you see fit:

 

post_max_size =8M 
upload_max_filesize
=2M
max_execution_time
=30
max_input_time
=60
memory_limit
=8M

Change to (can be whatever size you require here I've the settings set to 20MB):

post_max_size = 20M 
upload_max_filesize
= 20M
max_execution_time
=500
max_input_time
=500
memory_limit
=128M

 

How to add another Wordpress installation

You can add another Wordpress install by using the Web Platform Installer and selecting Wordpress again. The installer will know that you already have PHP and MySQL setup so it will just ask you where you want Wordpress installed. Simply follow the normal steps (put it on a domain, give it a folder and enter database settings) and your all set.

How to setup Wordpress to be a Multi-website installation

By default Wordpress is setup for 1 website but you can easily set it up to handle multiple website if you want - instead of installing Wordpress into loads of sub folders. All you have to do is open your Wordpress wp-config.php file and before the line enter the following:

define('WP_ALLOW_MULTISITE', true);

Now log into your Wordpress site and go to Tools -> Network and select Subdomain or SubFolders and follow the rest of the onscreen instructions.

How to turn on detailed PHP error messages:

If you or your developer wants to temporarily turn on error messages on your server then go to your PHP.ini file (C:\Program Files\PHP) and locate the following line from display_errors = Off to display_errors = On. Open IIS and restart the website. You will now have detailed PHP errors.

You can also turn on detailed error reports through IIS by selecting the domain and double clicking on Error Pages. On the right hand side you can click on Edit Feature Settings and choose Detailed Errors to activate 404 errors. To turn on detailed errors for server 500 errors simply right click on Status Code 500 from the list of codes in Error Pages in IIS and select Edit Feature Settings and click on Detailed Errors.

Be sure to turn off these detailed errors before going live with your site if you want to avoid displaying sensitive information about your server and application to potential hackers!

Summary

As you can see there isn't much to setting up and installing PHP, MySQL and Wordpress onto a Windows Server 2008 box. Hopefully you'll find this guide useful.

New update for RTE News Reader app coming out shortly

I've just submitted a new update to the Windows Marketplace for my RTE News Reader app. This update is only a minor update but includes a fix to a nasty bug that was forcing some news articles to not display.

The bug was caused by badly formatted XML from RTE.ie - rogue ampersands to be precise. I was able to track down that it was badly formatted XML by using a simple XML validate checker - http://validator.w3.org/feed/ This checker highlights everywhere that the feed could be failing.

Once I could see the issues I then had to put in a workaround. The problem with just replacing &'s is that they are also going to be used for valid html encoded values in the XML. I had to ensure that I was replacing single ampersands only. I was able to do this by using a regular expression to find single instances of ampersands in the text and replaced them with html encoded versions of themselves. This Stackoverflow article discusses how to implement such a fix: http://stackoverflow.com/questions/121511/reading-xml-with-an-into-c-sharp-xmldocument-object

The app is now going through the usual approval processes in the App Hub. All going well, it should be available for download by the end of next week.

 

How to fix the DataTables.net Internet Explorer error: "Unable to get value of the property 'style': object is null or undefined"

On one of my latest management projects I had to test and ensure that the project would work as expected in Internet Explorer. With the exception of a few style issues, which are to be expected when IE testing, I noticed that my DataTables.net code was returning the following error: Unable to get value of the property 'style': object is null or undefined. This was only happening in Internet Explorer 7 and below.

Usually IE would return this error message if the number of columns I was declaring in the DataTables javascript did not match the number of headers I had in my HTML. However, I knew that I did have the correct number of headers as the code works as expected in all the other browsers.

When I went to investigate my code I noticed a rogue coma on the last element in my column collection when I was declaring my DataTable. My code looked something like this:

$(document).ready(function () {
            oTable = $('#dt').dataTable({
                "sAjaxSource": 'AllUsers/',
                "aoColumns": [
			            { "mDataProp": "Firstname" },
			            { "mDataProp": "Surname" },
			            { "mDataProp": "Email" },
		            ]
            });
        });

When I removed that last coma after my Email column everything worked as expected. Now my code looks like this:

$(document).ready(function () {
            oTable = $('#dt').dataTable({
                "sAjaxSource": 'AllUsers/',
                "aoColumns": [
			            { "mDataProp": "Firstname" },
			            { "mDataProp": "Surname" },
			            { "mDataProp": "Email" }
		            ]
            });
        });

It's weird that IE had an issue with this and the other browsers were ok with it. I guess it's just down to the different rendering engines in the browsers. It was incorrect before but the other browsers ignored the issue. Thankfully this was an easy fix!

How to force your database name using Entity Framework migrations in a multi-project solution

If you're using Entity Framework migrations in a multi-project solution you might have noticed that when you run the 'Update-Database' action your database was given the name 'yourdatabase.Data.DataContext'. Some people don't mind this default naming scheme but I want to call my databases something a bit cleaner.

My typical MVC solution contains many projects to help keeps things separated. My database code is in my 'Data' project but my web.config file handling my connection string is usually contained in my 'Web' project. I noticed that even if I have given my database a name in my connection string this was not being picked up by the Entity Framework Migrations code.

Luckily all you have to do to force entity framework to use the database name you want is put the database name into your Context file. For example:

public class DataContext : DbContext
    {
        public DataContext() : base("DatabaseNameHere")
        { }

        public DbSet Table1 { get; set; } 
        public DbSet Table2 { get; set; }
    }

How to avoid the entity framework migrations error: 'Could not load file or assembly or one of its dependencies.'

I've been using Entity Framework migrations for a few weeks now and I'm having a great time with. However, I've notice that every now and then Entity Framework throws an error when I try to run the 'Update-Database' command.

Whenever you get a message 'Could not load file or assembly or one of its dependencies. The system cannot find the file specified.' there are a few steps that I've noticed you can do to help work around this type of error.

  • Step 1: Firstly, ensure that your models and any relationships that you've setup are correct. Sometimes this error means that you have incorrectly setup a join or a relationship previously setup is broken. At present the error messaging returned by migrations is a tad lacking and it returns the above error for broken model relationships.
  • Step 2: If you change your models I find that unless I edit my Data Context file I get this error. My solutions usually contain many projects. I don't know if that is the reason I get this error message but if I update one of my models without altering the context file migrations continues to return the above message for me. If I don't need to alter the context file (usually I don't as I've just added a new column) then simply pressing space and re-saving the context file does the trick.
  • Step 3: Check your database isn't 'blocking' migrations from running. I ran into a few occurances where I would have manually deleted my database and occasionally this would stop migrations from creating a new database. This is a simple fix. Just right click on the Databases heading in SQL Server and click on 'refresh'. If a refresh doesn't solve the issue, try closing SQL Server Management Studio down and restarting it again.
  • Step 4: Clean your build history and try a rebuild before running 'Update-Database'.
  • Step 5: Lastly, try forcing code first to run by using '- Force'. For example 'Update-Database -Force'. This command is also useful for telling migrations to carry out a task that would result in a data loss.

If you continue to get the error message mentioned above then the issue is nearly always down to your code. Recheck it and try again. I'm sure as Entity Framework Migrations matures they will be able to return better, more meaningful, error messages.

A little Spring cleaning! RichardReddy.ie gets a new lick of paint.

richard reddy .net web developer

I've been very bust over the last few weeks working on some interesting MVC 3 projects but one of the things I was meaning to get around to was redoing my own RichardReddy.ie website. I had let the domain just sit there for about 12months but thankfully I had some time over the weekend to get a simple 'CV' style site up and running.

I will be launching another 2 personal sites very soon to highlight my mobile work. I've been having a great time developing for Windows Phone and I'm hoping to make some more apps for the phone very soon so having a website/portal showcasing my work makes sense. All going well these should be live before the end of March.

RTE News Reader hits the Windows Marketplace

RTE News Reader App for Windows Phone

Over Christmas I decided to dip my toes into making a Windows Phone app for my Lumia 800. If there's one app that I was missing when I moved over to Windows Phone from iOS it was the RTE app. There was no official app so I went about making a quick little app to pull in their RSS feed and make readings the news stories a bit easier to consume on the phone.

I ran into issues straight away as the RTE feed does not support RSS 2.0 which a lot of the code samples out there seem to be using. Thankfully as I've been using Linq to XML so much in my job I did a little workaround to allow me take in the feed in the app. After that any other issues I had were just your basic 'getting to grips' issues. Funny things like finding out that Windows Phones can't support GIF images out of the box or that they only have 16bit displays so gradients look crappy caught me off guard as I coded up the app.

Thankfully I could work around these limitations. Making the app was a great learning experience and was actually surprisingly easy to do for a typical .net developer. If I have one complaint it would be that the App Hub website is a bit dodgy right now. This is the website you register your app on. The website is really slow and while they have implemented ajax calls for most operations, it can take upwards of 25secs to see any results with zero indication that anything is actually loading for the user.

Having said that, there is nothing sweeter than the satisfaction of thinking that there are people out there who are using your app (and hopefully enjoying it!). I have tons of new features I'd like to add to make the app a lot more useful for others. As soon as new updates are out I'll let you know here or on my Twitter feed.

I was also a little shocked that my app went to number 1 in the Irish News section and number 6 in the overall top free downloads for the Irish Marketplace! That's pretty sweet :)

RTE News Reader app for Windows Mobile is number 1 news app in Ireland

If you want to check out the app yourself, head on over to the Marketplace and give it a whirl! I respond to all emails sent through the app so don't be shy and get in touch. I don't mind if it's good or bad. If there's a feature you'd like and I can add to the app than I'll do it :)

How to get ApplicationBarIconButton images to display

I ran into an issue the other day where I wanted to use one of the default icon set images for my new Windows Phone app. I followed the guides online and took the images from the Windows Phone SDK on my computer and pasted them into my project.

However, every time I ran my project I noticed the image was not displaying. I would just get a nice looking X in a circle (I guess it's the new "red X"!). To resolve this issue you need to right click on the icon(s) you want and select Properties. When the Property window opens change the Build Action to Content. For me, this was defaulting to Resource and was the reason that the image would not appear for me in the application bar.

IIS7 ASP Routing not working on live server

We had an issue at work the other day where one of the developers was having an issue with asp routing in IIS7. It was the first time this particular server was asked to run a .net 4 website so naturally some fine tuning was required. When we tried to navigate to the webpage the following error appeared: 403: Access Permission Denied

I thought this looked odd as all permissions were applied correct and the webpage in question was coming up for us when we included it's extension. I took a look at the web.config file and noticed the rule to use asp routing was missing so we added that:

         
    
        
        
    

However, this didn't fix our issue. I was puzzled and spent a further 30mins exploring all the different options and settings in IIS. Eventually I took a look at the Global.asax where the page routing was detailed. I noticed that there was a folder by the same name as the page we were calling. We had Directory Browsing turned off - hence the Access Denied Permission error that was throwing me off!

So I guess the bottom line is, add the above code to your web.config and if it's still not working then make sure you don't have a folder in the project with the same name that you're trying to route to!!