Jump toSuggest an edit

How to configure PHP

Reviewed on 12 February 2024Published on 05 August 2021

This documentation describes the usage of a previous web hosting offer proposed by
Refer to the Scaleway Web Hosting documentation for information about the current web hosting product.

How to configure PHP at Scaleway

phpinfo is a function of the PHP language, that allows you to see the active modules, the configuration of the server, the restrictions, and the compilation parameters of the language:

// Display information about the PHP version used:
echo phpinfo();
  • The default version of PHP for all webhostings is PHP 5. During the creation of your webhosting, a phpinfo.php file will be created.

How to use sessions

Sessions are a method to save certain information when you are browsing, (your shopping cart during a pending order, for example). The session system is a default feature of PHP.

  • Refer to the official documentation for more information about sessions.

Let us see how to use sessions with PHP4:

  1. Log into your PHP session using FTP and go to the folder www/ in which you will add the code of your website.
  2. Create a new file and name it start.php containing the following lines:
    session_register ("count");
    $count = 42;
    echo "We registered ".$count." <br />";
    To go to the next page <A HREF="URLexample/nextpage.php">click here</A>
  3. Create a new file and name it nextpage.php containing the following lines:
    echo "The previously registered count is " . $count ."<br />";
  4. Upload the files to your website and open the file start.php in your browser.

How to configure a root directory (DocumentRoot)


Never use the absolute path hard coded in your site, because the path is likely to change, and your site will be inaccessible.

  1. Use the variable $DOCUMENT_ROOT that points to the root of the website in which your script is being hosted.
  2. Use $path = “$DOCUMENT_ROOT/afolder/anotherfolder/”; if you want to know the path of your website http://www.mysite.ext/afolder/anotherfolder.

How to configure a directory inclusion (IncludePath)

As part of the creation of a large website, it is possible to centralize frequently included files by adding a default directory to the search list of included files. You must create it, as it is not created by default.

  1. Create a directory include (all lowercase letters) in the website’s folder (for example: www/include).
    • Such directory can only be used within the website it was created in. This means the main website’s directory, which is named www/include, is not accessible from a secondary website (such as blog.domain.ext).
  2. Below is an example of a directory-inclusion:
    • Let us suppose you created a file global.php including different information or methods.
    • You want to access it from anywhere on your website without copying it in each subdirectory or entering the relative path to that file in each program.
    • Let us assume that your .php files are located on the main website www.mydomain.ext>.
    • You have to create www/include and store your file global.php in it (it is therefore in www/include/global.php seen in FTP).
    • Call it from a .php file regardless of where it is located inside the main website by writing:
      // following code...
    • You can also use:
      // more code to follow...

How to connect to a database

  • Persistent connections are not possible due to the architecture of the webhosting platform and are performed as a standard connection.

Refer to the documentation to configure the connection to a database using PHP.

How to upload files

  • The maximum file size you can upload is 10 MB.
  1. Rename an uploaded file using the function move_updloaded_file before the end of your script.
  2. The temporary file phpXXXXX will be deleted at the end of the receiving PHP script. Below is an example:
    <form method="post" enctype="multipart/form-data" action="upload.php">
    <input type="file" name="file" size="30">
    <input type="submit" name="upload" value="Upload">
    // if form is submitted
    if (isset($_POST['upload'])) {
    $tmp_file = $_FILES['file']['tmp_name'];
    $name_file = $_FILES['file']['name'];
    if (!is_uploaded_file($tmp_file)) {
    exit("The file can not be found");
    if (!move_uploaded_file($tmp_file, $name_file)) {
    exit("Impossible to move the file to $name_file");
    echo "The file has been uploaded and can be found at $name_file";

How to send emails

The email function of PHP is available, but it has some limitations:

  • No more than 35 recipients per call of the function,
  • Maximum 500 outgoing mails per day, with a limitation of 60 mails/hour,
  • Size of the mails is limited to 2 MB,
  • Antispam detection,
  • The mail function returns TRUE on success and FALSE if one of these conditions is not met.

Here is an example:

  • Let us suppose that the domain is domain.ext.
// Put here your valid email address
$to = "contact@domain.ext";
// Subject of the message
$subject = "Test mail() function of PHP";
// Body of the message, text encoded using iso-8859-1
$message = "Hello,\nthe message was send. Regards the Webmaster\n";
// Headers of the message
$headers = ""; // we clear the variable
$headers = "From: Webmaster <webmaster@domain.ext>\n"; // Adding the From field
// $headers = $headers."MIME-Version: 1.0\n"; // Adding the MIME version
$headers = $headers."Content-type: text/plain; charset=iso-8859-1\n"; // Add the type of encoding
// Call the mail function
if ( mail($to, $subject, $message, $headers) == TRUE )
echo "Mail sent.";
echo "Error: The message could not be sent.";

A malicious individual can use contact forms to send you spam. By calling several times a second, it will eventually saturate the contact@domain.ext email address you specified. The addition of a captcha can help you avoid this kind of hacking, and thus the suspension or cancellation of your account.

How to create a contact form (form2mail)

Let us suppose that the domain in this example is domain.ext.

  1. Create a file form.html and upload it using FTP. Your file should be similar to:
    <form action="form2mail.php" method="post">
    Enter your email address: <input type="text" name="email"><br />Message:<br />
    <textarea name="message" rows="8" cols="50"></textarea><br />
    <input type="submit" value="Send the mail">
  2. Create a second file form2mail.php and upload it using FTP. Your file should be similar to:
    /* Initialization of the variables */
    $from = "webmaster@domain.ext"; // the sender,
    replace domain.ext with your domain name
    $to = "you@domain.ext"; // recipient, put your mail address in here
    /* Preparation */
    $subject = "Test of the mail() function of PHP"; // The subject of the mail
    $email = NULL;
    $message = NULL;
    /* Get the content of the email field */
    if (!empty($_POST['email'])) {
    $email = $_POST['email'] ;
    /* Get the content of the message field */
    if ($email && !empty($_POST['message'])) {
    $message = "Message sent from $email :\n" . $_POST['message'];
    /* Sending*/
    if ($email && $message)
    /* Required headers for the mail */
    $headers = "From: Webmaster <$from>\n";
    $headers .= "To: Contact <$to>\n";
    /* $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-type: text/plain; charset=iso-8859-15\n";
    /* Call of the mail function */
    if (!mail($to, $subject, $message, $headers)){
    echo "Error: Impossible to send the mail";
    } else {
    echo "Email sent";
    else {
    echo "Error: You need to specify a mail address and a message.\n";

How to configure PHP versions

Scaleway offers different PHP versions:

  • The version 5.5
  • The version 5.6
  • The version 7.0
  • The version 7.1
  • The version 7.2
  • The version 7.3

Versions prior to PHP 5.6 are deprecated, so we recommend you update the code of your website. If you need an older version, you must contact the support and request it.

The default version for .php is 7.3 for current webhosting accounts. For older accounts the version can be changed directly from the Dedibox console:

  1. Log into your account.
  2. Click Hosting, then Manage, next to your webhosting.
  3. Click Manage in the menu on the right. The Website configuration page displays.
  4. Click the Edit action.
  5. Select the PHP version of your choice.
  6. Click Submit to update your PHP version.

How to configure PHP


Configuring PHP is possible for all our offers. However, ensure you are running at least PHP version 5.3 and above.

  1. Upload a .user.inifile to the folder corresponding to your subdomain (folder /www for example).

    The majority of options are configurable, except for those with an impact on the resources of the server.

  2. You can modify all values with PHP_INI_ALL changeable option you can find by clicking this link.
    • chown: modifications of the owner of a file are prohibited. Files uploaded using PHP or FTP already belong to your user.
    • system/exec/popen: the execution of binaries or CGI files is not possible for security reasons.
    • ASP is not supported. The execution of CGI scripts (cgi-bin) and other programs is disabled.

How to solve an HTTP error 500 in the htaccess file

You can get this error because your .htaccess file has errors, such as:

  • Presence of unauthorized directive,
  • Presence of a syntax error,
  • .htaccess file transferred in binary, instead of a transfer as text,
  • Lack of a final blank line.
  1. Rename the .htaccess file to htaccessX.txtto solve these errors.
  2. Create an empty .htaccess file.
  3. Add the lines one by one until you find the lines that caused the error 500.

How to solve an error in a PHP Script

An error 500 can come from an error in the PHP code.

Change the error_reporting and display_errors in a user.ini file as described in How to configure PHP.

How to solve email problems

  1. Update your CMS if it uses the phpmailer class (XOOPS, WAnewsletter for example).
  2. Replace the phpmailer directory present in your CMS with the latest version proposed here
See also
How to configure an htaccess fileHow to create a MySQL database
Docs APIScaleway consoleDedibox consoleScaleway LearningScaleway.comPricingBlogCarreer
© 2023-2024 – Scaleway