How to solve Fatal error: Call to undefined function readline()? readline library not found?

8,969

Solution 1

The default php builds on ubuntu use libedit and instead of readline. (Due to some licensing issue)

To get the readline support you can download the source and build it

Solution 2

This worked just fine for me on Ubuntu 12.10:

sudo apt-get install php5-readline
Share:
8,969

Related videos on Youtube

SirBT
Author by

SirBT

Updated on September 18, 2022

Comments

  • SirBT
    SirBT over 1 year

    I have an Ubuntu 12.04 LTS. And XAMPP for linux 1.7.7.

    When I code in php with and call the readline function I get this error message? "Fatal error: Call to undefined function readline()"

    I recently found the below thread which pointed out the name of the package that contained the desired readline: How to solve configure: error: readline library not found?

    I went ahead and installed # apt-get install libreadline6. But this didnt seem to make a difference. I still get the same error message: "Fatal error: Call to undefined function readline()". Was the thread missing further steps? Can anyone help me?

    I am new to Ubuntu.

    <?php
    
    echo "Simple menu \n" ;
    
    echo "1. Play Sports \n";
    echo "2. Play Strategy games \n";
    
    $userInput = readline('Enter something here: ');
    
    ?>
    
    • devav2
      devav2 over 11 years
      which version of php are you using?
    • SirBT
      SirBT over 11 years
      @Devav2 The PHP version I use is: PHP 5.3.8
  • Lekensteyn
    Lekensteyn over 11 years
    This is only useful if you are actually building a program with readline support. Just installing it does not magically make PHP support the readline extension.
  • SirBT
    SirBT over 11 years
    any suggestions on how to build it? Any help is greatly appreciated.
  • SirBT
    SirBT over 11 years
    @green7 If you read the beginning of the thread, I did mention that I did install it using: sudo apt-get install libreadline6-dev.
  • SirBT
    SirBT over 11 years
    @Lekensteyn How do I build a program with readline support? Doesn't the little program in the initial thread count as a program with readline support?
  • devav2
    devav2 over 11 years
    Found this link online. This might help you.
  • green
    green over 11 years
    @SirBT No, you didn't.
  • Lekensteyn
    Lekensteyn over 11 years
    @SirBT Only if PHP was compiled with readline support enabled. In that case the binary would depend on libreadline.so.6 and therefore requiring the libreadline6 package.
  • Ryre
    Ryre almost 10 years
    Worked for me as well!