Recommended way to install additional binaries, to run them from PHP


I asked this question a while ago, but I never got a reply: How to install additional packages / binaries in the instances of local sites?. However, it would be great :slight_smile:

I would like to install binaries such as jpegoptim and pngquant for optimization purposes. What is the recommended way to do this?

Thanks a lot for your help!

Hi @TigrouMeow,

Sorry for any oversight in previous questions! It seems like you’re asking a general question about using command-line utilities to help develop your Wordpress site, and a specific question about image optimization.

As far as using specific command line tools, that’s something you’d have to set up yourself as part of your development flow. For example, you could set up a custom bash script or use a PHP wrapper class to interact with the tools via PHP. Note that Local does ship with Composer, which you can utilize via a site’s Site Shell if you don’t already have it globally installed.

That being said, Local does have an Image Optimizer Add-On that you can install today! It handles lossless compression of jpeg files in the wp-content/uploads folder. The code for that add-on is publicly available if you’re interested in seeing how it operates or want to explore adapting it for your particular use case. There are also several Wordpress plugins that take care of image optimization, so I’d definitely recommend exploring that option!

Let me know there’s anything else we can help with, and feel free to submit a feature request if you think there’s something Local should be doing to make this easier.

Thanks for your reply :slight_smile: I am actually building plugins, so I don’t need to optimize images for my own sake, but I am using Local as a dev environment and I need this in order to pursue the development of my plugins. I am not looking for alternatives; of course, I know about them.

It means that I absolutely need to install jpegoptim (and others) on my Local environment, and I need to be able to run it through the shell that I can access through Local. And of course, I’ll run those using PHP as well.

Is there any way to install additional librairies?

Alternatively, if you could let me another way to make those librairies available in Local, that’s also okay: jpegoptim, jpegtran, optipng, pngquant, svgo, gifsicle, webp.

Thanks :slight_smile: