PHP in der Webhosting-Umgebung

PHP and an optional MySQL database are available in the LRZ web hosting environment.  This enables the operation of many web applications. This pages explains technical background and provides tipps for working with specific versions.

PHP execution

In our infrastructure, PHP is executed via the FastCGI Process Manager (PHP FPM), making your website's PHP processes run with the privileges of your website's functional account.

Available PHP versions

We usually provide more than one PHP version at a time. The current default PHP version will be used for a new website.

You may choose to use a different version than the default one. Please contact the LRZ web hosting team to change your website's PHP version.

Please note

Each major version of PHP, like 7.3 or 7.4, is supported by the PHP development team for two years (see "Supported Versions").

As soon as a major release reaches its end of life (EOL) and no longer receives security updates, we will also no longer be able to provide support for that PHP version to avoid security risks. This means that we will upgrade websites in our hosting running the PHP version that is falling out of support to the next higher major version (e.g. from PHP 7.3 to 7.4). This action usually happens in early December each year. As part of this, you must ensure that your web application is compatible with the next higher PHP version. If you use a CMS such as TYPO3 or Wordpress, you can usually find compatibility information in the system requirements.

We will inform you about an upcoming change in our supported PHP versions several weeks in advance.

In cases where a non-default PHP version was configured for the website (for example, if you use a very recent PHP version), your website's PHP version will not be changed automatically.

PHP extensions

A range of PHP extensions/libraries are available in our infrastructure, e.g. gd (graphics library), ftps, imap, intl, ldap, mbstring or mcrypt. Due to the maintenance aspect and our limited person power, we will usually not be able to provide more extensions. Please contact us if there is a certain extension that you need and we will consider if we can provide it. The same applies to the customisation of PHP parameters.

Using PHP on the command line and in cron jobs

On the access servers, PHP is available for use on the command-line and in cron jobs. The php command executes the most recent installed version of PHP that is configured for your website. You can find out the exact version with the -v flag. The following shows an example where PHP 7.4 is configured for the site. PHP is executed in version 7.4.11 ("11" is the patch level version).

user@webdev02:~$ php  -v
PHP 7.4.11 (cli) (built: Oct 8 2020 17:32:43) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.11, Copyright (c), by Zend Technologies

However, the PHP version that is executed via the php command may change due to updates (see the information box under "Available PHP versions"). Therefore, we provide a dedicated command for each major PHP version, like for example php7.4 (see below for more information).

Tip

The configuration of your website determines which major PHP version your website uses (see above).

To avoid errors in the execution of your web application, you should also use this major PHP version on the command line or in cron jobs or other scripts.  Therefore, it is recommended to use the version-specific PHP command (see below) to avoid unexpected version jumps.

There are various ways to find out which PHP versions are installed and what the commands are called:

user@webdev02:~$ update-alternatives --list php
/usr/bin/php7.1
/usr/bin/php7.2
/usr/bin/php7.3
/usr/bin/php7.4
/usr/bin/php8.0

user@webdev02:~$ ls /usr/bin/php*
/usr/bin/php  /usr/bin/php7.1  /usr/bin/php7.2	/usr/bin/php7.3  /usr/bin/php7.4  /usr/bin/php8.0

user@webdev02:~$ ls /bin/php*
/bin/php  /bin/php7.1  /bin/php7.2  /bin/php7.3  /bin/php7.4  /bin/php8.0

Notes:

  • You can find the PHP commands in the /bin directory as well as under /usr/bin.
  • The PHP commands in /bin and /usr/bin are identical.
  • Usually, /bin and /usr/bin are included in the command search path (meaning both directories are contained in the $PATH environment variable, which you can check by running the command echo $PATH). This means that you can simply use the command without using the whole path (for example, php7.4 instead of /usr/bin/php7.4).

Tip

Cron jobs are executed in a separate environment where the command search path is different from the interactive shell. When writing cron jobs, you should therefore do the following to avoid problems:

  • Use absolute paths for commands (for example, use /usr/bin/php7.4 instead of php7.4).
  • If your cron job executes a shell script, you should set the $PATH environment variable explicitly at the start of the script.

Available PHP Components

The PHP environment consists of the following components:

  • Interpreter for the PHP scripting language. The PHP scripts run with the permissions of the functional account that the website is assigned to.
  • Extensions and libraries like "ftps",  "gd",  "imap",  "intl",  "ldap",  "mbstring",  "mcrypt".
  • Composer ("packet manager" for PHP) on the access server.
  • Other software packages, that are dependencies of the other components or complete them

The LRZ can supply further components can only in a limited fashion. Please contact the Webhosting Team if you miss something. The same is true for adjustments to PHP settings.

Currently (January 2024) the available PHP brachches are 8.0, 8.1, 8.2 and 8.3.



Your Site's PHP Branch

The PHP Team supports several PHP branches (major versions) in parallel. For these active branches, updates to close newly dicovered security issues are available. In the Webhosting environments of the LRZ, several PHP branches are available.

The Webhosting Team can configure the PHP version for each site individually. Besides that, there is adegault branch for all sites that have not configured a certain version.

On the default branch

The default branch is adjusted regularly to the officially supported versions (see the overview at "supported versions"). The update to next branch is usually done each year, and is announced several weeks ahead.

If your site uses the default branch, please make sure that your web application is compatible with the next branch. Most web applications document their compatibility as system requirements.

Additionally, the appendices of the PHP handbook give advice for migration from each PHP branch to the next.

If you would like to set a certain PHP branch for your site, you can request the change from the Webhosting Team:

  • What should be done exactly?
  • When should the change be done?
    • You can ask us to change the version at any time
    • We can make an appointment for a certain time

After changing the PHP version, we test the site in a very superficial manner.

  • Due to lack of personal resources, we can just check a few pages for ovious problems.
  • Due to technical reasons, we can not check if everything is still working

If the website doesn't work at all, we revert the change immediately. In any case we contact you on the result.


Tipps for PHP on the command line

PHP is available on the commaind line of the access host for interactive tasks or cron jobs


Tipps for cron jobs

Cron jobs run in their own environment. In this environment, search paths for commands might differ from those in the interactive shell. To avoid problems, you should

  • Use the absolute paths in cron job definitions
  • If the cron job calls shell scripts, they should explicitly set the search path (environment variable "$PATH") at the top of the script


Available PHP branches

There are several methods to know which branches of PHP are available in the webhosting environment. This also reveals specific PHP interpreter calls for the command line.

Log in to the access server using the functional ID of the site, and enter the following commands.

user@webdev
user@webdev02:~ $ update-alternatives  --list  php
[...]
/usr/bin/php8.0
/usr/bin/php8.1
/usr/bin/php8.2

user@webdev02:~ $ ls  /usr/bin/php*
/usr/bin/php  [...]  /usr/bin/php8.0  /usr/bin/php8.1  /usr/bin/php8.2


Notes:

  • Usually, "/usr/bin" is part of the command search path, i.e. the strings are contained in the environment variable "$PATH".  This can be checked with the command "echo $PATH". That is why one can often just write  "php" or  "php8.2" instead of writing the full path.
  • The command "php" (without a version number) is the PHP interpreter for the current default branch. The defaut branch changes regularily, and so does this command.
  • Commands with names like "php<Versionsnummer>" are interpreters for a specific branch, that is constant over time. With these commands, only the minor version changes from time to time (like from  "8.2.11" to "8.2.12").  This shouldn't affect the compatibility of scripts.

Using the option "–-version" (or "-v"), the exact version is displayed.

user@webdev02:~ $ php  --version
PHP 8.1.23 (cli) (built: Oct  6 2023 10:11:51) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.23, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.23, Copyright (c), by Zend Technologies


user@webdev02:~ $ php8.2  --version
PHP 8.2.11 (cli) (built: Oct  6 2023 10:11:52) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.11, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.11, Copyright (c), by Zend Technologies

Use a specific PHP branch

The PHP branch for the website is set through our configuration. Sometimes, a PHP interpreter is needed on the command line on access server

  • The CMS or a setup using composer needs PHP.
  • A PHP script is used in a cron job.

Tipp zum PHP-Branch

To avoid problems, you should use the same version on the command line, that your website uses.

If you need a certain PHP version, certain problems can occurr with the command "php", the default interpreter for the server pool.

  • Even if "php" is currently the interpreter matching your site, it may not always be that way. You should use the version-specific commands (like "php8.2") in scripts and cron jobs.
  • Sometimes, the interpreter can not be called directly. That is sometimes the case in certain setup scripts, that contain a call to "php". If the default version is too old for the setup script to run, it halts with an error message.

With the second problem, the way to go is to make sure that the command  "php" calls the "correct" Interpreter.

Assuming you need the PHP branch "8.2", and work with bash as shell. The following should work.

A new "php" command

You make a new command "php" that starts "php8.2" in turn.

Erzeugung des neuen "php"
# Create the neccessary directories.
mkdir  --parents  --mode=02700  --verbose  $HOME/bin/Overlay

# Change into ".../Overlay".
cd  $HOME/bin/Overlay

# Create a symbolic link to the desired version-specific command.
ln  --symbolic  --verbose  /usr/bin/php8.2  php

# Test if the new "php" works as expected
./php  --version

The name "Overlay" for the directory is a suggestion; it should remind of the fact that commands in this directory will overlay commands with the same name. That is why you need to be careful with what you place inside  ".../Overlay".

Place "Overlay" to the beginning of the search path

The directory "$HOME/bin/Overlay" has to placed at the very beginning of the search path (variable "$PATH").

The modification of "$PATH" needs to occur automatically:

  • On login
  • When running a bash script

The shell "bash" uses severeal profile files.  In tha man-Page of "bash", the section "INVOCATION" says:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists.

After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.

The --noprofile option may be used when the shell is started to inhibit this behavior.

[ Hinweis:  Das Zeichen "Tilde" ("~") ist eine Kurzform für "$HOME". ]

You extend one of the files "$HOME/.bash_profile", "$HOME/.bash_login" or "$HOME/.profile" (in this order) at a suitable location.
If none of these files exists, you should create a new "$HOME/.bash_profile" for this.

The file is now extended with the following command:

Erweiterung von "$PATH"
# Caution: The backslash ("\") has to be at the end of the line

expr  match  "$PATH"  ".*/Overlay:"  > /dev/null \
||  export  PATH="$HOME/bin/Overlay:$PATH"

With this command, "$PATH" is only extended, if it doesn't contain the string "/Overlay:" already. Therefore, the command can be executed multiple times without extending the path repeatedly. You can also place the command into several scripts, which might be neccessary in certain cases (see the section "INVOCATION" in the "bash" man page).

When using other shells, the profile system of that shell has to be used, and the command to extend "$PATH" may need to be adjusted.

Extending "$PATH" in the interactive shell

You can extend the search path in the currently running shell using  export  PATH="$HOME/bin/Overlay:$PATH" . With the scripts above in place, this needs to be done once for the active shell, and will be done automatically on login later on.

The command  "php -v" should show "8.2" now.