Knowledge base

1000 FAQs, 500 tutorials and instructional videos. Here, there are only solutions!

Search

This guide explains how to configure PHP settings for Web Hosting directly from the command line when you run PHP scripts using PHP CLI (Command Line Interface).

 

Preamble

  • This type of configuration can be useful when you need to temporarily modify certain parameters for a specific script or for a PHP session.
  • These changes will only be valid for the execution of the current script and will not modify the global PHP configuration.

 

Modify PHP CLI settings

For example, to temporarily modify the settings for a specific script without having to modify the configuration of the server's global PHP, follow the method below; with the PHP CLI environment, you can specify multiple PHP parameters at the same time by separating them with spaces.

Using the -d parameter

When you run PHP from the command line, you can use the -d parameter to specify PHP configurations. This allows you to modify the PHP parameters for this specific execution. For example, to set the maximum execution time to 90 seconds, the memory limit to 256 MB, and disable safe mode, you can do it as follows:

php -d max_execution_time=90 -d memory_limit=256M -d safe_mode=Off -f test.php

Has this FAQ been helpful?

This guide explains how to change the PHP version used in the command line (PHP CLI) on an Infomaniak Web Hosting.

 

Preamble

  • This guide is useful if you need to temporarily adjust settings for a specific script or for a PHP session executed in the command line (CLI).
  • To modify the general PHP version used by your hosting on the web server (FPM/Apache) via the Infomaniak Manager, refer to this other guide.

 

Default PHP version in command line

When you run the php command (usually via /usr/bin/php), it is the default PHP version configured on the server that is used. This version may evolve over time according to the platform updates.

To find out the exact version currently active on your hosting, run:

php -v

To ensure the stability of your scripts, it is recommended to use an explicit version (php7.4, php8.0, php8.1, etc.) or to adjust your PATH variable to point to the directory of the desired version (for example /opt/php8.1/bin).

 

Modify the PHP version used in CLI

There are two main files that can be used to configure the PHP version automatically loaded in your SSH session:

 

1. Using ~/.bashrc (recommended)

The .bashrc file is read by Bash when opening an interactive shell (non-login), i.e., in the majority of cases when you open a normal SSH session or execute commands via deployment tools.

  1. Create the ~/.bashrc file if it does not exist, then open it:

    touch ~/.bashrc
    nano ~/.bashrc
  2. Add the following line to specify the desired PHP version (example: PHP 8.1):

    export PATH="/opt/php8.1/bin:$PATH"
  3. Reload your environment:

    source ~/.bashrc
  4. Check the currently used version:

    php -v
    which php

    You should see a path of the type /opt/php8.1/bin/php.

 

2. Using ~/.profile (alternative)

The .profile file is read only when the shell is launched in login mode (for example during an initial SSH connection). If your environment does not automatically load .bashrc, you can define the PHP version directly there.

  1. Create the ~/.profile file if it does not exist, then open it:

    touch ~/.profile
    nano ~/.profile
  2. Add the following line:

    export PATH="/opt/php8.1/bin:$PATH"
  3. Reload your environment:

    source ~/.profile

 

3. Load .bashrc from other profiles

To ensure that the configuration is loaded in all types of sessions (login and non-login), it is recommended to include in your ~/.bash_profile and ~/.profile files the following line:

if [ -f ~/.bashrc ]; then . ~/.bashrc; fi

Thus, your PHP configuration defined in .bashrc will always be applied, regardless of how the SSH session is opened.

 

Run a specific version occasionally

If you want to run a script with a specific version of PHP without modifying your environment, you can call the corresponding binary directly:

/opt/php8.1/bin/php mon_script.php
/opt/php8.2/bin/php -v

 

After these steps, the chosen PHP version will be loaded automatically each time a new session is opened, and your CLI scripts will run with the desired version.


Has this FAQ been helpful?

This guide explains how to change the PHP version available for the websites of your Web Hosting Infomaniak.

 

Preamble

  • It is possible to switch from an old and potentially vulnerable PHP version to a recent one, but you will not be able to revert to this vulnerable version afterward for security reasons.
  • The change is effective immediately and permanently.
  • Refer to this other guide if you are looking for information about configuring the PHP version used in SSH.
  • It may be necessary to update your hosting in advance to access the very latest PHP versions offered by Infomaniak.

 

Change the PHP version used for a website

It is possible to easily change the PHP version used on an entire website:

  1. Click here to access the management of your site on the Infomaniak Manager (need help?).
  2. Click directly on the name assigned to the site in question.
  3. Click on More information.
  4. Click on Modify:
  5. Select the desired PHP version.
  6. Click on Save at the bottom of the page to save the modification:

Has this FAQ been helpful?

This guide explains how to use PHP environment variables with Web Hosting that runs on php-fpm.

 

Preamble

  • PHP environment variables are system variables used to store information about HTTP requests and redirects.
  • They are generally used on web servers to store details about previous requests or redirects that have been performed.
  • These variables can contain information such as previous URLs, HTTP methods, or other data related to the client's navigation on the web server.

 

Using environment variables

To use PHP environment variables:

  1. Define the PHP environment variables in a .htaccess file:
    • SetEnv EXAMPLEVARIABLE hello
  2. In your PHP file, the name of the variable to call corresponds to the same variable name defined in the environment variable:
    • <?php getenv('EXAMPLEVARIABLE');

In this example, the displayed result will be hello.

 

Going further with environment variables

It is possible to configure environment variables directly from the Manager for your entire website:

  1. Click here to access the management of your site on the Infomaniak Manager (need help?).
  2. Click directly on the name assigned to the site concerned:
  3. Click on Manage under Advanced settings:
  4. Click on the PHP / Apache tab:
  5. Further down on the page, click on the chevron to expand the Environment Variables section.
  6. Click on the icon Add.
  7. Enter the variable and its value.
  8. Click the button to save:

Has this FAQ been helpful?

This guide explains how to use GnuPG / PGP with PHP on an Infomaniak Cloud Server, following the obsolescence of the native extension (pure PHP alternatives or modern wrappers are preferred).

 

Preamble

  • The system extension PHP_GnuPG is no longer maintained by the PHP community and is therefore no longer available on recent environments.
  • Two main alternatives in Pure PHP (installable via Composer) allow you to continue signing or encrypting your data securely.
  • If needed, local partners referenced by Infomaniak can handle these procedures: launch a free call for tenders; they handle everything, freeing you from technical details — also discover the role of the host.

 

Option 1: Crypt_GPG (Recommended)

This library acts as a wrapper: it communicates directly with the gpg binary installed on your Cloud Server. It is the most performant and stable solution.

To install it, connect via SSH and run this command at the root of your project:

# Install the PEAR Crypt_GPG package via Composer
composer require pear/crypt_gpg

Example of usage to encrypt a message (object-oriented approach):

<?php
require_once 'vendor/autoload.php';

try {
    // Initialize the GPG object
    $gpg = new Crypt_GPG();

    // Set the recipient email (must match a public key already imported on the server)
    $gpg->addEncryptKey('contact@example.com');

    $message = "This is a secret message.";
    
    // Encrypt the data
    $enveloppe = $gpg->encrypt($message);
    
    echo $enveloppe;
} catch (Exception $e) {
    // Handle potential encryption errors
    echo "Error: " . $e->getMessage();
}

 

Option 2: OpenPGP.php (Independent)

This library is entirely written in PHP. Its main advantage is that it does not depend on the server's gpg binary, ensuring total portability of your code across different environments.

# Install the OpenPGP.php library
composer require singpolyma/openpgp-php

Example of basic structure:

<?php
require_once 'vendor/autoload.php';

// Use the library classes to handle OpenPGP packets 
// directly in PHP without system calls to the GPG binary.
// Example: $msg = OpenPGP_Message::parse(OpenPGP::unarmor($data));

Has this FAQ been helpful?

This guide concerns the ODBC functions of PHP.

 

The ODBC functions of PHP are only supported on Managed Cloud Server.

 

Open Database Connectivity functions

These are the functions used to interact with databases via the ODBC (Open Database Connectivity) interface, a standard for accessing data sources uniformly. Here are some examples of using the ODBC functions of PHP:

  • Being able to read data from an external database and display it on your website
  • Insert or modify data in an external database
  • Perform complex queries on an external database

Has this FAQ been helpful?

This guide explains how to work without the PECL SSH2 client module, which is unavailable on Infomaniak Web Hosting and Cloud Servers, by using the phpseclib library instead. This library works with native PHP without requiring any specific extension.

 

Preamble

  • The use of PECL SSH2 client results in errors of type No compatible key exchange algorithms found or Unable to exchange encryption keys in its latest available version.
  • Phpseclib allows:
    • SSH authentication via password or private key.
    • Remote command execution.
    • Secure file transfer (SFTP).
    • SSH key management.

 

Using phpseclib

To integrate an SSH connection into a PHP script, use phpseclib as follows:

use phpseclib3\Net\SSH2;
use phpseclib3\Crypt\PublicKeyLoader;

$ssh = new SSH2('domain.xyz');
$key = PublicKeyLoader::load(file_get_contents('/path/to/private_key'));

if (!$ssh->login('utilisateur', $key)) {
    exit('Authentication Failed');
}

echo $ssh->exec('ls -la');

Has this FAQ been helpful?

This guide explains why it is dangerous to use a PHP version that is no longer officially updated and how to use a more recent PHP version with a website hosted by Infomaniak.

 

Is an outdated PHP version dangerous?

When you use a (soon-to-be) vulnerable PHP version on one or more of your websites, a warning message appears in the dashboard of the affected hostings.

The PHP language evolves regularly and when you use a PHP version that is no longer updated, you expose your website to security risks. Malicious individuals could, for example, exploit known security vulnerabilities to gain access to your site and modify its content. It is therefore strongly recommended to always use a recent PHP version.

3 situations are possible:

  • The PHP version is fully supported: no action is required
  • The PHP version only receives security updates: it is recommended to use a more recent PHP version
  • The PHP version is no longer updated: it is strongly recommended to use a more recent PHP version

Learn more: https://www.php.net/supported-versions.php

 

Using a more recent version

The latest PHP versions are more performant and speed up website loading.

Before using a more recent PHP version, it is important to follow the following precautions:

  • If your site uses a CMS or a web application (WordPress, Joomla, Drupal, etc.), make sure the current version of the CMS is supported by the PHP version you want to use.
  • If your site was developed manually, consult the official PHP documentation to learn about modified functions and potential changes that may affect the operation of your code.

In case of malfunction after migration to a more recent PHP version, it is sometimes possible to revert to a previous version, provided that it is still supported!


Has this FAQ been helpful?

This guide explains how to enable support for certain file types (e.g., .inc) on an Infomaniak web hosting via PHP so that they are processed in the same way as a .php file.

 

Preamble

  • Previously, you had to add the following line in a .htaccess file:
    • AddType application/x-httpd-php .inc
    • This prevented the file content from being displayed as text instead of being correctly interpreted by PHP when accessed via a browser.
  • Now you can manage file extensions via the FPM Extensions field in the Manager of your hosting.

 

Manage extensions recognized by PHP

To add support for a specific file type:

  1. Click here to access the management of your product on the Infomaniak Manager (need help?).
  2. Click directly on the name assigned to the product in question.
  3. Click on Manage under Advanced settings:
  4. Click on the PHP / Apache tab.
  5. Edit the FPM Extensions field to add the desired extension.
  6. Click the button at the bottom of the page to save:

Has this FAQ been helpful?