How to get Wordpress working on Blacknight's Windows hosting

I recently setup a Wordpress site on my Blacknight Windows hosting account using their Web Applications tool. During the setup I had 2 issues that I could not find any blog posts on that I thought might be useful to other people out there who are trying to do the same thing as me.

My requirement was to install Wordpress on the root level of my domain.

Before I started to install Wordpress I setup my Windows hosting so that PHP would work on it. Using the Blacknight control panel I clicked on the domain I wanted to use and then clicked on the Website Configuration link. Click on the Install button to see a list of applications you can setup and choose Wordpress.

In this area, I selected PHP to run as 'Fast CGI application' and ActivePerl support to 'run as a CGI application'. I clicked save and moved onto the Web Application manager.

I selected Wordpress and was brought to the settings screen. Everything looked ok. I changed the folder to install to as '/' and entered the admin password I wanted to use. When I clicked save I was told that the folder had to contain a value so I had to leave it as the default '/Wordpress' option to get it to install for me.

At this point everything looked like it had installed. I had green lights in my Blacknight control panel and was told that the install was successful but when I went to my site I was seeing a 404.0 asp.net error. It turns out that you need to give the blacknight server about 5-15mins to install Wordpress for you. Even if you see the files in FTP you might not be able to go to the website for a few minutes. This is normal. Just give it a while and eventually your Wordpress install will appear for you on yourdomain.com/Wordpress.

Next up I wanted to move the Wordpress install to the root level. I tried following the guide from Wordpress on how to do this but it didn't seem to work for me. It turns out that you can move your Wordpress install by opening your Blacknight control panel and going back into the Web Application section and choosing the Wordpress link. On the bottom of the page is a button saying 'Change URL path'. Simply put in '/' (no quotes) and give it another few moments. Type in yourdomain.com and your Wordpress install will be visible for you.

As you can see, it all makes sense when you know how. the key is to allow the Web Applications to install to a /Wordpress folder, give it 5-10mins to set it up and then update the Wordpress install to the root level. Hopefully this will help some others out who might be scratching their heads as to why they are seeing 404 errors or wondering how to install to root on the Windows Hosting package.

Files uploaded through Wordpress on Windows Server are missing permissions

When uploading files in Wordpress, PHP uses a temporary upload folder. By default PHP will use the C:\Windows\Temp when uploading files. If you install PHP and Wordpress onto your Windows server then you might notice that any files uploaded through Wordpress are not accessible on your site. This is down to PHP taking the folder permissions from the C:\Windows\Temp folder which does not have public access granted on it (for obvious security reasons!).

To work around this issue you need to create a new folder and give that folder the correct permissions for the uploaded files to be available to users who visit your site.

Step 1: Create a new folder. I decided to use a folder on the root level: C:\TempUploadedFiles

Step 2: Right click on this folder and grant enough permissions for the files to be viewed online. Typically you would add IIS_IUSR, Users and NetworkService users with read permissions.

Step 3: Now we need to tell PHP to use this new folder when uploading files. Open your PHP.ini file in notepad (usually in C:\Program Files (x86)\PHP) and locate the line with 'upload_tmp_dir'. Replace the whole line with this:
upload_tmp_dir = C:\TempUploadedFiles
(make sure there is no semi colon at the start of the line!)

Gotcha: Be sure to check that there is no other 'upload_tmp_dir' declared in the PHP.ini file. In the file I was using there was another instance of 'upload_tmp_dir' located at the end of the file and it was overwriting my values.

Step 4: Save your PHP.ini file and open IIS. Locate your website and click on restart for the new settings to take effect.

Step 5: Open Wordpress and upload your new file. PHP will use your new destination to handle the file during upload and when the file has fully uploaded it will transfer it to the correct location in your wp-content/public folder with the correct permissions.

You only need to make this change once as in future all PHP sites will use the new C:\TempUploadedFiles folder.

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.