Posted on

Kay’s ‘Getting started with XDebug for WordPress’ Guide

Over the weekend I spoke at WordCamp London about using XDebug, it was a quick lightning talk, and I wanted to write out what I went through and some additional bits because a few people said they’d like something like that to get them started. Plus usually after a WordCamp I usually just post a simple blog about ‘Oh yeah this happened and it was fun’ so I wanted to write something more useful after it!

It’s also worth mentioning that I’m not a developer, so this is a very basic ‘How to get started’ guide showing you just some of the things XDebug can do. It’s a much more powerful tool than outlined here, and you should definitely do some extra research after reading!

So uh, yeah! Here goes.

Setting XDebug up on a local environment (MAMP)

The easiest way to get started with XDebug is with MAMP on your computer, because it comes already installed. If you’re using a different local development solution there’s tonnes of guides online for a variety of them. I just used MAMP because I found it by far the quickest and easiest to set up for beginners.

Here are the steps:

  1. Download and install MAMP from: https://www.mamp.info/en/

When MAMP is installed and opened you will have a window like the one to the right. Click ‘Start servers’ to fire up your local environment.

This will load up a webpage with useful resources for your local development area. It’ll look like the screenshot below – and will include links to your homepage and php info page.

 From here, click on the ‘phpInfo’ page, this gives you useful information about the version of PHP and the modules associated with it running on your test server. we specifically want to use this page to find out where our php.ini config file is located.

Now we know where the file is located, we can navigate there on our computer. So if you go to the folder where the php.ini files located and open it up in your preferred text editor program, you can edit some of the options here. We are going to enable XDebug by finding this line at the bottom:

;zend_extension=”/Applications/MAMP/bin/php/php7.2.1/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so”

This is the XDebug module, which is disabled by default, to enable it all you need to do is remove the semi-colon from the start and add whichever XDebug options you want to enable, so here’s what my XDebug lines look like in php.ini after enabling it:

Finally, I enable onsite errors on my test server so I can see them immediately on the page. To do this I change the line in my php.ini file currently saying ‘display_errors = Off’ to:

Then use the MAMP main screen to restart my server. When that is done you can check your php.ini file to see if XDebug is listed as enabled, or you can go ahead and start breaking some PHP code, because with display errors enabled it will show you on your homepage like this:

You don’t have to enable onsite errors, but I find them easy to work with, instead you can choose log files to send them to, for a full list of options check out: https://xdebug.org/docs/

Profiling

Profiling is a super handy tool that XDebug offers. It helps to find out where memory issues lie, by saving data about your called functions in a cachegrind file.

To enable profiling, you first need to add this to your php.ini file (or possibly .htaccess depending how your server is set up and if you’re using actual online hosting):

php_value[xdebug.profiler_enable]=1

This enables profiling, and your site will start generating a cachegrind file full of useful insights. For ease of obtaining this, you can set your own path for where the cachegrind file(s) will be saved:

php_value[xdebug.profiler_output_dir]=/var/www/vhosts/mysite.co.uk/httpdocs/

From there, I can download and save my cachegrind file to my computer. Opening it will give you all the information obtained, but it’s pretty much unreadable because of the file format. But with a program like Webgrind you can open the cachgrind file in a much more readable and user-friendly format. For Mac users like myself however, the easiest way to do this is by installing and running Qcachegrind. Which is installed as follows:

  • Open Terminal on your Mac.
  • type ‘brew install qcachegrind’
  • Type ‘brew install graphviz’

Now you can run Qcachegrind and open the file you saved earlier, as follows:

qcachegrind ~/Downloads/cachegrind.out.21991

Obviously change the directory to wherever you downloaded and saved your cachegrind file. When this is ran it will load up a window that looks something like this:

This screenshot does contain a lot of information, but it is far more readable than just opening up the cachegrind file in your text editor. The left side panel gives you load times for individual functions, in order of what takes the longest. With this you can easily identify if a plugin is slowing your WordPress site down, because it might have a specific function taking a long time here.

The right side gives a more graphical representation of these load times. Bigger boxes are bigger and longer-to-run functions. It does give a lot more information than this, but this is mostly what I’ve used qcachegrind for, and its definitely worth running if you want to get some deep insights in to what is running and causing slowdown on your site.

Breakpoints and FYIs

I don’t do a lot of hardcore development myself, so breakpoints aren’t something I regularly use. But they’re definitely worth looking in to because it allows you to use XDebug with your code editor and set a line in your file to stop the script running at that point.

I’m going to link to the documentation for Atom for that, but yeah, check breakpoints out:

https://atom.io/packages/php-debug

Other things to be aware of when running XDebug on your servers are:

  • XDebug is resource intensive, so if you do enable it on any live hosting, make sure you turn it off any time it is not being actively used by yourself to debug code. Ideally just run it on your staging.test environments.
  • Keep in mind on-site errors will also need switching off if you don’t want them showing up.
  • Cachegrind files and extended error logs can fill up server space quickly, so again, only enable it when needed!

Thanks for reading through this, if anyone needs further help getting started with XDebug feel free to get in touch. I’m not sure how good I am at writing tutorials so if anyone gets stuck I’d love to know if something needs making clearer!

Also check out 34SP.com‘s WordPress hosting as we have XDebug ready to run on our servers which helps us to help you debug your site!

Check out the official documentation for a full list of options and features and have a rad time debugging! – https://xdebug.org/docs/

Posted on

The rad time I had at WordCamp Dublin 2017

34SP.com were sponsoring Dublin’s first WordCamp which took place over the last weekend. The WordPress team specifically couldn’t all attend due to other commitments, so the attending team ended up being myself, Siobhan and Pete.

Pete and Siobhan ready for takeoff!
Pete and Siobhan ready for takeoff!

Man, did we have a great time at this one. It was my first time going far enough out with colleagues to warrant flying. It felt particularly important to make it a good one, because without Tim and Keith it made myself the only one from the WordPress team there. So without sounding lame as heck I wanted to make them proud.

We kicked off the adventure by meeting up to get the flight from Manchester to Dublin, Siobhan is a very nervous flyer, so take-off was a bit shady, Pete was ace and stepped in to be comforting and lose a hand to her squeezing. Haha, but after a very quick flight we arrived in Dublin!

We stayed at the Holiday Inn Express near the airport, it was actually just above Santry park so it had a beautiful view as you left the building. The hotel was also one of the few close enough to the venue in relation to what else we were seeing when making out admittedly late booking. So I feel we did well with it.

After freshening up we spent the first day exploring a little of the centre of Dublin, because Pete and Siobhan hadn’t been before. We had an ace time; Hard Rock cafe was doing a vegetarian week which meant they had some great food choices for Siobhan. Can we talk about those amazing buffalo cauliflower wings? I’m still emotional.

We then went for a few drinks in local bars which were recommended by the Hard Rock staff. Dublin is an expensive city, so the staff recommended a bar with a lot of two-for-one offers; Capitol Lounge on Aungier St. It was a good shout, we enjoyed it there and tried another place around the same area which sold some nice ale. Sadly I forget the name of the second place.

Knowing we had to be up the next day we retreated back quite early, and at the time we got in the taxi we then became aware of sponsor’s party for the event. Bad timing meant we missed that, and ended up being so rock ‘n’ roll we played charades until we were tired. Charades was hilarious though, because we were all terrible at it and shouted at each other a lot of our terrible acting.

At the event

We (well I) was up at 6am because I couldn’t pass up the free breakfast at the hotel. Siobhan joined me soon after and we were all ready to leave around 7am. The event was held at the DCU Business school, and we arrived and had the stand set up by 8am ready for people arriving.

Flaunting the last three swag bags.
Flaunting the last three swag bags.

We met some really nice people at WordCamp Dublin. It was fun because we met more new people than usual, being over the water and all. The atmosphere was really relaxed, so much so that I probably felt the most comfortable I ever have leading up to my talk.

I did what was probably my last presentation of ‘Making kitten GIF galleries fabulous‘ for a while, as I feel ready to move on to new talks now. I got some really good feedback on the presentation, as usual. It also meant a lot when we got people afterwards telling me how they found it useful and practical. Queue big smiles!

We were so well looked after by the organisers and the catering. Biscuits, fruit and sweets were readily available. Volunteers checked in to make sure we had everything we needed, helped us with some trouble putting the iPad stand up and helped us get t-shirts even though we were late getting our tickets! They spoilt us really, which we appreciated.

Talks! I went to a couple of talks, one I was particularly eager to listen in on was Tammie’s talk on ‘Getting to know Gutenberg’, as I was a little behind with knowing what all the fuss was about. I’m actually now writing my posts in Gutenberg, because I’m excited about the plugin and it’s development. So I plan to write some reviews and thoughts on that.

Tammie's talk on 'Getting to know Gutenberg'
Tammie’s talk on ‘Getting to know Gutenberg’

I also attended a talk by Gerald Glynn on how to ‘Build a bespoke page builder’, which was him showing a very unique way of using custom post types to create something really special for his clients. I enjoy seeing what people do with the custom post types plugin as it really fires up your imagination for just what you can create in WordPress.

A large chunk of my Sunday was spent at the happiness bar/help desk. As we were advised there were a few people roaming around and looking for help. I spoke to some lovely people there too! I remember offering some image optimisation tips off the back of my talk, helped a lovely lady called Carrie get set up with Yoast and then myself and Robbie enlisted some CSS advice from Julia on the organising team. So I learned some handy helpful tips too. One of the best things about WordCamps is the opportunity to get some really top notch advice from people who use WordPress every day.

Other bits and thoughts

Other highlights of this weekend included the best sushi I have ever eaten: At a local chain restaurant called Musashi. Sadly the chain is exclusive to Dublin at the moment, but the food was beautiful!

Amazing Japanese grub!
Amazing Japanese grub!

This was Pete’s first WordCamp, and he owned it, he was so helpful the entire time, and enjoyed chatting to people about WordPress and our rad support team. He and Siobhan also attended some talks I did not, but I hear really good things about the Lightning Talks specifically.

I totally needed this WordCamp. I’ve been in a minor rut lately because I’ve been working hard to pass some exams and I’m struggling to get there. No big deal really, but WordCamp Dublin has rejuvenated my enthusiasm and interest in learning.

I remember the first time I attended a WordCamp with 34SP.com, it was WordCamp Manchester a few years back, and I remember being inspired as heck because I was genuinely thrilled to be working in web hosting, and with WordPress daily.

Man I sound so lame, but I used to spend so much time when I was younger playing with websites and learning about how the web worked, it’s easy to lose sight of how thrilling that is when you hit a bump. So uh, yeah! A big thanks for WordCamp Dublin and it’s organisers for making me feel energised and excited to learn more and work hard. 🙂 


 

Posted on

Adventures at WordCamp Edinburgh

So the WordPress team wandered up to Edinburgh over the weekend. Myself, Keith, Tim and Siobhan got the train up on Friday and stayed until Monday afternoon. Long weekend! It was rad though, here’s what we got up to:

We arrived early in the afternoon on Friday. Siobhan had booked us an AirBNB – I’m getting SO in to AirBNBs, by the way. Because it was nice to have this big four bed apartment to ourselves where we can hang around together, rather than having separate hotel rooms where you wander off to be on your own every evening. Instead we sat around having cups of tea and talking about the talks and people we spoke to at the event.

The event started early Saturday morning. I didn’t attend WordCamp Edinburgh last year, so it was my first one. I loved the venue – CodeBase was a really nice, relaxed space for the conference. It reminded me of our own Nexus Art Cafe in Manchester. Mostly because of all the beanbags and comfy comfy furniture, but with the plan to inspire techies. There were retro game machines and 1970’s Macintosh computers. I loved the space.

We put up our stand and on offer were some limited edition Wapuu stickers, notepads, pens and t-shirts. But importantly we were talking to people about our managed WordPress Hosting

I did talk on ‘Making WordPress fly with Jetpack‘  – which was well received by most of the people I spoke to, so that was pretty great. Tim did his practical security talk which is always a nice one to do – plenty of handy tips anyone can do to keep their sites safe.

Amongst the talks, was one I really, really enjoyed. Rachel Martin did a talk on ‘Blogging as therapy’ where she spoke about how using her site to blog about a traumatic event in real life helped her cope. It was nice to see a talk more aimed around just blogging, and blogging because you enjoy it. Also writing when times are tough is something I enjoyed hearing about, because I do a whole bunch of creative writing when I’ve got stuff on my mind. So yeah it was just a really interesting and relatable talk.

There were some great restaurants around Edinburgh. Most notably was Loudons Cafe. This was recommended to us by another WordCamper as a great place to get Breakfast. It was amazing! I had French Toast one day and fruit pancakes another. Loved it there! We were also well catered for by the WordCamp itself – loads of sandwiches and nibbles at the after party. I ate too much this weekend. But it’s okay.

On the way home from WordCamp Edinburgh I was feeling a little mischievous. Out hotel was situated right beside Edinburgh Castle, which is situated on a hill. So every time we saw the castle (a freakin’ lot!) I kept singing Ed Sheeran’s ‘Castle on the hill’ song. Siobhan was kinda losing her mind. So in our boredom Keith and I set up a script on my laptop to auto-send her random Ed Sheeran lyrics. It quickly got turned off when she turned around and gave me the death stare. Fun, though!

Overall I had a great weekend. WordCamp Edinburgh was really well organised, and felt really relaxed. We chatted to some really nice members of the community, who I hope so see again next year!