Installing ZendPHP on Debian and Ubuntu (DEB)

This topic describes the procedure for installing ZendPHP on Ubuntu or Debian using Debian software package files (DEB).

Set up repository on Debian/Ubuntu

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

  1. Add the repos.zend.com GPG key to your apt keychain:

    Copy
    curl -s https://repos.zend.com/zend.key | gpg --dearmor > /usr/share/keyrings/zend.gpg
  2. Add the repos.zend.com repository to your apt sources lists:

    Copy
    sudo echo "deb [signed-by=/usr/share/keyrings/zend.gpg] https://repos.zend.com/zendphp/deb_{os}{os_version}/ zendphp non-free" > /etc/apt/sources.list.d/zendphp.list

    where {os} is one of "debian" or "ubuntu", and {os_version} is the operating system version, minus any "." separators (For example, for Ubuntu 20.04, it would be "2004", and the string would be "deb_ubuntu2004").

    If you were provided credentials, provide the package manager with them:

    Copy
    $ sudo \
    echo "machine repos.zend.com login {LOGIN_OR_ORDER_ID} password {PASSWORD}" \
    > /etc/apt/auth.conf.d/zendphp.conf
  3. Update your package sources:

    Copy
    sudo apt-get update

Install ZendPHP on Debian/Ubuntu

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

  1. Install the PHP packages:

    sudo apt-get install 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 apt-cache search php{VERSION}-zend to search our package library.

    We recommend installing the following packages in addition to the base package:

  2. Switching PHP versions. You can switch between different PHP CLI binaries using the update-alternatives command:

    sudo update-alternatives --set php /usr/bin/php{VERSION}-zend

  3. [Optional] On Apache2, install the PHP package (representing mod_php) for your ZendPHP version:

    sudo apt-get install libapache2-mod-php{VERSION}-zend

    This enables mod_php and configures it for use in handling PHP files.

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

    sudo apt-get install php{VERSION}-zend-fpm

    Enable the FastCGI module and then configure the php-fpm bindings for it:

    sudo a2enmod proxy_fcgi setenvif sudo a2enconf php{VERSION}-zend-fpm

    Start the php-fpm pool and Apache2:

    sudo systemctl start php{VERSION}-zend-fpm sudo systemctl restart apache2

    Configuration for the pool is in /etc/php/{VERSION}-zend/fpm/php-fpm.conf.

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

    sudo apt-get install php{VERSION}-zend-fpm nginx

    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/sites-available/default file to 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:/run/php/php7.4-zend-fpm.pid; } }

    Now start the php-fpm pool and restart nginx:

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

Installing and using PECL on Debian/Ubuntu

The PECL binary, used to compile and install extensions shipped via https://pecl.php.net, is available via the php{VERSION}-zend-dev package and requires the php{VERSION}-zend-xml extension. You can install everything at once as follows:

sudo apt install -y php{VERSION}-zend-dev php{VERSION}-zend-xml

Installing an extension

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

sudo 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 extensionname.ini in /etc/php/{VERSION}-zend/mods-available/ as follows:

sudo echo "; configuration for php common module ; priority=20 extension=extension-name.so" > /etc/php/{VERSION}-zend/mods-available/extension-name.ini

Once done run php -m (if using the CLI SAPI), or use phpinfo(), to verify that your extension is enabled.