Changing the PHP Configuration (Apache)

For Managed Cloud Hosting with Apache Web Server

You can configure your PHP environment using a .htaccess file.

PHP provides special variables, so-called directives, for configuration changes. This can be used, for example, to assign the available resources, edit PHP accounts, or switch various functions on and off.

Please note: Since PHP runs as an Apache module, .user.ini files have no effect as these are not taken into account by the Apache web server! Instead, use the path described here via the .htaccess.

What is .htaccess?

.htaccess is an Apache configuration file that can be used to set up directory-related rules.

The .htaccess must be created as text file (plain text), filled and stored in the desired directory on the web space. There it automatically affects all subdirectories (a .htaccess file in the document root directory is valid for the entire web space)

Hint: If the directory already contains a .htaccess file, entries must be added there since Apache only considers a .htaccess file.

PHP directives

For an overview of the directives available for configuration settings, see https://secure.php.net/manual/en/ini.list.php.

Please note: Only directives that are assigned to a PHP_INI_* mode of type PHP_INI_ALL or PHP_INI_PERDIR can be set via the .htaccess! (more on php.net)

Syntax of the .htaccess entries

In the .htaccess file, the values must be assigned to the directives according to the following scheme:

Code used for  
php_value name value non boolean values
php_flag Name onoff Boolean values  
Examples:

This sets the memory limit for PHP processes to 512 MB:

php_value memory_limit 512M

This activates the display of runtime errors:

php_flag display_errors on
.htaccess examples

Hint: To ensure that the code is only executed if the corresponding PHP version runs as an Apache module, the <IfModule> directive is also used.

PHP 5.x:

<IfModule mod_php5.c>

############################################
## adjust memory limit
    php_value memory_limit 512M

## adjust maximum time in seconds a script is allowed to run 
    php_value max_execution_time 600

## enable error messages
 php_flag display_errors on

</IfModule>   

PHP 7:

<IfModule mod_php7.c>

############################################
## adjust memory limit
php_value memory_limit 512M

## adjust maximum time in seconds a script is allowed to run
php_value max_execution_time 600

## enable error messages
php_flag display_errors on

</IfModule> 

Checking the configuration

You can check whether a setting has been changed as desired with the following small script in the corresponding directory:

<?php phpinfo(); ?>

The phpinfo() function displays extensive information about the current state of PHP. In the configuration options, the locally valid values are always displayed on the left; the changed value should now be displayed here.

Hint: Depending on the selected stack, there may already be a corresponding phpinfo.php file in your document root directory.