Skip to content

Instantly share code, notes, and snippets.

@matheusb-comp
Created April 28, 2021 22:43
Show Gist options
  • Save matheusb-comp/045b1d4c8fdc6a161d5c7cd53d505ff3 to your computer and use it in GitHub Desktop.
Save matheusb-comp/045b1d4c8fdc6a161d5c7cd53d505ff3 to your computer and use it in GitHub Desktop.
PHP wrapper to load libreadline at runtime
#!/bin/sh
# PHP installed in AWS EC2 using Amazon-Linux-Extras is compiled with:
# --without-readline --with-libedit
#
# However, for some reason, libedit doesn't accept UTF-8 input:
# https://github.com/bobthecow/psysh/issues/148
#
# Instead of building PHP from the source code, apparently libreadline
# can just be preloaded when running PHP:
# https://stackoverflow.com/q/28003239/12869323#comment44417638_28003239
#
# So the PHP executable can be renamed and wrapped by this script:
# $ sudo mv /usr/bin/php /usr/bin/php-bin
# $ sudo mv php-wrapper /usr/bin/php
# $ sudo chown root:root /usr/bin/php
# $ sudo chmod +x /usr/bin/php
export LD_PRELOAD=/usr/lib64/libreadline.so.6
exec php-bin "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment