PHP

From Han Wiki
Revision as of 11:45, 24 April 2018 by Mhan (talk | contribs) (→‎Installing mcrypt on PHP 7.2)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Jump to navigation Jump to search

CLI

Show errors when executing in CLI

$ php -d display_errors myscript.php

PHP 7.2

Installing mcrypt on PHP 7.2 FPM

  • Last tested on Ubuntu 16.04.4 LTS (xenial)
  1. install required packages
    mhan@host:~/dev $ sudo apt-get -y install gcc make autoconf libc-dev pkg-config
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    Note, selecting 'libc6-dev' instead of 'libc-dev'
    autoconf is already the newest version (2.69-9).
    gcc is already the newest version (4:5.3.1-1ubuntu1).
    make is already the newest version (4.1-6).
    pkg-config is already the newest version (0.29.1-0ubuntu1).
    libc6-dev is already the newest version (2.23-0ubuntu10).
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    
    mhan@host:~/dev $ sudo apt-get -y install libmcrypt-dev
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    libmcrypt-dev is already the newest version (2.5.8-3.3).
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    
    mhan@host:~/dev $ sudo apt-get install php7.2-dev
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following NEW packages will be installed:
      php7.2-dev
    0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
    Need to get 557 kB of archives.
    After this operation, 5,669 kB of additional disk space will be used.
    Get:1 http://ppa.launchpad.net/ondrej/php/ubuntu xenial/main amd64 php7.2-dev amd64 7.2.4-1+ubuntu16.04.1+deb.sury.org+1 [557 kB]
    Fetched 557 kB in 1s (475 kB/s)
    [master 5187285] saving uncommitted changes in /etc prior to apt run
     4 files changed, 10 insertions(+), 4 deletions(-)
    Selecting previously unselected package php7.2-dev.
    (Reading database ... 176836 files and directories currently installed.)
    Preparing to unpack .../php7.2-dev_7.2.4-1+ubuntu16.04.1+deb.sury.org+1_amd64.deb ...
    Unpacking php7.2-dev (7.2.4-1+ubuntu16.04.1+deb.sury.org+1) ...
    Processing triggers for man-db (2.7.5-1) ...
    Setting up php7.2-dev (7.2.4-1+ubuntu16.04.1+deb.sury.org+1) ...
    update-alternatives: using /usr/bin/php-config7.2 to provide /usr/bin/php-config (php-config) in auto mode
    update-alternatives: using /usr/bin/phpize7.2 to provide /usr/bin/phpize (phpize) in auto mode
    [master b808f2b] committing changes in /etc after apt run
     4 files changed, 4 insertions(+), 4 deletions(-)
    
  2. install mcrypt-1.0.1
    mhan@host:~/dev $ sudo pecl install mcrypt-1.0.1
    WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
    downloading mcrypt-1.0.1.tgz ...
    Starting to download mcrypt-1.0.1.tgz (33,782 bytes)
    .........done: 33,782 bytes
    6 source files, building
    running: phpize
    Configuring for:
    PHP Api Version:         20170718
    Zend Module Api No:      20170718
    Zend Extension Api No:   320170718
    libmcrypt prefix? [autodetect] :
    building in /tmp/pear/temp/pear-build-rootD4MO1w/mcrypt-1.0.1
    running: /tmp/pear/temp/mcrypt/configure --with-php-config=/usr/bin/php-config --with-mcrypt
    checking for grep that handles long lines and -e... /bin/grep
    checking for egrep... /bin/grep -E
    checking for a sed that does not truncate output... /bin/sed
    checking for cc... cc
    checking whether the C compiler works... yes
    checking for C compiler default output file name... a.out
    checking for suffix of executables...
    checking whether we are cross compiling... no
    ...
    If you ever happen to want to link against installed libraries                                                                                         [3/531]
    in a given directory, LIBDIR, you must either use libtool, and
    specify the full pathname of the library, or use the '-LLIBDIR'
    flag during linking and do at least one of the following:
       - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
         during execution
       - add LIBDIR to the 'LD_RUN_PATH' environment variable
         during linking
       - use the '-Wl,-rpath -Wl,LIBDIR' linker flag
       - have your system administrator add LIBDIR to '/etc/ld.so.conf'
    
    See any operating system documentation about shared libraries for
    more information, such as the ld(1) and ld.so(8) manual pages.
    ----------------------------------------------------------------------
    
    Build complete.
    Don't forget to run 'make test'.
    
    running: make INSTALL_ROOT="/tmp/pear/temp/pear-build-rootD4MO1w/install-mcrypt-1.0.1" install
    Installing shared extensions:     /tmp/pear/temp/pear-build-rootD4MO1w/install-mcrypt-1.0.1/usr/lib/php/20170718/
    running: find "/tmp/pear/temp/pear-build-rootD4MO1w/install-mcrypt-1.0.1" | xargs ls -dils
    26300   4 drwxr-xr-x 3 root root   4096 Apr 24 11:14 /tmp/pear/temp/pear-build-rootD4MO1w/install-mcrypt-1.0.1
    27940   4 drwxr-xr-x 3 root root   4096 Apr 24 11:14 /tmp/pear/temp/pear-build-rootD4MO1w/install-mcrypt-1.0.1/usr
    27945   4 drwxr-xr-x 3 root root   4096 Apr 24 11:14 /tmp/pear/temp/pear-build-rootD4MO1w/install-mcrypt-1.0.1/usr/lib
    28355   4 drwxr-xr-x 3 root root   4096 Apr 24 11:14 /tmp/pear/temp/pear-build-rootD4MO1w/install-mcrypt-1.0.1/usr/lib/php
    28368   4 drwxr-xr-x 2 root root   4096 Apr 24 11:14 /tmp/pear/temp/pear-build-rootD4MO1w/install-mcrypt-1.0.1/usr/lib/php/20170718
    27762 164 -rwxr-xr-x 1 root root 164976 Apr 24 11:14 /tmp/pear/temp/pear-build-rootD4MO1w/install-mcrypt-1.0.1/usr/lib/php/20170718/mcrypt.so
    
    Build process completed successfully
    Installing '/usr/lib/php/20170718/mcrypt.so'
    install ok: channel://pecl.php.net/mcrypt-1.0.1
    configuration option "php_ini" is not set to php.ini location
    You should add "extension=mcrypt.so" to php.ini
    
  3. create a /etc/php/7.2/mods-available/mcrypt.ini
    ; configuration for php mcrypt module
    ; priority=20
    extension=mcrypt.so
    
  4. create a symlink for mcrypt under fpm
    root@hydrogen:/etc/php/7.2# cd fpm/conf.d
    root@hydrogen:/etc/php/7.2/fpm/conf.d# ln -s ../../mods-available/mcrypt.ini 20-mcrypt.ini
    
  5. restart fpm service
    root@hydrogen:/etc/php/7.2/fpm/conf.d# systemctl restart php7.2-fpm.service