Nitropack is quickly becoming a required plugin/service for websites these days. We’re seeing more and more clients want to use it. If you’ve never heard of it, check out their website - the brief summary is that they can speed up your website and help you improve your Pagespeed score.

One of the things we really like is that it has a great Wordpress plugin already made and it works together with CloudFlare - they are different enough that you can have both enabled at the same time.

All that said, the jury is still out on whether Nitropack actually does anything helpful. Having high Pagespeed scores also doesn’t mean that your website scores highly in real-world tests. There are also reports, though I can’t verify them, that Nitropack is bad for SEO. We’re currently testing it at the time of writing this and have not seen any negative or positive impact on SEO.

But this blog post isn’t about Nitropack itself, it's about the process of installing the Nitropack PHP SDK on a custom PHP website. Our website is not using any CMS - we custom-coded ours in PHP and therefore cannot use any of the pre-coded plugins Nitropack has. So, depending on how your website was coded, your installation may be different but will generally be the same.

Here’s how to install the Nitropack PHP SDK

1. Grab The PHP SDK

The official download link is here. These files are a Composer package that should be installed with Composer command line tool. If you do not have that or are not able to use that, you can grab an uploadable version here, which is based on this refactored version of the original at this Git.

Keep in mind, regardless of how you install it it will be using the Composer system. This comes up in Step 3.

2. Install with Composer or upload files

Depending on which version you want to go with, you’ll either use Composer or upload the files. If you’re uploading the files, make sure it’s in the root directory of your website or wherever your homepage lives.

3. Add code to all pages

Remeber that this will be using Composer so you’ll need to add this code to all files/pages where you want to use Nitropack.

<?php
//this is for the official version
require_once('autoload.php');

//fill these in. you can find them in your dashboard.
$nitro = new NitroPack\SDK\NitroPack('your_site_id', 'your_site_secret');

//if your page has a layout name that gets reused throughout the site, put it here
$layout = ‘name’;

if ($nitro->hasCache($layout)) {
    $nitro->pageCache->readfile();
    exit;
}
?>

<?php
//this is for the uploadable version
require_once("vendor/autoload.php");

use NitroPack\NitroPack;

//fill these in. you can find them in your dashboard.
$nitro = new NitroPack('your_site_id', 'your_site_secret');

//if your page has a layout name that gets reused throughout the site, put it here
$layout = ‘name’;

if ($nitro->hasCache($layout)) {
    $nitro->pageCache->readfile();
    exit;
}
?>

4. Wait for Nitropack to Connect

Check your dashboard for the messages about how many pages have been optimized and what the current status is. If you get errors, check out the section below on troubleshooting.

Optimizing pages can take a while but we found a way to speed it up - Cache Warmup! Check the next Step.

5. Speed up Optimizing with Cache Warmup

If you haven’t set this up, Nitropack is just going to guess the pages on your website. Before we set this up, it was looking for Wordpress system pages that our website doesn’t have...because it’s not Wordpress. But Nitropack wastes time looking for tons of pages that don’t exist.

A requirement for this step is that you have a sitemap on your website. It must be an XML file extension. 

Once you have that, head on over to the Cache Warmup settings page in your dashboard and click that “play” icon button, switch the toggle for “Cache warmup status” to on/green, and then put in your homepage URL and your sitemap URL.

Nitropack PHP SDK Installation Problems

File_put_contents() permission issues

If you’re installing the PHP SDK, there’s a good chance you’re on a custom server that has its own set of permissions challenges. You just have to make sure the web user for your server has permission to write to the “data” folder inside the Nitropack folder. The data folder is where it stores static versions of your pages so it needs access and owner/group permissions of 775 or 755.

The Nitropack dashboard says it’s not connected.

This is probably an issue with installation. Make sure you put the files and code in the correct place.

There’s a Nitropack bar in my footer, how do I remove that?

You have to upgrade to a paid plan and then clear the cache.