Welcome to Centmin Mod Community
Register Now

PHP-FPM PHP 7 compatibility wrapper for deprecated mysql extension

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by joshuah, Apr 27, 2017.

  1. joshuah

    joshuah Member

    121
    14
    18
    Apr 3, 2017
    Ratings:
    +17
    Local Time:
    6:42 PM
    Hello,

    Just wondering if you could confirm if the following works (or an alternative)?

    How to put MySQL functions back into PHP 7

    I have a website that still runs on mysql_connect, mysql_numrows etc. and dont have the time to convert it (it's a private website, not public facing).

    I am running PHP 7.0.17 on the server.

    Thanks.

     
  2. eva2000

    eva2000 Administrator Staff Member

    50,478
    11,663
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,088
    Local Time:
    6:42 PM
    Nginx 1.25.x
    MariaDB 10.x
    haven't tried it myself so not sure. Will check it out
     
  3. joshuah

    joshuah Member

    121
    14
    18
    Apr 3, 2017
    Ratings:
    +17
    Local Time:
    6:42 PM
    Awesome, thanks mate.
     
  4. eva2000

    eva2000 Administrator Staff Member

    50,478
    11,663
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,088
    Local Time:
    6:42 PM
    Nginx 1.25.x
    MariaDB 10.x
    Testing adding legacy mysql extesion to PHP 7.1.4

    Code (Text):
    php -v
    PHP 7.1.4 (cli) (built: Apr 13 2017 21:43:15) ( NTS )
    Copyright (c) 1997-2017 The PHP Group
    Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
        with Zend OPcache v7.1.4, Copyright (c) 1999-2017, by Zend Technologies
    


    Actual install steps as per How to put MySQL functions back into PHP 7 just tailored for Centmin Mod PHP-FPM installs. You will have to do these manual steps everytime you upgrade PHP.

    Code (Text):
    # http://php.net/manual/en/mysql.php
    # http://php.net/manual/en/mysql.installation.php
    # http://php.net/manual/en/mysqlinfo.api.choosing.php
    # https://ckon.wordpress.com/2015/08/06/put-mysql-functions-back-into-php-7/
    # https://github.com/php/pecl-database-mysql
    cd /svr-setup/php-7.1.4/ext
    git clone https://github.com/php/pecl-database-mysql mysql --recursive
    cd /svr-setup/php-7.1.4/ext/mysql
    phpize
    ./configure --with-php-config=/usr/local/bin/php-config
    make
    make install
    echo "extension=mysql.so" > /etc/centminmod/php.d/mysql.ini
    fpmrestart
    php --ri mysql
    


    Unfortunately phpinfo for mysql shows the updated newer mysqlnd native instead of legacy mysql extension as Centmin Mod php-fpm is compiled with newer mysqlnd native driver

    Code (Text):
    php --ri mysql
    
    mysql
    
    MySQL Support => enabled
    Active Persistent Links => 0
    Active Links => 0
    Client API version => mysqlnd 5.0.12-dev - 20150407 - $Id: b396954eeb2d1d9ed7902b8bae237b287f21ad9e $
    
    Directive => Local Value => Master Value
    mysql.allow_persistent => On => On
    mysql.max_persistent => Unlimited => Unlimited
    mysql.max_links => Unlimited => Unlimited
    mysql.default_host => no value => no value
    mysql.default_user => no value => no value
    mysql.default_password => no value => no value
    mysql.default_port => no value => no value
    mysql.default_socket => /var/lib/mysql/mysql.sock => /var/lib/mysql/mysql.sock
    mysql.connect_timeout => 60 => 60
    mysql.trace_mode => Off => Off
    mysql.allow_local_infile => On => On
    


    However, php list extension module command does report mysql extension as loaded so you will have to test your web app which utilises legacy mysql extension to see

    Code (Text):
    php -m
    [PHP Modules]
    bcmath
    bz2
    calendar
    Core
    ctype
    curl
    date
    dom
    enchant
    exif
    filter
    ftp
    gd
    geoip
    gettext
    gmp
    hash
    iconv
    igbinary
    imagick
    imap
    intl
    json
    ldap
    libxml
    mailparse
    mbstring
    mcrypt
    memcache
    memcached
    mysql
    mysqli
    mysqlnd
    openssl
    pcntl
    pcre
    PDO
    pdo_mysql
    pdo_sqlite
    Phar
    posix
    pspell
    readline
    redis
    Reflection
    session
    shmop
    SimpleXML
    snmp
    soap
    sockets
    SPL
    sqlite3
    standard
    sysvmsg
    sysvsem
    sysvshm
    tidy
    tokenizer
    xml
    xmlreader
    xmlrpc
    xmlwriter
    xsl
    Zend OPcache
    zip
    zlib
    
    [Zend Modules]
    Zend OPcache
    


    if you need to temp disable legacy mysql extension comment out with semi-colon ; in from of load extension line in mysql extension .ini file at /etc/centminmod/php.d/mysql.ini and restart php-fpm
    Code (Text):
    ;extension=mysql.so
    
     
  5. joshuah

    joshuah Member

    121
    14
    18
    Apr 3, 2017
    Ratings:
    +17
    Local Time:
    6:42 PM
    Awesome mate, worked great :)
     
  6. eva2000

    eva2000 Administrator Staff Member

    50,478
    11,663
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,088
    Local Time:
    6:42 PM
    Nginx 1.25.x
    MariaDB 10.x
    Great to hear.. might add it to php upgrade routine to prompt users if they want to add legacy mysql extension for php 7.x installs :)
     
  7. joshuah

    joshuah Member

    121
    14
    18
    Apr 3, 2017
    Ratings:
    +17
    Local Time:
    6:42 PM
    Awesome! Just curious though, I was just checking into a little more and now a little concerned...

    "Although it should be possible to build this extension with PHP 7.0, you are strongly encouraged to port your code to use either MySQLi or PDO_MySQL, as this extension is not maintained and is available for historical reasons only."

    Would it be better to build the extension rather than use their code? *shrugs*
     
  8. eva2000

    eva2000 Administrator Staff Member

    50,478
    11,663
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,088
    Local Time:
    6:42 PM
    Nginx 1.25.x
    MariaDB 10.x
    what they mean at GitHub - php/pecl-database-mysql: Legacy MySQL extension, is you should update your web app/script to support newer mysqli and pdo_mysql extension and not rely on this legacy mysql extension compiled into PHP 7.
     
  9. joshuah

    joshuah Member

    121
    14
    18
    Apr 3, 2017
    Ratings:
    +17
    Local Time:
    6:42 PM
    I was referring more to "as this extension is not maintained and is available for historical reasons only."

    And "Warning: This extension is deprecated and unmaintained."
     
  10. eva2000

    eva2000 Administrator Staff Member

    50,478
    11,663
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,088
    Local Time:
    6:42 PM
    Nginx 1.25.x
    MariaDB 10.x
    yes mysql extension is deprecated hence it's removal from PHP 7 :)
     
  11. joshuah

    joshuah Member

    121
    14
    18
    Apr 3, 2017
    Ratings:
    +17
    Local Time:
    6:42 PM
    What's your thoughts on running it, security wise?
     
  12. eva2000

    eva2000 Administrator Staff Member

    50,478
    11,663
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,088
    Local Time:
    6:42 PM
    Nginx 1.25.x
    MariaDB 10.x
    Well mysql extension is still in PHP 5.6 and is okay. Though most modern web app/scripts have moved to mysqli/mysqlnd or PDO mysql extension method of PHP communication with MySQL server. So having mysql extension in PHP doesn't matter.
     
  13. joshuah

    joshuah Member

    121
    14
    18
    Apr 3, 2017
    Ratings:
    +17
    Local Time:
    6:42 PM
    Thanks mate. Yeah I think you should add it to the routine for upgrades.. would save time needing to manually do this every upgrade.
     
  14. eva2000

    eva2000 Administrator Staff Member

    50,478
    11,663
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,088
    Local Time:
    6:42 PM
    Nginx 1.25.x
    MariaDB 10.x
    Just about to commit the update to 123.09beta01 branch for php upgrades detecting PHP 7+. You'll be prompted to whether you want to install legacy mysql extension for PHP 7+
    Code (Text):
    PHP 7+ detected which uses newer mysqlnd
    or PDO MySQL extensions and removed the
    legacy mysql extension. You can optionally
    re-add the removed legacy mysql extension
    to PHP 7+ by answering yes to next question
    Only answer yes if you know for sure you
    have very old web scripts which need mysql
    legacy extension re-added. Otherwise answer
    no which is recommended for best stability
    
    Re-add legacy mysql extension to PHP 7+ [y/n] ? y
    

    It gets installed into PHP 7+ binary itself so no need for separate /etc/centminmod/php.d/mysql.ini settings file to load mysql.so extension this way. Confirm mysql extension is loaded via listing php loaded extensions and look for = mysql
    Code (Text):
    php -m
    

    Code (Text):
    php -m
    [PHP Modules]
    bcmath
    bz2
    calendar
    Core
    ctype
    curl
    date
    dom
    enchant
    exif
    filter
    ftp
    gd
    geoip
    gettext
    gmp
    hash
    iconv
    igbinary
    imagick
    imap
    intl
    json
    ldap
    libxml
    mailparse
    mbstring
    mcrypt
    memcache
    memcached
    mysql
    mysqli
    mysqlnd
    openssl
    pcntl
    pcre
    PDO
    pdo_mysql
    pdo_sqlite
    Phar
    posix
    pspell
    readline
    redis
    Reflection
    session
    shmop
    SimpleXML
    snmp
    soap
    sockets
    SPL
    sqlite3
    standard
    sysvmsg
    sysvsem
    sysvshm
    tidy
    tokenizer
    xml
    xmlreader
    xmlrpc
    xmlwriter
    xsl
    Zend OPcache
    zip
    zlib
    
    [Zend Modules]
    Zend OPcache
    
     
  15. joshuah

    joshuah Member

    121
    14
    18
    Apr 3, 2017
    Ratings:
    +17
    Local Time:
    6:42 PM
    awesome news mate. Can you please confirm, once I upgrade from the current branch, do I just remove the existing file: /etc/centminmod/php.d/mysql.ini and then do the upgrade? I just dont want anything to conflict.
     
  16. eva2000

    eva2000 Administrator Staff Member

    50,478
    11,663
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,088
    Local Time:
    6:42 PM
    Nginx 1.25.x
    MariaDB 10.x
    yup correct.. if /etc/centminmod/php.d/mysql.ini is still there afterwards, restarting php-fpm gives error
    Code (Text):
    PHP Warning:  Module 'mysql' already loaded in Unknown on line 0
    

    remove /etc/centminmod/php.d/mysql.ini and restart php-fpm should be fine
     
  17. joshuah

    joshuah Member

    121
    14
    18
    Apr 3, 2017
    Ratings:
    +17
    Local Time:
    6:42 PM
    Thanks. Doing the upgrade now :)
     
  18. joshuah

    joshuah Member

    121
    14
    18
    Apr 3, 2017
    Ratings:
    +17
    Local Time:
    6:42 PM
    hmm.. odd.. i just installed 7.0.18 (I had 7.0.17 before upgrade). After install, /etc/centminmod/php.d/mysql.ini was present. I removed it, and restarted php-fpm and then the website that uses mysql_* stopped working. I added back the /etc/centminmod/php.d/mysql.ini file with the extension=mysql.so and then it started working again..
     
  19. eva2000

    eva2000 Administrator Staff Member

    50,478
    11,663
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,088
    Local Time:
    6:42 PM
    Nginx 1.25.x
    MariaDB 10.x
  20. joshuah

    joshuah Member

    121
    14
    18
    Apr 3, 2017
    Ratings:
    +17
    Local Time:
    6:42 PM
    tells me i am already up to date.