Knowledge base

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

This guide concerns IonCube Loader, a PHP module that allows decoding of PHP scripts that have been encoded with IonCube Encoder.

 

Preamble

  • IonCube encoding is used to protect the source code of an application and prevent its modification or illegal distribution.
  • By using IonCube Loader, website owners can ensure the security of their code and content while allowing secure and easy distribution of their applications.

 

Using ionCube Loader

With shared hosting it is no longer offered. You can check this from the dashboard:

  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 advanced settings:
  4. Click on the PHP Extensions tab.
  5. Click on ionCube Loader (if present in the list) to see the details:

Has this FAQ been helpful?

This guide details sending emails from a website hosted by Infomaniak using the PHP function mail() which is disabled by default.

 

Preamble

  • Infomaniak strongly discourages the use of the PHP mail() function for sending emails from your applications:
    • The emails will be considered as "unauthenticated" and will therefore be subject to limits.
    • Their deliverability will be affected, which can harm your website.
  • It is strongly recommended to use an authenticated SMTP sending method for your email sending from your applications; Infomaniak offers a corresponding service.

 

Specify the sender's address

For messages to be sent correctly from your CMS/web application (and to avoid an error such as Could not instantiate mail function or sender mismatch) it is necessary to specify a valid address in the site parameters on the Infomaniak side:

  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 advanced settings:
  4. From the General tab, enter an existing email address in the Sender's email field.
  5. Click on the blue Save button:

 

Re-enable the mail function

If you still want to use the PHP mail function, you will need to activate it on each of the sites of your concerned Web Hosting:

  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 advanced settings:
  4. Click on the PHP / Apache tab:
  5. Activate the mail function:
  6. Click on the Save button at the bottom of the page to validate the changes.

 

PHP mail() examples...

 

...on WordPress

Configure the sending of the default contact form included with Divi Builder:

  1. Log in to the WordPress admin dashboard.
  2. Go to the Divi editor of the page containing the contact form.
  3. Click on the Settings icon to configure the Divi contact form:
  4. Under EMAIL, enter the email address that will receive the form submissions and save:
  5. By default, when a visitor uses the form to contact you, you will receive an email from mail@your-site-name and if you reply, the recipient will automatically be the email address indicated by the visitor when filling out the contact form.

 

... on Prestashop

Go to Prestashop advanced settings:

  1. Specify the SMTP mode.
  2. Enter localhost as the server.
  3. Enter port 25.
  4. Do not specify a username or password.

 

... on Joomla

Configure email sending via PHPmail (not recommended) in Joomla:

  1. Log in to the admin dashboard of your Joomla site.
  2. Go to Configuration then Server.
  3. Do not enter ANYTHING in the Site Email field:

This unfortunately prevents any test sending via the button for this purpose, but it will work if you configure a contact form on your site. Click on Save once the box is left empty.

 

PHP mail() reply address

When sending an email with PHP's mail() function, the return-path will be written in the form root@h2web3.infomaniak.ch for example. However, the header Reply-To: present in the code of your form allows you to specify a valid reply address.


Has this FAQ been helpful?

This guide explains how to connect to an external database from a Cloud Server.

 

Introduction

  • It is possible to connect to MySQL via SSL (whether external or not) - this should be specified when establishing the connection.
  • The MySQL port 3306 is closed by default - to open it, please refer to this other guide.
  • Infomaniak does not install PDO_DBLIB.

 

Install PHP_PDO_ODBC

Prerequisites

You can install the PHP_PDO_ODBC extension from the PHP Extensions menu of your Cloud Server:

  1. Click here to access the management interface for your product on the Infomaniak Manager (need help?).
  2. Click directly on the name assigned to the product in question.
  3. Click on PHP Extensions in the left-hand menu.
  4. Click on the blue Install an extension button.
  5. Choose the PHP_PDO_ODBC extension.
  6. Confirm the installation.

 

Configure the connector

The driver configuration is already defined in /etc/odbcinst.ini:

[FreeTDS]
Description = MS SQL database access with Free TDS Driver
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so

There is no need to redefine it statically in the .odbc.ini or in the user's home directory ‍~~/.odbc.ini‍, or even dynamically in the PHP code.

For example, with the FreeTDS driver defined beforehand, the driver version must also be specified at the end of the pdo object declaration:

$con = new PDO('odbc:Driver=FreeTDS;Server=__SERVER IP__;Port=3306;DATABASE=__DATABASE NAME__;UID=__USERNAME__;PWD=__PASSWORD__;TDS_Version=8.0');

Has this FAQ been helpful?

This guide concerns Laravel, an open-source web framework written in PHP following the model-view-controller (MVC) principle. Also refer to their documentation.

 

Prerequisites

 

Installation of Laravel 11

To do this:

  1. Log in to the server via SSH (need help?).
  2. Navigate to the site directory by running the command “cd path-to-site” (for example cd sites/laravel.domain.xyz).
  3. Create a new project by running the command composer create-project laravel/laravel example-app.
  4. Modify the .env file at the root of the hosting to update the connection parameters to the new database:
    • DB_CONNECTION=mysql
    • DB_HOST=xxxx.myd.infomaniak.com
    • DB_PORT=3306
    • DB_DATABASE= the name of the MySQL database (xxxx_newbdd)
    • DB_USERNAME= the MySQL user with rights to this database
    • DB_PASSWORD= its password
  5. Navigate to the project directory and publish via SSH:
    cd example-app
    php artisan migrate
  6. Modify the target directory to point to the “public” subdirectory of the project, here /sites/laravel.domain.xyz/example-app/public.

Has this FAQ been helpful?

This guide explains how to increase the max_children value on Managed Cloud Server to increase the number of simultaneous PHP processes that can be used by your site. This will be very useful for resolving infinite page loading issues on your site.

 

Preamble

  • By default on all hosting, the max_children limit is set to 20.
    • Although it is possible to increase this value from the Infomaniak Manager, the max_children limit is automatically adjusted based on the configuration of your Managed Cloud Server.
    • To increase this limit on shared hosting, migrate to Managed Cloud Server.
  • To understand how to calculate the max_children needed as accurately as possible, refer to this article on the subject.

 

Increase the max_children value

Prerequisites

  • Ensure that you have the necessary resources on the Managed Cloud Server.
  • Ensure that all resources of the Managed Cloud Server are not being used; if it turns out that they are fully used, increasing the max_children value will have no effect (Modify Managed Cloud Server resources).
  • Monitor the resources of your server, in case the resources of your server are reached, it will be necessary to check the optimization of processes and your site before considering increasing the max_children value.
  • Consult the PHP error reports from the /ik-logs folder (master process php logs - file name: php-fpm.log) to check if the "max_children" limit has been exceeded... example of error: [05-Jul-2024 09:08:58] WARNING: [pool www.infomaniak.ch] server reached max_children setting (20), consider raising it

To access the management of PHP / Apache parameters of the site for which you need to increase the max_children value on Managed Cloud Server, refer to this other guide.

You will be able to...

  • ... choose a new max_children value:

Do not forget to save the changes at the bottom of the page.

 

Limits depending on the server

Limit of max_children depending on the resources of the Managed Cloud Server:

Managed Cloud Server Configurationmax_children
2 CPU / 6 Go RAM20
4 CPU / 12 Go RAM40
6 CPU / 18 GB RAM60
8 CPU / 24 GB RAM80
12 CPU / 36 GB RAM120
16 CPU / 48 GB RAM160
24 CPU / 72 GB RAM240
32 CPU / 96 or 128 GB RAM320

Has this FAQ been helpful?

This guide explains how to disable or configure HSTS for a website.

 

Introduction

  • When HSTS is enabled for a website, the server instructs the website visitor (if their web browser is compatible) to replace all insecure links with secure links.
  • Example: http://www.domain.xyz.com/one/page/ is automatically replaced with https://www.domain.xyz/one/page/.
  • After enabling an SSL certificate on a website, HSTS is configured as follows: max-age=16000000.

 

Disable HSTS…

 

… with a CMS (WordPress, Joomla, etc.)

Include the following line in all pages generated by the CMS:

header( 'Strict-Transport-Security: max-age=0;' );

For WordPress, you can, for example, add this directive to the functions.php file of your theme:

add_action( 'send_headers', 'add_header_xua' );
function add_header_xua() {
header( 'Strict-Transport-Security: max-age=0;' );
}

More details on WordPress

 

… with a PHP site

Include the following line in all PHP pages:

header( 'Strict-Transport-Security: max-age=0;' );

To do this without having to modify each PHP page of a website, you can use the auto_prepend_file directive in the .user.ini file of the website in question:

auto_prepend_file=/home/clients/xxxx/web/hsts_disable.php

... with the following hsts_disable.php file:

header( 'Strict-Transport-Security: max-age=0;' );

… with a website containing static content (not PHP)

 

… avec un site au contenu statique (non PHP)

Include this header in a .htaccess file:

# BEGIN DISABLE HSTS
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=0; includeSubDomains;"
</IfModule>
# END DISABLE HSTS

 

Customize HSTS

The default value can be modified in your website's PHP files using the following directive:

header( 'Strict-Transport-Security: max-age=X; includeSubdomains; preload' );

(X being the desired number of seconds).

 

Enable HSTS for all hosted subdomains

includeSubDomains; is enabled by default, and as its name suggests, it includes subdomains in "Strict Transport Security".

When a visitor accesses an unsecure subdomain, the browser will automatically redirect to HTTPS and trigger a security error.

If this behavior is not desired, this header must be removed.

 

Clear the browser's HSTS cache…

… on Chrome

  1. In Chrome, type chrome://net-internals/#hsts.
  2. Enter the domain name in the text field in the "Delete domain security policies" section.
  3. Click the Delete button.
  4. Enter the domain name in the text field in the "Query HSTS" section.
  5. Click on the Query button.
  6. The response should be "Not found".

… on Safari

  1. With Safari, start by closing the browser.
  2. Delete the ~/Library/Cookies/HSTS.plist file.
  3. Reopen Safari.

… on Firefox

  1. With Firefox, close all tabs.
  2. Open the Firefox menu and click on History / Show History.
  3. Find the page for which you want to delete the HSTS preferences.
  4. Right-click on one of the corresponding entries.
  5. Choose Forget this site.

Has this FAQ been helpful?

This technical guide details the resource limits on Infomaniak's Web Hosting services; it is essential to distinguish between real time (clock) and processing time (CPU) to understand the origin of script interruptions.

 

1. MySQL Connection Time (I/O)

Limit: 30 real seconds

This limit corresponds to the absolute time elapsed "clock in hand." It concerns the communication between PHP and the database server (MySQL/MariaDB).

As soon as a connection is opened, the database server allocates a maximum of 30 seconds to receive the request, execute it, and return the results. If this deadline is exceeded (often due to a poorly optimized SQL query), the MySQL server abruptly cuts the connection. This usually generates the error MySQL server has gone away.

 

2. PHP Processing Time (CPU)

Limit: 10 CPU seconds

This limit exclusively concerns the computing power consumed by the web server to execute the PHP code.

It is crucial to note that waiting time does not count. When PHP waits for a response from the database, it is paused and consumes virtually no CPU time. Therefore, a script will be interrupted by the web server only if it performs intensive calculations (complex loops, cryptography, file processing) for more than 10 cumulative seconds.

 

Interaction of the two limits

To ensure the stability of the application, each operation must simultaneously respect these two distinct constraints:

  • The application has 30 seconds of total time to interact with the database (network latency + SQL execution).
  • The application has 10 seconds of pure computing time to process the received data.

Example of valid operation: a script that waits 25 seconds for a complex response from MySQL (I/O) and then processes the result for 2 seconds (CPU) will work perfectly, as it has not exceeded either of the two individual quotas, even if the total time is 27 seconds.


Has this FAQ been helpful?

This guide concerns Redis, a PHP module for Infomaniak Cloud Server.

 

Preamble

  • Redis is used with PHP to accelerate performance by serving as a cache for temporary data and managing user sessions, thus improving the efficiency of web applications.
  • Redis also allows the implementation of queue systems and temporary storage of data for asynchronous tasks or statistics.

 

Install Redis

Redis is installed from Fast Installer, applications available in a few clicks on Cloud Server:

  • After installation, Redis is accessible via the IP/port localhost:6379 or 127.0.0.1:6379
  • The password for Redis must be between 15 and 99 characters (inclusive).

Has this FAQ been helpful?

This guide explains how to modify the value of the PHP directive include_path.

 

Modify the include_path

Like any other PHP setting, include_path is defined in the .user.ini file.

Here is an example of a path to use in your .user.ini file:

  • The dot (.) at the beginning allows the current directory to be included in the search.
  • Le point (.) au début permet de conserver le répertoire courant dans la recherche.
  • The colon (:) is used as a separator between the different folders.

Refer to this other guide about phpinfo to verify that your new directive has been taken into account (it may take a few minutes for the change to appear).

Although this method is still functional, using Composer's autoloader is now the preferred solution for managing includes.


Has this FAQ been helpful?

This guide details the software libraries that can be used to manipulate the PDF format and that are compatible with the various web hosting offers from Infomaniak.

 

Introduction

  • The PDF PHP extensions allow you, among other things, to generate a PDF from dynamic data, for example, to create custom invoices.

 

PDF and Cloud Server

On Cloud Server, you can install apps like PDFtk

On shared hosting, ImageMagick is active and supports the EPDF, PDF, and PDFA formats.


Has this FAQ been helpful?

This guide is intended for developers and webmasters who are experiencing issues with the display of special characters (e.g., accents, Arabic characters, Chinese characters, emojis, etc.) on an Infomaniak website or in its database.

 

Introduction

  • Common causes of incorrectly displayed characters that appear instead of special characters or emojis like ??:
    • PHP connection in utf8 instead of utf8mb4
    • MySQL table or column in latin1 or utf8 instead of utf8mb4
    • SQL file encoded differently from the import setting
    • Incorrectly encoded HTML/CSS/JS files
    • Missing or incorrect charset declaration on the HTML, PHP, or HTTP side
  • Common solutions:
    • Use utf8mb4 everywhere: database, connections, tables, columns, files, headers
    • Validate the encoding of all files and dumps
    • Test the display of emojis, accents, and other multilingual characters
  • Also, refer to this other guide to force a different encoding when connecting to a MySQL database.

 

Use a text editor that supports saving in UTF-8 without BOM (Visual Studio Code, Sublime Text, Notepad++...)

 

1. Use UTF-8 or UTF-8MB4 everywhere

MySQL's utf8 encoding does not support 4-byte characters, such as emojis. These will be displayed as ??. Therefore, you should use utf8mb4, which is a true, complete implementation of UTF-8.

 

2. HTML – Correct encoding declaration

In the <head> of your HTML pages:

Also, make sure that the CSS/JS files are saved in UTF-8 (without BOM).

Assurez-vous aussi que les fichiers CSS/JS sont enregistrés en UTF-8 (sans BOM). 

 

3. PHP – Enforce UTF-8 or UTF-8MB4

a) HTTP Headers

header('Content-Type: text/html; charset=utf-8');

b) MySQL connection (MySQL API)

b) Connexion MySQL (API MySQL)

$connection = mysql_connect($host, $user, $pass);
mysql_set_charset('utf8mb4', $connection);

c) PDO Connection

 $dsn = "mysql:host=localhost;dbname=ma_base;charset=utf8mb4";
$pdo = new PDO($dsn, $user, $pass, [
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);

 

4. MySQL database

a) Configuration in phpMyAdmin

  • The database, tables, and columns must be in utf8mb4_unicode_ci or utf8mb4_general_ci.
  • In the Operations tab, choose utf8mb4_unicode_ci for the collation.

b) Useful SQL commands

ALTER DATABASE ma_base CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
ALTER TABLE ma_table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

c) After the PHP connection

mysqli_query($conn, "SET NAMES 'utf8mb4'");
mysqli_query($conn, "SET CHARACTER SET 'utf8mb4'");

 

5. .user.ini / .htaccess file

To force server-side encoding (Apache):

AddDefaultCharset utf-8
Header set Content-Type "text/html; charset=utf-8"
# For PHP
php_value default_charset UTF-8
php_value mbstring.internal_encoding UTF-8

 

6. Import/export SQL dumps

Errors such as é becoming ? or an emoji ☺ becoming ?? often stem from an encoding mismatch.

Check the encoding of the SQL file before importing. Use iconv if necessary:

iconv -f ISO-8859-1 -t UTF-8 dump.sql > dump_utf8.sql

In phpMyAdmin, specify the import encoding (e.g. UTF-8, UTF-8MB4 or latin1) according to the file.


Has this FAQ been helpful?

This guide explains how to manage Memcached and specifically how to check if this in-memory caching system is working correctly on your Managed Cloud Server.

 

Prerequisites

 

Check Memcached execution

To verify that Memcached is working correctly:

  1. Copy the following code into a PHP file (connecting to the local memcache server):

    $fp = fsockopen("localhost", 11211);
    if ($fp) {
    // on demande les stats
    fwrite($fp, "stats\n");
    while (!feof($fp)) {
    $buf = rtrim(fgets($fp));
    if (preg_match('/^STAT curr_items ([0-9]+)$/', $buf, $matches)) {
    // le nombre d'items stockes
    print $matches[1] . PHP_EOL;
    } elseif (preg_match('/(END|ERROR)/', $buf)) {
    // fin des stats
    break;
    }
    }
    fclose($fp);
    } else {
    print "Error: cannot connect to local memcached server: $!" . PHP_EOL;
    }
  2. Upload the PHP file to your hosting.
  3. Run the PHP file.

The script returns the number of elements cached in the server's memory.

 

Enable Memcached on…

… Prestashop

The native integration of Memcached in the Prestashop application simplifies its configuration. To enable it:

  1. Access your Prestashop admin space.
  2. Go to the Advanced Settings tab.
  3. Select Performance.
  4. Choose Yes from the dropdown menu under Use cache in the Caching section.
  5. Select CacheMemcached.
  6. Add a server by providing the required information such as
    1. the IP address: 127.0.0.1
    2. the port: 11211
    3. the weight: 1

You can check the information by clicking the "Test server" button before saving it at the bottom of the "Caching" section.

Once this step is complete, your PrestaShop application is ready to use Memcached to cache certain API calls, database calls, and objects.


Has this FAQ been helpful?

This guide explains how to modify an existing Web Hosting offer to, for example, host additional websites if the maximum site quota is reached, or to obtain a more recent hosting solution to benefit from the latest versions of PHP & MySQL.

 

Modify the web hosting offer to…

 

… order additional sites, disk space, or IPs

To access the web hosting configurator:

  1. Click here to access your hosting management on the Infomaniak Manager (need help?).
  2. Click on the action menu ⋮ located to the right of the hosting concerned.
  3. Click on Modify the offer:
  4. Increase the values you wish to modify.
  5. Click on the Next button to proceed to the payment of the modifications made to the hosting:

 

… switch to a more recent server

To obtain a hosting solution on a more recent server and thus benefit from, among other things, the latest versions of PHP & MySQL, you can either…

  • … refer to this other guide by following the procedure indicated to the end:
  • … refer to this other guide by following the procedure indicated up to point 4 then click on the button to update:

If no information banner is displayed, it means you already benefit from a recent hosting offer.


Has this FAQ been helpful?

This guide concerns the Apache mod_auth_mysql module, which enables user authentication and access authorization via a MySQL database.

 

With shared hosting

The mod_auth_mysql module is not available with shared hosting plans; consider a Cloud Server or use PHP scripts and sessions.


Has this FAQ been helpful?

This guide explains how to benefit from new versions of PHP, MySQL, and many other packages by migrating a Cloud Server to new Infomaniak infrastructure.

 

Preamble

  • Migration is free and takes place in 3 steps:
    1. Infomaniak provides a state-of-the-art Cloud Server with the same characteristics as the current one, at the same price and same commitment period.
    2. You have one month to move your hosting to the new Cloud Server provided (see below).
    3. Once your hosting is moved to the new server, cancel the old Cloud Server.
  • FTP access and databases do not change.
  • Only the supported versions of PHP and MariaDB, as well as the server's IPv4 and IPv6 addresses, change at the hosting level.
  • The hostnames (hostnames) do not change and are automatically updated to point to the new IP addresses.
  • During this operation, the statistics are reset.

 

Migration procedure

By migrating your data to the new Cloud infrastructure, you increase the performance and reliability of your sites, which will have access to the latest technologies:

  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 concerned.
  3. Click the blue button in the box "Upgrade your Cloud Server" (or Manage):

Has this FAQ been helpful?

This guide explains how ModSecurity works, how to configure it, and how to manage it on Infomaniak servers.

 

Introduction

  • ModSecurity (mod_secure) is available and enabled by default on Infomaniak servers:
    • All HTTP requests will be subject to the security rules defined by ModSecurity.
    • The uploadprogress PHP extension is not available on Infomaniak servers, as PHP is used in its FPM version.
  • It is not possible to disable ModSecurity on Infomaniak servers:
    • The setting is global to the server where your site is hosted, which means that all defined security rules will be applied to your site.

 

In case of a problem

Language error in the browser (code 403)

If the error message ModSecurity: Access denied with code 403 (phase 2). Operator EQ matched 0 at REQUEST_HEADERS. (...) appears regarding ModSecurity, you should check that a default language is properly configured in your web browser. This error can sometimes be caused by incorrectly configured language settings in the browser.

"Request body larger than configured limit" warning

If you see messages regarding the Request body larger than configured limit error or warning, please note that this is only a warning — the request still goes through and is not blocked. This configuration is specific to certain older hosting generations (of the jessie type) and allows all requests to pass through to the server without impacting your visitors.


Has this FAQ been helpful?

This guide covers ImageMagick, a powerful software suite for image manipulation, available on Infomaniak's Web Hosting and Cloud Servers.

 

Simplified Installation: To install ImageMagick or its extensions, it is recommended to use Fast Installer from your Manager.

 

ImageMagick and image manipulation solutions

Several tools are available to process your visuals (resizing, conversion, watermarks):

  1. ImageMagick (CLI): the main suite usable via command line (through SSH); the modern command is magick, but the old syntax convert is still available.
  2. PHP Extension imagick: this is the most common solution for websites (WordPress, etc.); it allows you to use ImageMagick directly in your PHP scripts.
  3. GD Library: a lighter alternative, often pre-installed, ideal for simple manipulations (thumbnails, text on image).
  4. PerlMagick: dedicated interface for Perl scripts to access ImageMagick features.

 

Paths and Commands

On Infomaniak infrastructures, ImageMagick is installed by default. The executables are located in the following directory:

/usr/bin/

Here are the main available commands:

CommandMain Usage
magick (or convert)Convert, resize, and transform images.
identifyRetrieve the metadata of a file (format, size, etc.).
mogrifyApply a modification directly to the original file.
compositeOverlay multiple images (e.g., adding a logo as a watermark).

To test the presence of the Perl module Image::Magick, you can use the following command:

perl -e 'use Image::Magick; print "Installed\n"';

Has this FAQ been helpful?

This guide concerns the synchronization of servers via the NTP (Network Time Protocol) and the configuration of the timezone on Infomaniak servers.

 

Precise server synchronization via NTP

Infomaniak servers are all synchronized via the NTP protocol. The company provides its own public-accessible stratum-1 NTP servers for flexible use.

To integrate these servers into your settings, use the following entry: pool.ntp.infomaniak.ch.

The default timezone configuration is in UTC. However, PHP functions are designed to take into account different timezones depending on specific needs.

To adjust the timezone in your PHP scripts, use the function date_default_timezone_set('UTC').

 

MySQL: temporal specifics

The Infomaniak infrastructure supports features for working with temporal data accurately and efficiently, taking into account timezones, which is crucial for many modern applications:

  • MySQL uses a timezone database to store and manage timezone information.
  • The mysql.time_zone table contains timezone data, including time offset information, timezone names, etc.
  • The CONVERT_TZ function is used to convert a time from one timezone to another in MySQL with the following syntax: CONVERT_TZ(dt, from_tz, to_tz), where:
    • dt is the date/time to convert.
    • from_tz is the source timezone.
    • to_tz is the target timezone.
  • Example: CONVERT_TZ('2024-05-14 12:00:00', 'UTC', 'America/New_York') will convert the time 12:00:00 UTC to local time in New York.

Has this FAQ been helpful?

This guide explains how to resolve an issue when importing a .csv file into a MySQL table. The proposed alternative is to read the CSV file line by line using PHP and insert the data into the MySQL database.

 

"LOAD DATA LOCAL INFILE" function disabled

The LOAD DATA LOCAL INFILE function allows you to import a CSV file directly into a MySQL table. However, this feature is often exploited by attackers to gain unauthorized access to websites hosted on servers that allow it.

To prevent any security risks and protect customer data, Infomaniak has disabled the LOAD DATA LOCAL INFILE function. Users who import their CSV files via phpMyAdmin (without checking the “CSV via LOAD DATA” option) are not affected.

Here is an alternative method for importing data in CSV format into a MySQL table. The example below shows how to properly handle errors when opening the CSV file and inserting data into the database.

This script uses mysqli to connect to the database and prepared statements to insert the data. This ensures better security, optimal compatibility with recent versions of PHP, and simple integration into your project, whether in an existing script or a new file located in the /web directory:

$fileName = "data.csv";

// Connect to MySQL database using mysqli
$link = new mysqli("localhost", "username", "password", "database");

// Check database connection
if ($link->connect_error) {
   die("Connection failed: " . $link->connect_error);
}

// Open the CSV file for reading
if (($handle = fopen($fileName, "r")) !== FALSE) {

   // Read each line of the CSV file
   while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {

       // Prepare the SQL query dynamically
       $query = "INSERT INTO `test` VALUES (" . str_repeat('?,', count($data) - 1) . "?)";
       $stmt = $link->prepare($query);

       // Check if query preparation was successful
       if ($stmt === FALSE) {
           die("Query preparation failed: " . $link->error);
       }

       // Bind parameters (assuming all columns are strings)
       $types = str_repeat('s', count($data));
       $stmt->bind_param($types, ...$data);

       // Execute the query
       if (!$stmt->execute()) {
           die("Query execution failed: " . $stmt->error);
       }

       // Close the statement
       $stmt->close();
   }

   // Close the CSV file
   fclose($handle);

} else {
   echo "Error: unable to open the file.\n";
   exit(1);
}

// Close the database connection
$link->close();
?>

 

Get help

Unfortunately, it is impossible to specify exactly where in the script these lines of code should be inserted.

If this method causes problems (for example, when importing multiple CSV files simultaneously without any error messages), the structure of the tables or the indexing of the fields may be the cause. In this case, contact your webmaster for verification.

Also, consult the official PHP documentation regarding the fgetcsv() function.


Has this FAQ been helpful?

This guide provides instructions for creating a multi-datacenter high-availability infrastructure with Jelastic Cloud.

 

Preamble

  • The principle of a multi-datacenter high-availability infrastructure is to replicate all necessary elements (web server, database server, and load balancer) in another datacenter to ensure the operation of your sites and apps in case of unexpected events (traffic spikes, hardware failure, network outage, etc.).
  • The advantages of a multi-datacenter high-availability infrastructure are numerous:
    • In case of an unexpected event on a server, another server immediately takes over; your sites and apps remain accessible.
    • In case of a disruption with a component of a datacenter, the replicated infrastructure in the other datacenter immediately takes over; your sites and apps remain accessible.
    • In case of significant traffic spikes, the traffic is distributed between the two infrastructures by load balancers; your sites and apps remain accessible and fast.

 

Setting up a high-availability infrastructure with Jelastic Cloud

For the purposes of this example, 2 web servers with 2 load balancers will be set up, each of these elements being hosted in Switzerland in a different Infomaniak datacenter.

Before proceeding, log in to the administration interface of your Jelastic Cloud server:

  1. Click here to access the management of your product on the Infomaniak Manager (need help?).
  2. Click on Log in to Jelastic Cloud:

 

1. Creating web servers

A web server hosts the content of your sites (php files, images, pdfs, etc.).

Here are the actions to perform to create the first server:

  1. Click on New environment.
  2. Click on the PHP tab.
  3. In App. Servers, choose for example an Apache server.
  4. Adjust the environment resources according to your needs.
  5. Choose Geneva DC2 for the server location.
  6. Rename the environment to easily identify it later (for example DC2-apache).
  7. Click on Create.

Create the second web server in another datacenter:

  1. Click on New environment.
  2. Click on the PHP tab.
  3. In App. Servers, choose for example a Apache server.
  4. Adjust the environment resources according to your needs.
  5. Choose Geneva DC3 for the server location.
  6. Rename the environment to easily identify it later (for example DC3-apache).
  7. Click on Create.

 

2. Creation of load balancers

A load balancer allows you to distribute the load and traffic of your sites between your web servers.

Here are the actions to perform to create the first server:

  1. Click on New environment.
  2. Click on the PHP tab.
  3. In Load Balancing, choose for example an NGINX server.
  4. Adjust the environment resources according to your needs.
  5. Choose Geneva DC2 for the server location.
  6. Rename the environment to easily identify it later (for example DC2-nginx).
  7. Click on Create.

Create the second load balancer in another datacenter:

  1. Click on New environment.
  2. Click on the PHP tab.
  3. In Load Balancing, choose for example an NGINX server.
  4. Adjust the environment resources according to your needs.
  5. Choose Geneva DC3 for the server location.
  6. Rename the environment to easily identify it later (for example DC3-nginx).
  7. Click on Create.

 

3. Configuration of load balancers and domain name

Now, you just need to tell the load balancers which web servers they should distribute the traffic to.

Start by creating the load-balancer.conf file on both load balancers:

  1. Connect via SSH to the DC2-nginx server by clicking on the Web SSH button of the environment.
  2. Open the load-balancer.conf file: nano /etc/nginx/conf.d/load-balancer.conf.
  3. Adjust the file code with the URL of your web servers:
    • http {
      upstream backend {
      server apache-dc2.jcloud-ver-jpc.ik-server.com;
      server apache-dc3.jcloud.ik-server.com;
      }
      server {
      listen 80;
      location / {
      proxy_pass http://backend;
      }
      }
      }
  4. Repeat these 3 steps for the DC3-nginx server.

Modify the load balancers configuration file:

  1. Connect via SSH to the DC2-nginx server by clicking on the Web SSH button of the environment.
  2. Create the following configuration file: nano /etc/nginx/nginx.conf.
  3. Adjust the server configuration file URL:
    • user nginx;
      worker_processes auto;
      worker_rlimit_nofile 2048;
      load_module modules/ngx_stream_module.so;
      #load_module modules/ngx_http_modsecurity_module.so;
      error_log /var/log/nginx/error_log info;
      events {
      worker_connections 2048;
      use epoll;
      }
      include /etc/nginx/conf.d/load-balancer.conf;
  4. Restart the NGINX service: sudo /etc/init.d/nginx restart.
  5. Repeat these four steps for the server DC3-nginx.

 

It is now necessary to indicate to your domain name on which servers the traffic should be redirected.

Prior to this, install a public IP address on your load balancers:

  1. Deploy the server node DC2-nginx.
  2. Hover over the Public IP line and click on the + that appears on the right.
  3. Add a public IPv4.
  4. Repeat these 3 steps for the server DC3-nginx.

At this stage, all you have to do is create two A records in the DNS zone of your domain name with the public IP of your two load balancers.

To ensure that changes are quickly taken into account, it is recommended to configure the A records with a TTL of 5 minutes.

In this example, the domain redirects your visitors to the load balancers, which in turn redirect the traffic to the web servers.

 

4. High availability infrastructure test

To test the proper functioning of your infrastructure, enter your domain name in a web browser and try in turn to disable an element of your infrastructure (one of the two load balancers, one of the two web servers). If everything works, you should still be able to access the content hosted on one of the two web servers.

Warning: data replication between web servers or database servers must be set up by you.


Has this FAQ been helpful?