Installing ZendPHP on Rocky or Alma Linux
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 a Rocky Linux or Alma Linux based operating system.
Set up repository on Rocky or Alma Linux
Before installing ZendPHP for the first time, set up your repository:
-
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:
-
Replace the {OS_VERSION} placeholder with the major version of the OS, either 8 or 9.
- If you were provided with credentials, replace
<username>
and<password>
above with:<username>={LOGIN_OR_ORDER_ID}
<password>={PASSWORD}
Otherwise, omit
<username>:<password>@
from thebaseurl
.
-
-
Update your package sources:
sudo yum update
Install ZendPHP on Rocky or Alma Linux
After setting up your repository and updating the packages, you can now install ZendPHP.
-
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
Note: To make the version you are installing the system default, install the packagephp{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
-
To switch PHP versions, Rocky and Alma Linux 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
commandscl list-collections scl load php{PHP_VERSION}zend
Note: If you did not install the syspaths package for your PHP version, you MUST usescl load
to enable it and make it available on your path. -
[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 namedphp*-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
-
[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. -
[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 Rocky or Alma Linux
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.