Skip to content

Instantly share code, notes, and snippets.

@rvalitov
Created June 24, 2023 08:00
Show Gist options
  • Save rvalitov/5e2fae28aa5bc81402ab6d4acb9d986f to your computer and use it in GitHub Desktop.
Save rvalitov/5e2fae28aa5bc81402ab6d4acb9d986f to your computer and use it in GitHub Desktop.
Configuration of jailkit for PHP and ISPConfig

Jailkit configuration

Jailkit is used to create a secure shell environment for the user. It's also used by ISPConfig to securely run user's cron jobs from command line. Default jailkit configuration may not properly support PHP. So, first jailkit needs to be installed:

$ sudo apt-get install jailkit

Then configuration file /etc/jailkit/jk_init.ini needs to be modified by addding 2 new sections - php and env:

[php]
comment = the php interpreter and libraries
executables = /usr/bin/php, /usr/bin/php5.6, /usr/bin/php7.0, /usr/bin/php7.1, /usr/bin/php7.2, /usr/bin/php7.3, /usr/bin/php7.4, /usr/bin/php8.0, /usr/bin/php8.1, /usr/bin/php8.2
directories = /usr/lib/php, /usr/share/php, /usr/share/php*, /etc/php, /usr/share/php-geshi, /usr/share/zoneinfo, /usr/share/ca-certificates, /etc/ssl/certs, /usr/lib/ssl/certs
includesections = env, netbasics

[env]
comment = environment variables
executables = /usr/bin/env

Notes:

  • In the example above we have a system with multiple PHP versions installed from 5.6 till 8.2. Only those versions should be specified that are installed in the system and should be available inside the jailkit.
  • Zone info data is copied in jailkit to avoid PHP error:

    Timezone database is corrupt

  • Certificates are copied to jailkit to avoid SSL error:

    cURL error 60: SSL certificate: unable to get local issuer certificate

ISPConfig

Configuration

The php section should be added in the ISPConfig jailkit configuration: image

Cron

The path of executable file should be relative to the user's home directory, for example, /private/import.sh: image

To run a PHP file it can be specified like this:

 php /web/administrator/cron.php

Possible issues

If you have absolute file paths specified in your project (such as Joomla) and that works fine during web access, then you may experience path resolution issue when running your code in console inside jailkit. The reason is that in jailkit you will have a different file structure and your absolute path won't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment