Install PECL modules without the prompts
Asked Answered
N

4

100

I just installed PHP on Ubuntu Natty from source.

I'm trying to use PECL to install additional modules like APC and Memcache. I'm using something like this:

pecl install apc

However, I get prompts asking me to confirm things.

How can I use the pecl command to just accept the defaults? I saw something like this on a message board: printf "yes\n" | pecl install pecl_http. However, in the case of APC this would answer yes for things where the default is no (I think).

Nisse answered 15/11, 2011 at 18:43 Comment(2)
@Gordon: I tried that but there doesn't seem to be a handle for what I need.Nisse
For the case where the default values are acceptable, in non interactive mode, PECL prompt is not required. For example, if you add to a Dockefile RUN pecl install apc, at build time, you'll get the default values automatically selected.Kennethkennett
N
99

The following code seems to work ok:

printf "\n" | pecl install apc

You can also replace apc with any other PECL package.

Cheers.

Nisse answered 16/11, 2011 at 15:49 Comment(3)
I'm also seeing success with yes | pecl install memcache -- although I suppose your solution works better for packages where the default is something other than "yes"Mckeehan
Thanks dude, this even worked with CircleCILitigate
Worked for me since I'm installing the extension in a docker container! Thanks!Divulsion
K
96

The "yes" command can do more than just type "yes"; it can type anything you want, over and over. Including an empty line, which is a good way to accept defaults.

I just needed this myself, so here is what worked well for me:

yes '' | pecl install -f apc
Knee answered 9/2, 2014 at 22:41 Comment(4)
Thanks for the input, Tom. Was your code meant to be "yes\n" | pecl install -f apc?!Nisse
@ObinwanneHill: Tom was referring to the yes command. The benefit of this over printf is that it generates output repeatedly, which makes it more portable should the pecl installer prompt for additional questions than your scripted printf expected.Treva
@Treva Oh I see, was not familiar with that command. ThanksNisse
The problem comes when you want a NO instead of a YES in any of the optionsAmphoteric
S
22

If you don't want give the same answer for every single prompt ("yes", "no", or ""), you can use --configureoptions to set specific values for each option (see the PECL manual).

You'll want to find your package's package.xml file to see what options are configurable. As an example, for the memcached package, you'd go here:

https://github.com/php-memcached-dev/php-memcached/blob/master/package.xml

Search for the <configureoption> tags, which in this case are:

<configureoption name="with-libmemcached-dir"     prompt="libmemcached directory"     default="no"/>
<configureoption name="with-zlib-dir"             prompt="zlib directory"             default="no"/>
<configureoption name="with-system-fastlz"        prompt="use system fastlz"          default="no"/>
<configureoption name="enable-memcached-igbinary" prompt="enable igbinary serializer" default="no"/>
<configureoption name="enable-memcached-msgpack"  prompt="enable msgpack serializer"  default="no"/>
<configureoption name="enable-memcached-json"     prompt="enable json serializer"     default="no"/>
<configureoption name="enable-memcached-protocol" prompt="enable server protocol"     default="no"/>
<configureoption name="enable-memcached-sasl"     prompt="enable sasl"                default="yes"/>
<configureoption name="enable-memcached-session"  prompt="enable sessions"            default="yes"/>

You can then pass these options along to the install command like so:

pecl install --configureoptions 'with-libmemcached-dir="no" with-zlib-dir="no" with-system-fastlz="no" enable-memcached-igbinary="yes" enable-memcached-msgpack="no" enable-memcached-json="no" enable-memcached-protocol="no" enable-memcached-sasl="yes" enable-memcached-session="yes"' memcached
Sero answered 14/7, 2022 at 13:47 Comment(0)
M
10

Obinwanne's Hill answer nailed it for me, so I'm not providing anything new here, but the following seems like the absolute shortest also without any fancy tools.

echo '' | pecl install apc
Minnick answered 11/11, 2015 at 9:23 Comment(2)
A shorter alternative to achieve the same result is: pecl install apc <<<''Belloc
You can go even shorter echo | pecl install apc, without the ''. Cheers!!Natatorium

© 2022 - 2024 — McMap. All rights reserved.