For Linux Hosting

Although the PHP scripting language has been mainly developed for the creation of dynamic websites, you can also execute PHP scripts completely independent of the web server. For this purpose, you can call the PHP script on the command line with the so-called PHP Command Line Interpreter (short: PHP CLI).

Requirements:

To run PHP scripts on the command line, you need:

  • A Linux-based web hosting package with shell access (SSH).
  • A device with an SSH client installed. For computers with Windows operating system we recommend the program Putty.
  • Your IONOS FTP server name and the access data for your main FTP user.

To execute PHP files from the command line, do the following:

  • Start the SSH client and connect to your web space.
    Connecting to Your Web space via secure Shell (SSH) using PuTTY

    You can now enter commands on the Linux command line in the terminal window.
  • If the PHP script you want to execute is located in a subdirectory, use the command cd <directory path> to change to the appropriate directory. For example, to change to the Scripts directory, type the following command:

    cd Scripts

  • You can now execute your PHP script by typing the command to call the PHP CLI program on the command line, specifying the name of the PHP file to be executed. For example, to execute the PHP file my_skript.php, enter the following command:

    /usr/bin/php8.3-cli my_skript.php

Set PHP version

In the example above, you have run your script with the recommended version of PHP, PHP 8.3. If your script is not compatible with PHP 8.3, you can also use older versions of PHP. 

The following table shows the PHP versions available in IONOS web hosting with PHP CLI. The Path column specifies the command that must be entered on the command line for each version of PHP.

 

Version Path
PHP 8.4 /usr/bin/php8.4-cli
PHP 8.3 (recommended) /usr/bin/php8.3-cli
PHP 8.2 /usr/bin/php8.2-cli
PHP 8.1 /usr/bin/php8.1-cli
PHP 8.0 (deprecated) /usr/bin/php8.0-cli
PHP 7.4 (deprecated) /usr/bin/php7.4-cli
PHP 7.3 (deprecated) /usr/bin/php7.3-cli
PHP 7.2 (deprecated) /usr/bin/php7.2-cli
PHP 7.1 (deprecated) /usr/bin/php7.1-cli
PHP 7.0 (deprecated) /usr/bin/php7.0-cli
PHP 5.6 (deprecated) /usr/bin/php5.6-cli
PHP 5.5 (deprecated) /usr/bin/php5.5-cli
PHP 5.4 (deprecated) /usr/bin/php5.4-cli
PHP 5.2 (deprecated) /usr/bin/php5.2-cli
PHP 4.4 (deprecated) /usr/bin/php4.4-cli

Note:

Use outdated PHP versions only if an update of the script is not possible and therefore the use of the older PHP version is necessary for compatibility reasons.

Examples

  • To execute the file my_skript.php with PHP 8.3, enter the following command:

    /usr/bin/php8.3-cli my_skript.php

  • To run the file my_skript.php with PHP 8.2, enter the following command:

    /usr/bin/php8.2-cli my_skript.php

For more information on how to use PHP CLI, please visit: https://www.php.net/manual/en/features.commandline.php