PHP allows you to execute arbitrary external programs using
exec. This is great for when you need to do something beyond what is possible to do with PHP alone.
For instance, let’s say you needed to do some PDF manipulation. You might find that a program like QPDF suits your needs. If you install QPDF on your server you can call it from PHP simply by using
exec. For example:
The Inaccessible VPS
I’ve recently been developing a web application for a client that involves a lot of custom PDF processing. At this moment, we’re using three different PDF manipulation libraries/programs to fulfill the needs of this site. Unfortunately, there is no single PDF library that handles all of our needs for this application.
Thankfully, the client has elected to use a VPS. The great thing about using a VPS is it gives you full control over the entire server, allowing maximum flexibility to use any third-party libraries we need.
Unfortunately, however, the client chose to use the same company they purchased their domain name from as their VPS provider. You might know them from their Super Bowl ads. Or their support of SOPA. Or that time their CEO shot and killed an elephant. Or perhaps one of the other controversies they’ve been involved in.
The client also chose the $129.99/month “assisted service plan” which removes root access to the server in exchange for allowing the company’s “expert staff” (more on them later) to manage it on your behalf. You can’t even access the server via SSH. Instead, you are given access to a Plesk control panel, but you don’t even get full access to that — most of the interesting settings are locked out.
So one of the major reasons for picking a VPS — direct, unrestricted control — isn’t even available.
Ok, so, giving them the benefit of the doubt, maybe dealing with support every time you need to run a command on the server isn’t so bad (bear with me here). Maybe we can even forgive the minimum 24-72 hour turnaround time (longer than any host I’ve ever dealt with) as long as they do what you need.
exec was disabled by default, but they enabled it for us. Great. We asked to have PDFtk installed, they installed it. Well, first they told us they couldn’t install it because it’s a Windows program (all you have to do is scroll a bit to see the Linux version). Not exactly confidence-inspiring, but after getting our support request escalated and pointing out the Linux version, a few days later, we had it up and running.
We later found that we would need QPDF as well to unlock encrypted PDFs. (PDFtk can do this too, but, unlike QPDF, it requires the original encryption password.) So we submitted another support ticket. While they did at least recognize QPDF is available for Linux, they refused to install it because “we can’t install any application that require [sic] us to compile it on the server.”
Of course, QPDF binaries are available from a number of places. This is a CentOS 6 server, and QPDF can even be installed directly from the EPEL repository.
Breaking New Ground
Sadly, supplying ready-to-install binaries still wouldn’t be enough to convince support to install QPDF.
At this point you might be wondering why we hadn’t already moved to another host, and, indeed, if it were up to me, we would have moved this site long before this set of issues. Unfortunately it isn’t up to me, and the client still wants to use the original VPS. I suspect it’s because they agreed to a one or two-year contract with this provider.
Anyway, back to QPDF. Support replied saying they still couldn’t install it because, while they were able to find documentation showing examples of using PDFtk from a web application (presumably using a wrapper such as this), they couldn’t find any documentation that indicated QPDF could be used in the same way. Evidently nobody has ever called QPDF from PHP before (or, more likely, it’s just that nobody has posted PHP examples of it because of how trivial it is to use via
So that is the reason for this post: to provide public documentation showing how QPDF could conceivably be used from a web application. It’s apparently impossible to program anything without ready-to-go examples from documentation, blog posts, or Stack Overflow.
Don’t Do This
Seriously. Use a reputable web hosting company. Web hosting is a horrible business, but, at the very least, you can save yourself a lot of headaches by not buying it from the long list of “services” your domain registrar tries to sell you during checkout.
I used Liquid Web for nearly 10 years and, even with managed servers, I’ve never had to try to convince them to install something. They’re not scared to give you root access. Even when I would screw something up, they were always happy to help, and even explain the steps they took to fix it.
I’ve recently started moving some sites to Linode. I haven’t had to use their support yet, but even if you choose their paid managed support, you still retain root access to your servers.
If nothing else, if you’re hosting something big enough to need a VPS, at least make sure you have root access. That way, if support turns out to be incompetent, you can at least go in and fix things yourself.
Update: QPDF has been installed! Total time from first request: 15 days.