Wednesday, April 6, 2016

How to edit a WordPress website offline on your Windows desktop using WAMP

In my previous post I covered the installation of WordPress with WAMP. This is a follow-on for the the below post:
How to install WordPress locally on your Windows desktop using WAMP

Now that I have wampserver and WordPress installed and running on my desktop it's now time to import the site so I can work on it. Once again I have another gripe with the WordPress documentation - There isn't enough detail as usual. How to move your WordPress site to edit it offline should be discussed in the "Moving WordPress" section of their Codex but it's so generic it verges on unhelpful. With this post I aim to help anyone in a similar situation to me. 

Backing up your WordPress site
Your WordPress database contains every post, every comment and every link you have on your blog. If your database gets erased or corrupted, you stand to lose everything you have written. While I could go through the process of doing everything manually, I decided to make use of the various plugins available in WordPress. I started with "UpdraftPlus - Backup/Restore" but in order to make use of migrate and export options I needed to buy another plugin for that plugin - Yeah, not happening. Next up I decided to take a look at a plugin named "Backup Guard" which seems to work great so far.

First off I installed BackupGuard on the production site. After installation there is a new entry in the sidebar for "Backup Guard". Clicking on the backup guard entry will bring you to the following GUI where you can complete a backup or import a previous backup. I performed a manual backup and you can see it completed successfully:

Here is where I encountered my first problem. When I clicked the download button it simply opened my website, rather than actually downloading anything. Right click the save logo and choosing save target just gave me an error stating no file. I'm not sure if this would have worked in another browser or not but I just decided to use SFTP instead and transferred the backup (sg_backup_20160406201153.sgbp) to my local desktop. Swapping over to the offline instance of WordPress I tried to import the backup, however it told me the file was too large (67MB) but offered me an alternative.

If your file is larger than 2MB you can copy it inside the following folder and it will be automatically detected: C:\WAMP\www\wordpress\wp-content\uploads\backup-guard

Please note your directory may be different depending where you installed WordPress. So I did just that; Copied my sgbp file to the above folder and it appeared once I returned to the backup guard section again. Now I just needed to click the restore button and hope everything went to plan:
This process took approximately a minute or so and then I was brought back to the login prompt again. First I felt a little panicky because my credentials I setup in the previous installation were not being accepted. Then I realised my mistake; The credentials being requested were those of my live website rather than the offline instance. The import was a success! 

Much easier than I expected..

How to install WordPress locally on your Windows desktop using WAMP

Despite the love/hate (mainly hate) relationship I have with WordPress I have decided that I need to start gaining a better understanding of how it works. Rather than making changes online to a live website it would obviously be better to do this with an offline copy which is exactly what I aim to explain here: Installing WordPress on your desktop so you can work offline.

To run WordPress on any machine there are a few requirements:
  • PHP version 5.6 or greater
  • MySQL version 5.6 or greater OR MariaDB version 10.0 or greater
  • Server software such as Apache
This may seem like an intimidating list of software to source and download one-by-one, but that won't be necessary. This is where WAMP comes into play!

What is WAMP and why do I need it?
WampServer is a Windows web development environment. It allows you to create web applications with Apache2, PHP and a MySQL database. Alongside, PhpMyAdmin allows you to manage easily your databases. An all-in-one package which contains everything that WordPress requires so our lives had suddenly become much easier. There are other clients for Windows such as XAMPP with the biggest difference being that WAMP runs on Windows, XAMPP is multi-platform. Aside from that it's a matter of personal preference. They both provide you with an Apache-MySQL-PHP environment that runs pretty much the same under both systems.

Installing wampserver on Windows
Before installing WordPress you will need to download and install wampserver on your Windows desktop. Double click on the downloaded file and just follow the instructions. Everything is automatic. The WampServer package is delivered with the latest releases of Apache, MySQL and PHP. 

You will need to choose the installation directoy for WAMP - The recommendation being that you do not install to "Program Files" but instead install it in a folder in the root directory as there could potentially be some permissions issues. I installed it to C:\WAMP which worked fine. At one point during the installation, WampServer will ask for the location of the default web browser and text editor. WampServer will automatically choose notepad.exe and Internet Explorer as the default options but these can be changed if needed. 

Once the installation completes successfully you should see the 'W' icon in your notification area:

If you don't you will need to start wampserver by finding the entry in your start menu. On Windows 8 my entry looked like this:

Creating a database for WordPress to use
Before installing WordPress you will need to create a database that WordPress can use. To do this we will need to access one of the wampserver features named phpMyAdmin. Easiest method of accessing this is to left-click the wampserver icon and click on phpMyAdmin
This will open a new browser window to http://localhost/phpmyadmin with a login prompt. The default credentials here are root with no password. When you log in you may notice the big warning at the bottom of the page stating "You are connected as 'root' with no password, which corresponds to the default MySQL privileged account. Your MySQL server is running with this default, is open to intrusion, and you really should fix this security hole by setting a password for user 'root'." Sounds scary but this is not a problem as long as this is only a local installation. 

Click on the databases tab at the top of the page which will give you a list of the current databases and allow you to create a new database. In the 'Create database' menu enter a name for your database. I called mine 'wordpress' for simplicity sake:

Download and install WordPress on Windows
Don't worry we're almost there! Now it's time to go and grab yourself a copy of WordPress from their website: https://wordpress.org/download/

This will download a .zip file which you will need to unzip. Once unzipped you will find a wordpress folder which you will need to move to C:\WAMP\www. So my directory structure looks like C:\WAMP\www\wordpress. As soon as the copy completes you should be able to access WordPress via your web browser via http://localhost/wordpress. If you rename the wordpress folder to mysite then you would access it via http://localhost/mysite. You should be prompted to choose your language for WordPress.

WordPress will then inform you that it is going to create a wp-config file using the provided information in the following steps. If for any reason this automatic file creation doesn’t work, don’t worry. All this does is fill in the database information to a configuration file. You may also simply open wp-config-sample.php in a text editor, fill in your information, and save it as wp-config.php. 

One the next page you will need to enter your database details. Here is what mine looks like:
If you recall in the earlier steps I created a database named wordpress and we logged in using the default credentials of root and no password. If this works you can proceed to the next steps with a very friendly message:
All right, sunshine! You’ve made it through this part of the installation. WordPress can now communicate with your database. If you are ready, time now to…
Now we can proceed with actually installing WordPress!

On the next page it will ask you for:
  • A website title - What is the name of your website? I just named mine offline.
  • A username for logging in with
  • A password for the above username - You can use the default here if you want but I would never remember that. 
  • An email address
It doesn't really matter what you enter here since this will only be used for offline testing anyway. Again if you plan on actually using this to host a website for the outside world you will need to be more security conscious than I am being here.

If the installation succeeds you should then be brought to the login prompt where you will need to enter the username and password you just created. 

What now?
Whatever you want! You now have a fully functional installation of WordPress which you can use testing and offline development. Have fun!!

Thursday, December 3, 2015

The anatomy of a WordPress theme

My cousin asked me to develop a website for her Father's business. Initially I thought this would be a great learning experience as I knew the basics of web development (HTML, CSS, PHP, and a bit of JavaScript) but had never completed a full website before. I slowly but surely realised just what I had landed myself into... !

To cut a long story short I decided it would be best to implement a WordPress theme! I've always heard this makes content management very straightforward and doesn't require much knowledge of PHP / HTML for managing. Sounds perfect - Unless you're the one developing the site in which case it's a fucking balls.


Had I known how difficult this would be I definitely would not have chosen WordPress for my first development job. I guess the first hurdle I encountered was understanding the template hierarchy. See what I did at first was simply hard code an index.php and styles.css and upload them as a theme. Then I tried to create a new page from within WordPress and that wouldn't work - It kept bringing me back to index.php. I had also tried to create a contact.php with the company contact details - Now how the hell do I open this in WordPress? Hmmmm.. !

It was at this point I learned about the WordPress Theme Hierarchy. I didn't understand it, but I knew it existed. So I kept trying numerous different implementations, none of which worked. Read multiple blog posts and just ended up confused. Until I saw the 'template-loader.php' being mentioned somewhere and this is what finally made me understand the theme template. Show me in code and I'll understand!

Let's take a look:

Examining this file is what finally made everything click with me in terms of how pages get selected, and the reason why creating a new page in the WordPress GUI was not working. I only had an index.php! Basically, this code steps through each of the query context conditionals in a specific order, and defines the template to use for the first one that returns true. So in my case, only index.php was being found and so only the contents of index.php were being returned.

When a person browses to your website, WordPress selects which template to use for rendering that page. As we learned earlier in the Template Hierarchy, WordPress looks for template files in the following order:
  1. Page Template — If the page has a custom template assigned, WordPress looks for that file and, if found, uses it.
  2. page-{slug}.php — If no custom template has been assigned, WordPress looks for and uses a specialized template that contains the page’s slug. A slug is a few words that describe a post or a page. If the page slug is recent-news, WordPress will look to use page-recent-news.php.
  3. page-{id}.php — If a specialized template that includes the page’s slug is not found, WordPress looks for and uses a specialized template named with the page’s ID. If the page ID is 6, WordPress will look to use page-6.php.
  4. page.php — If a specialized template that includes the page’s ID is not found, WordPress looks for and uses the theme’s default page template.
  5. index.php — If no specific page templates are assigned or found, WordPress defaults back to using the theme’s index file to render pages.
I realise this is just the basic knowledge needed but I hope to discuss this further. Writing here helps me understand and get my thoughts clear.

Saturday, June 27, 2015

Setting up the Plex container in unRAID 6

In this post I am going to discuss how I went about adding the Plex container in unRAID 6. It's a fairly straightforward process and didn't cause me many headaches thankfully. I was originally running the server from my desktop but that wasn't an ideal solution because I don't leave my desktop on all the time.





Enabling Docker

The first step involved here was enabling Docker. To do this you simply navigate to the Settings tab, click Docker, and then use the drop down menu to enable Docker. PlexMediaServer is one of the default docket templates that comes packaged by lime-technology in unRAID 6. Navigate to the new Docker tab and you will see a section named 'Add container'. From there you want to choose 'PlexMediaServer' under the limetech heading. 

There is only one required folder named 'config' for this docker but you're going to want add more. The config folder does exactly what it says on the tin - Stores the configuration settings for this particular docker. I originally made the silly mistake of pointing this folder to a directory on the flash drive running unRAID. As soon as I rebooted the server I lost all the configuration I had spent the previous setting up - bummer. So for this directory you're going to want to specify a directory on the array. I created a folder called 'DockerConfig'.

In order to add any media you will also need to specify these directories too. I added one named /movies pointing to /mnt/disk1/movies and another named /series pointing to /mnt/disk1/series. 

All that is left now it to allow unRAID to create the docker container. Simple as.


Configuring Plex

There wasn't a whole lot of configuration required with Plex assuming you only want to use it locally within your home. If you plan on streaming media externally you will need to setup remote access. There are three steps required in doing this. The first step required is to sign into your Plex account, assuming you created one. If not you will need to register an account. The second is port forwarding - By default Plex will use port 32400 but you can specify another port if you prefer. You will need to forward this port to the IP of your server. Lastly you need to edit the settings of your plex server for remote access and manually specify whatever port you chose by ticking the box to manually specify. 

Wednesday, June 24, 2015

unRAID 6 benchmarks

Now that I've got unRAID up & running I thought it would be interesting to run some benchmarks so I could determine what kind of speed to expect. I have purchased a gigabit switch and cat6a ethernet cables for wiring everything up so this as fast as I can get for now. The program I used to run these benchmarks is called 'CrystalDiskMark'. This is with two WD Red 3TB drives with one acting as a parity disk.


I don't think that's too bad considering I don't have a cache device set up yet. Still slower than my desktop mechanical drive for both sequential read and write speeds but I doubt I will notice the difference when it comes to real world usage - Hopefully anyway. Parity certainly had more of an impact on the speeds than I would have liked. My internal 1TB WD Blue mechanical drive clocked the below speeds. Much faster for sequential reads and writes but a hell of lot slower for the 4k metrics.


I'll probably revisit this in the future when I set up my cache device.

Monday, June 22, 2015

Benchmarking my desktop SSD

My desktop currently has a 120GB M500 Crucial SSD installed for booting my OS and related applications. It's not exactly a top-of-the-line drive by any means but it's more than enough for every day use. The spec sheet for this model claims I should be getting up to 500 MB/second reads and 400MB/s writes. So when I saw the results of my CrystalDiskMark test I was underwhelmed to say the least. It's worth nothing that this drive was 75% full at the time of the test so I understand this has the potential to affect speeds - But not this much!

56MB/s sequential writes?? Time to figure out what's going on here..



Troubleshooting steps

First off I needed to ensure that AHCI was enabled. AHCI stand for Advance Host Controller Interface. This is a hardware mechanism that allows software to communicate with Serial ATA (SATA) devices such as SSDs. Windows supports AHCI out-of-the-box by default but just to be sure I went into device manager to confirm the AHCI controller was enabled and running.

So it's enabled - Great! Now I just need to confirm that the SSD is being managed by this controller. Right click the controller, choose properties, then navigate to the 'Details' tab. In this section you are greeted with a drop down menu where I chose 'Children' and could see my SSD listed so AHCI is definitely enabled.

Then I needed to confirm that 'TRIM' was enabled. TRIM support is essential for an SSD to run the way it should to avoid slow writing times. This command allows an operating system to inform a solid-state drive (SSD) which blocks of data are no longer considered in use and can be wiped internally. To test if this is enabled you can run the command "fsutil behavior query DisableDeleteNotify". If this returns as 0 then TRIM is enabled.

The next step was to make sure I was at the latest revision of the firmware. The firmware download for my SSD comes as an ISO package so I stuck it onto a USB using unetbootin and made a backup of my current SSD before proceeding - I've had enough bad experiences to warrant backups! Thankfully the installation completed successfully without any issues and I was upgraded from MU03 to the MU05 revision. Rebooted and went through another benchmark with CrystalDiskMark. No improvement whatsoever.



So considering there was little to no change in the speeds I figured I would confirm the results with another benchmark tool - Atto disk benchmark. Now I'm seeing more along the lines of the expected speeds! At my maximum I reached over 500MB/s reads and maxed out about 140MB/s writes. I'm still a little disappointed with the write speeds though but this is a start at least.




As this was an SSD I was recommended to test out 'AS SSD Benchmark' which also confirmed that AHCI was enabled and my alignment was okay. This reported speeds were pretty much along the same lines as what I've seen so far with write speeds being reported between 113MB/s and 134MB/s. Still disappointing.





I went ahead and asked someone else to run the same test on their Crucial M4, which is an older model than mine. He was clocking double my write speeds with similar read speeds using the same test config as me. Only other difference between his test and mine was that his drive has higher total capacity with about 50% free whereas I only had 25% free. I went about reducing the space consumed on my drive and then re-ran the test only to receive roughly the same numbers again..





The conclusion

After a bit more digging I realised this was down to false advertising rather than anything being wrong with my drive / configuration. The M500 series drives are capable of up to 400MB/s write speed at the higher capacity spectrum of drives. My specific model - CT120M500SSD1 - I found is only capable of about 130MB/s which more or less matches up with the speeds I was recording in some of the benchmarks. Here is a screenshot from the product page on newegg:


Sunday, June 21, 2015

Installing unRAID 6 on my HP Proliant Gen8 Microserver G1610T

In this post I am going to discuss how I went about installing unRAID 6 on my HP Proliant Microserver G1610T.


Downloading the unRAID image

Before going about installing unRAID I was under the impression that it would come in an ISO package like every other OS. However unRAID just comes as a package of files with a 'make-bootable' executable inside. Preparing the USB is easy! First of all your USB needs to be formatted to FAT32 and the volume label must be set to UNRAID in capital letters. 

Then simply transfer all the files to the root directory of the USB (i.e. not in a folder) and then run the 'make-bootable.bat' file as administrator. (Right click -> Run as administrator) A CMD prompt will appear just asking you to confirm you want to proceed - Press any button to continue and hey presto job done.



Now you just need to eject the usb from your computer, connect it to the internal USB slot of the microserver and boot it up. Mine booted into the USB straight away without editing any BIOS options. After successfully booting up I was able to navigate to http://tower from my desktop and was greeted with the unRAID web GUI. It really was that easy!



Licensing

Before you're able to do anything inside unRAID you need a license key. Upon first installation you're entitled to a 30 day evaluation period to test out the software. To activate your license navigate to 'Tools -> Registration'. You will need to enter in your email address so the license URL can be sent to you which you then paste into the box provided.



After that you're pretty much good to go!