Installing ZendPHP on RHEL and CentOS (RPM)

The preferred installation procedure for all Linux distributions and for IBM i is the zendphpctl tool. This article describes the alternative manual procedure for installing ZendPHP on CentOS 7 and 8, and Red Hat Enterprise Linux (RHEL) 7, 8, and 9.

If you are installing ZendPHP on CentOS or RHEL version 7, please install the software collections package first. This is standard starting with RHEL version 8, and allows you to install multiple versions of PHP.

Set up repository on RHEL/CentOS

Before installing ZendPHP for the first time, set up your repository:

  1. Add the ZendPHP yum repositories:

    $ sudo echo -e "[zendphp]
    name=ZendPHP (x86_64)
    baseurl=https://<username>:<password>@repos.zend.com/zendphp/rpm_centos{OS_VERSION}/x86_64/
    enabled=1
    gpgcheck=1
    gpgkey=https://repos.zend.com/zend.key
    
    [zendphp_noarch]
    name=Zendphp (noarch)
    baseurl=https://<username>:<password>@repos.zend.com/zendphp/rpm_centos{OS_VERSION}/noarch/
    enabled=1
    gpgcheck=1
    gpgkey=https://repos.zend.com/zend.key
    " > /etc/yum.repos.d/zendphp.repo
    

    In the code snippet, replace the following values:

  2. Update your package sources:

    sudo yum update

Install ZendPHP on RHEL/CentOS

After setting up your repository and updating the packages, you can now install ZendPHP.

  1. Install the PHP packages:

    sudo yum install php{PHP_VERSION}zend

    This installs the common modules and the CLI binary for the specified version. If you would like to explore the additional packages that are available, use sudo yum search php{PHP_VERSION}zend to search our package library.

    Some packages have requirements that are found in the Extra Packages for Enterprise Linux (EPEL) repository. If a package indicates that a requirement cannot be found, install the EPEL repository:

    sudo yum install -y epel-release
    # Force YUM to refresh the repository list and install keys:
    sudo yum repolist
    
    To make the version you are installing the system default, install the package php{VERSION}zend-syspaths. For example, to install the 7.4 CLI and make it the system default use:
       sudo yum install -y php74zend php74zend-syspaths
  2. Switching PHP versions. RHEL and CentOS packages use software collections to allow installing multiple PHP versions on the same machine. You can list them and switch between them using the scl command

    scl list-collections
    scl load php{PHP_VERSION}zend
    If you did not install the syspaths package for your PHP version, you MUST use scl load to enable it and make it available on your path.
  3. [Optional] On Apache2, install httpd and the PHP package (representing mod_php) for your ZendPHP version:

    sudo yum install httpd php{PHP_VERSION}zend-php

    This enables mod_php under httpd by default. If you have other versions installed, you need to rename their configuration files so that you can use the one for your desired version. Look for files named php*-zend-php.conf in the directory /etc/httpd/conf.d/. Rename any files for versions you are not using to append a .tmp or .bak suffix. Once you have, restart httpd:

    sudo systemctl restart httpd
  4. [Optional] To install FastCGI on Apache2, you need to install httpd, and the php-fpm package for your PHP version:

    sudo yum install httpd php{VERSION}zend-php-fpm

    From here, you can start your php-fpm pool and Apache:

    sudo systemctl start httpd
    sudo systemctl start php{PHP_VERSION}zend-php-fpm
    

    Configuration for the pool is in the /etc/opt/zend/php{VERSION}zend/ directory.

  5. [Optional] To install FastCGI on nginx, you need to install the php-fpm package for your PHP version and nginx:

    sudo yum install nginx php{PHP_VERSION}zend-php-fpm

    From here, you need to create a virtual host configuration for nginx that proxies PHP requests to FastCGI as handled by your PHP version. For example on PHP 7.4 you need to edit the /etc/nginx/nginx.conf file to make the default host read:

    server {
    	listen 80;
    	root /var/www/html;
    	server_name _;
    	index index.html index.html index.php;
    	location / {
    		try_files $uri $uri/ /index.php$is_args$args;
    	}
    	location ~ \.php$ {
    		include snippets/fastcgi-php.conf;
    		fastcgi_pass unix:/var/opt/zend/php74zend/run/php-fpm/php-fpm.pid
    	}
    }

    Now start the php-fpm pool and restart nginx:

    sudo systemctl restart nginx
    sudo systemctl start php{PHP_VERSION}zend-php-fpm

Installing and using PECL on RHEL/CentOS

Installing PECL

The PECL binary, used to compile and install extensions shipped via https://pecl.php.net, is available via the php{VERSION}zend-php-pear package and requires the php{VERSION}zend-php-devel package. You also need build tools, generally provided via gcc, gcc-c++, and make packages. You can install everything at once as follows:

sudo yum install -y gcc gcc-c++ make \
php{PHP_VERSION}zend-php-devel \
PHP{PHP_VERSION}zend-php-pear

This installs the PECL binary to /opt/zend/php{VERSION}zend/root/bin/pecl.

Installing an extension

Installing an extension via the PECL binary follows the generic instructions for all platforms:

sudo scl enable php{PHP_VERSION}zend 'pecl install {extension_name}'

Enabling an extension

Once compiled, you need to enable the extension. Generally, PECL provides information like the following on successful completion:

install ok: channel://pecl.php.net/extension-name-and-version 
configuration option "php_ini" is not set to php.ini location 
You should add "extension=extension-name.so" to php.ini

The important piece is the section contained in quotes in the last line. Copy that information and create a file named 20-extensionname.ini in /etc/opt/zend/php{PHP_VERSION}zend/php.d/ as follows:

sudo echo "; Enable extension-name extension module 
extension=extension-name.so" > /etc/opt/zend/php{VERSION}zend/php.d/20-extension-name.ini

Once done, run php -m to verify that your extension is enabled.