Building PHP - linux-on-ibm-z/docs GitHub Wiki

Building PHP

Below versions of PHP are available in respective distributions at the time of creation of these build instructions:

  • RHEL (7.8, 7.9) have 5.4.16
  • RHEL (8.6, 8.8, 8.9) have 7.2.24
  • RHEL (9.0, 9.2, 9.3) have 8.0.30
  • SLES 12 SP5 has 7.4.33
  • SLES 15 SP5 has 8.0.30
  • Ubuntu 20.04 has 2:7.4+75
  • Ubuntu 22.04 has 2:8.1+92
  • Ubuntu 23.10 has 2:8.2+93

The instructions provided below specify the steps to build PHP v8.3.4 on Linux on IBM Z for the following distributions:

  • RHEL (7.8, 7.9, 8.6, 8.8, 8.9, 9.0, 9.2, 9.3)
  • SLES (12 SP5, 15 SP5)
  • Ubuntu (20.04, 22.04, 23.10)

General Notes:

  • When following the steps below please use a standard permission user unless otherwise specified.
  • A directory /<source_root>/ will be referred to in these instructions, this is a temporary writable directory anywhere you'd like to place it.

Step 1: Build using script

If you want to build PHP using manual steps, go to STEP 2.

Use the following commands to build PHP using the build script. Please make sure you have wget installed.

wget https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/PHP/8.3.4/build_php.sh

# Build PHP
bash build_php.sh   [Provide -t option for executing build with tests]

If the build completes successfully, go to Step 6. In case of error, check logs for more details or go to Step 2 to follow manual build steps.

Step 2: Install prerequisites

export SOURCE_ROOT=/<source_root>/
PACKAGE_NAME="PHP"
PACKAGE_VERSION="8.3.4"
PHP_URL="https://www.php.net/distributions/php-${PACKAGE_VERSION}.tar.gz"

2.1) Install the system dependencies

  • RHEL (7.8, 7.9)

    sudo yum install -y autoconf curl libcurl libcurl-devel libtool wget libxml2 libxml2-devel ncurses ncurses-devel libzip-devel libzip zlib-devel bzip2 git tar gcc gcc-c++ postgresql postgresql-devel pkgconfig make tcl
    
  • RHEL (8.6, 8.8, 8.9)

    sudo yum install -y autoconf libtool openssl-devel libcurl libcurl-devel libxml2 libxml2-devel readline readline-devel libzip-devel libzip nginx openssl pkgconf zlib-devel bzip2 sqlite-libs sqlite-devel oniguruma oniguruma-devel libpq-devel git curl tar make binutils gcc-toolset-10-gcc gcc-toolset-10-gcc-c++ binutils wget
    
  • RHEL (9.0, 9.2, 9.3)

    sudo yum install -y autoconf libtool openssl-devel libcurl-devel libxml2 libxml2-devel readline readline-devel libzip-devel libzip nginx openssl pkgconf zlib-devel sqlite-libs sqlite-devel oniguruma oniguruma-devel libpq-devel git tar make binutils gcc gcc-g++ bzip2 binutils wget
    
  • SLES 12 SP5

    sudo zypper install -y autoconf curl libtool libxml2 libxml2-devel readline readline-devel libcurl4 libcurl-devel libreadline6 nginx libzip-devel libzip2 pkg-config oniguruma-devel git tar postgresql10-devel postgresql10 sqlite3-devel zlib-devel gcc gcc-c++ make gmp-devel mpfr-devel mpc-devel bzip2 wget
    
  • SLES 15 SP5

    sudo zypper install -y autoconf curl libtool openssl-devel libxml2 libxml2-devel readline readline-devel libcurl4 libcurl-devel libreadline7 openssl libzip-devel pkg-config oniguruma-devel git tar sqlite3-devel zlib-devel gcc gcc-c++ libzip5 postgresql14 nginx postgresql14-server-devel make gzip gawk gmp-devel mpfr-devel mpc-devel bzip2 wget
    
  • Ubuntu (20.04, 22.04, 23.10)

    sudo apt-get update
    sudo apt-get install -y locales language-pack-de autoconf build-essential curl libtool libssl-dev libcurl4-openssl-dev libxml2-dev libreadline8 libreadline-dev libzip-dev nginx openssl pkg-config zlib1g-dev libsqlite3-dev libonig-dev libpq-dev gcc-10 g++-10 git curl tar gcc make bzip2 wget
    

2.2) Set up GCC 10

  • Build GCC 10.3.0 and update alternative for cc (On RHEL 7.x, SLES, Ub 20.04)

    ver=10.3.0
    cd "$SOURCE_ROOT"
    url=https://ftp.gnu.org/gnu/gcc/gcc-${ver}/gcc-${ver}.tar.gz
    curl -sSL $url | tar xzf - || error "gcc $ver"
    cd gcc-${ver}
    ./contrib/download_prerequisites
    mkdir build-gcc; cd build-gcc
    ../configure --enable-languages=c,c++ --disable-multilib
    make -j$(nproc)
    sudo make install
    sudo update-alternatives --install /usr/bin/cc cc /usr/local/bin/gcc 40
    
  • Set up Env variables for GCC (Only on RHEL 8.x)

    source /opt/rh/gcc-toolset-10/enable
    

2.3) Set up other Env variables:

  • Set Environment (Only on RHEL 7.x and SLES)

    export PREFIX=/usr/local
    export PATH=${PREFIX}/bin${PATH:+:${PATH}}
    PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig:${PREFIX}/lib64/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
    export PKG_CONFIG_PATH
    LD_LIBRARY_PATH=${PREFIX}/lib:${PREFIX}/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
    export LD_LIBRARY_PATH
    LD_RUN_PATH=${PREFIX}/lib:${PREFIX}/lib64${LD_RUN_PATH:+:${LD_RUN_PATH}}
    export LD_RUN_PATH
    
  • Set Environment (Only on RHEL (8.x, 9.x) and Ubuntu)

    export PREFIX=/usr/local
    export PATH=${PREFIX}/bin${PATH:+:${PATH}}
    

2.4) Build additional dependencies

  • Oniguruma (Only on RHEL 7.x)

    ver=v6.9.5
    cd $SOURCE_ROOT
    git clone https://github.com/kkos/oniguruma
    cd oniguruma
    git checkout ${ver}
    autoreconf -vfi
    ./configure --prefix=${PREFIX}
    make
    sudo make install
    
  • Readline (Only on RHEL 7.x)

    ver=8.1
    cd $SOURCE_ROOT
    wget https://ftp.gnu.org/gnu/readline/readline-${ver}.tar.gz
    tar xvf readline-${ver}.tar.gz
    cd readline-${ver}
    ./configure --prefix=${PREFIX}
    make
    sudo make install
    
  • Openssl (Only on RHEL 7.x and SLES 12 SP5)

    ver=1.1.1g
    cd $SOURCE_ROOT
    wget --no-check-certificate https://www.openssl.org/source/old/1.1.1/openssl-${ver}.tar.gz
    tar xvf openssl-${ver}.tar.gz
    cd openssl-${ver}
    ./config --prefix=${PREFIX}
    make
    sudo make install
    sudo mkdir -p /usr/local/etc/openssl
    cd /usr/local/etc/openssl
    sudo wget https://curl.se/ca/cacert.pem
    export SSL_CERT_FILE=/usr/local/etc/openssl/cacert.pem
    
  • Sqlite3 (Only on RHEL 7.x)

    ver=version-3.35.0
    cd $SOURCE_ROOT
    git clone https://github.com/sqlite/sqlite.git
    cd sqlite
    git checkout ${ver}
    CFLAGS="-DSQLITE_ENABLE_COLUMN_METADATA=1" ./configure --prefix=${PREFIX}
    make
    sudo make install
    
  • Curl (Only on SLES)

    ver=7.60.0
    cd $SOURCE_ROOT
    wget https://github.com/curl/curl/releases/download/curl-7_60_0/curl-${ver}.tar.gz
    tar xvf curl-${ver}.tar.gz
    cd curl-${ver}
    ./configure --prefix=${PREFIX}
    make
    sudo make install
    

Step 3: Build PHP

  • Get the source code

    cd "$SOURCE_ROOT"
    wget -qO- $PHP_URL | tar xzf -
    
  • Configure and build

    cd "$SOURCE_ROOT/php-${PACKAGE_VERSION}"
    ./configure --prefix=${PREFIX} \
        --without-pcre-jit --without-pear \
        --enable-mysqlnd --with-pdo-mysql \
        --with-pdo-pgsql=/usr/bin/pg_config \
        --enable-bcmath --enable-fpm --enable-mbstring \
        --enable-phpdbg --enable-shmop \
        --enable-sockets --enable-sysvmsg \
        --enable-sysvsem --enable-sysvshm \
        --with-zlib --with-curl --with-openssl \
        --enable-pcntl --with-readline
    make -j$(nproc)
    

Step 4: Run test cases (Optional)

  • Run tests (on all distros):

    cd "$SOURCE_ROOT/php-${PACKAGE_VERSION}"
    rm ./ext/opcache/tests/log_verbosity_bug.phpt
    make TEST_PHP_ARGS=-j$(nproc) test
    
  • Following Test Cases will fail on s390x:

    • Tests stream_isatty: Pass on re-run.
  • Following Test Cases will fail on both s390x and intel:

  • SLES 12 SP5:

    ext/standard/tests/strings/setlocale_variation2.phpt
    ext/dom/tests/DOMNode_isEqualNode.phpt
    sapi/fpm/tests/log-bwd-multiple-msgs-stdout-stderr.phpt
    
  • SLES 15 SP5:

    ext/standard/tests/file/disk_free_space_basic.phpt
    ext/dom/tests/DOMNode_isEqualNode.phpt
    
  • RHEL 7.x : ext/standard/tests/directory/bug74589_utf8.phpt

  • RHEL 8.x:

    ext/openssl/tests/ecc_custom_params.phpt
    ext/openssl/tests/openssl_error_string_basic.phpt
    ext/openssl/tests/openssl_private_decrypt_basic.phpt
    ext/sockets/tests/socket_import_stream-3.phpt
    ext/sockets/tests/socket_sendto_zerocopy.phpt
    
  • RHEL 9.x:

    ext/openssl/tests/openssl_error_string_basic_openssl3.phpt
    ext/openssl/tests/openssl_private_decrypt_basic.phpt
    ext/openssl/tests/openssl_x509_verify.phpt
    ext/openssl/tests/session_meta_capture.phpt
    ext/openssl/tests/stream_crypto_flags_001.phpt
    ext/openssl/tests/stream_crypto_flags_002.phpt
    ext/openssl/tests/stream_crypto_flags_003.phpt
    ext/openssl/tests/stream_crypto_flags_004.phpt
    ext/openssl/tests/tls_min_v1.0_max_v1.1_wrapper.phpt
    ext/openssl/tests/tls_wrapper.phpt
    ext/openssl/tests/tls_wrapper_with_tls_v1.3.phpt
    ext/openssl/tests/tlsv1.0_wrapper.phpt
    ext/openssl/tests/tlsv1.1_wrapper.phpt
    ext/phar/tests/phar_setsignaturealgo2.phpt
    ext/phar/tests/tar/phar_setsignaturealgo2.phpt
    ext/phar/tests/tar/tar_openssl_hash.phpt
    ext/phar/tests/test_signaturealgos.phpt
    ext/phar/tests/zip/phar_setsignaturealgo2.phpt
    

    Note:

    • For the execution of ext/pdo_mysql,ext/mysqli and ext/pdo_pgsql test case modules, Mysql and Postgresql server needs to be up and running. Also should have a test database and needed environment variables set.
    • To run individual test, you can execute the following command to execute the test by testname:
      make test TESTS=xxx
      
      For example, if test stream_isatty_err.phpt fails, you can execute the individual test by:
      make test TESTS=tests/output/stream_isatty_err.phpt
      

Step 5: Install PHP

cd "$SOURCE_ROOT/php-${PACKAGE_VERSION}"
sudo make install
sudo cp php.ini-development $PREFIX/lib/

Step 6: Verify installation

/usr/local/bin/php -v

The output should be similar to:

PHP 8.3.4 (cli) (built: Feb 29 2024 22:01:15) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.2, Copyright (c) Zend Technologies

References: