1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Editing the server configuration of a site (.user.ini; .htaccess)
This guide explains how to change the server configuration of a site with Web hosting and a managed Cloud Server.
The difference between .user.ini and .htaccess files
- Apache is the HTTP server. It is configured with a .htaccess file placed in the root of the website.
- PHP is a programming language used to create dynamic web pages via an HTTP server. It is possible to customize the PHP commands using a .user.ini file. These changes will be effective in the folder and sub-folders where the .user.ini file is located
- modification of the .user.ini file requires several minutes to become effective
- PHP commands must be placed in the .user.ini file to be taken into account
We will now illustrate 3 ways to modify the server configuration of a site.
1. Changing the PHP configuration via the Manager
Most settings (e.g., max_input_vars, allow_url_fopen, memory_limit, etc.) can be configured via the Manager:
- Open the Manager (manager.infomaniak.com)
- Go to Web Hosting
- If necessary, click the hosting/domain name concerned
- Under Sites at the bottom, click the domain name of the site concerned
- Click Advanced settings
- Under the PHP and Apache tabs, adjust the configuration of the site as needed
2. Changing the PHP configuration via the .user.ini file
For the PHP commands not present in the Manager, you must define the desired values in the .user.ini file. For example:
max_file_uploads = 20
The list of existing commands can be found on the official PHP website but the elements with "PHP_INI_SYSTEM" in the "Editable" column as well as max_input_time, memory_limit and mysqli.default_socket cannot be used.
3. Changing the PHP configuration in CLI
To customize the PHP commands using a command line interface (CLI) or in CRON tasks, you must define the desired values in a .user.ini file and then call the PHP executable with the -c .user.ini option
The following example enables the modification of the memory available for PHP:
~/web$ echo -e '<?php echo "memory_limit: " . ini_get("memory_limit") . "n"; ?>' >memory-limit.php
~/web$ php memory-limit.php
~/web$ echo 'memory_limit = 1024M' >.user.ini
~/web$ php -c .user.ini memory-limit.php
The following example enables allow_url_fopen for the WP CLI tool (specifically allows the recovery of extensions):
php -d allow_url_fopen=On ~/bin/wp package install trepmal/wp-revisions-cli
- How to create a .htaccess or .user.ini file
- Changing the PHP version of an Internet site
- Enabling Gzip compression
- Enabling Google's PageSpeed Tools
- Support for 301 type redirections
- Increasing the memory and runtime of scripts