PHP configuration

What is PHP?

PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language. As of January 2013, PHP was installed on more than 240 million websites (39% of those sampled) and 2.1 million web servers. Originally created by Rasmus Lerdorf in 1994, the reference implementation of PHP (powered by the Zend Engine) is now produced by The PHP Group. While PHP originally stood for Personal Home Page, it now stands for PHP: Hypertext Preprocessor, which is a recursive backronym. (Wikipedia definition)

PHP configuration at Online.net

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.

<?php
 
   // Display information about the PHP version used:
   echo phpinfo();
 
?>

You can see the phpinfo of our PHP versions at the following links:

The default version of PHP for all new hostings is PHP 5. During the creation of your hosting, a phpinfo.php file will be created.

How to use sessions?

Sessions are a method to save some information during a visit, for example the shopping cart during a pending order. The session system is a default feature of PHP.

Some links:

A simple example with PHP4 (does not work with PHP5):

1) Connect using FTP and go to the folder www/

In this folder we will add the code of your website

Make a new file “start.php” (attention about the extension .php) containing the following lines:

<?php
  session_start();
  session_register ("count");
  $count = 42;
  echo "We registered ".$count." <br>";
?>
  To go to the next page <A HREF="nextpage.php">click here</A>

Make a new file “nextpage.php” containing:

<?php
  session_start();
  session_register("count");
  echo "The previously registered count is " . $count ."<br>";
?>

Upload the files to your website and open the file start.php in your browser.

Root directory (DocumentRoot)

:!: It is crucial to never use the absolute path 'hard' coded in your site, because the path is likely to change and your site would be inaccessible.

Because of this you can use the variable $DOCUMENT_ROOT that points to the root of the website in which your script is being hosted.

Example : You want to know the path of your site http://www.mysite.ext/afolder/anotherfolder

You can use $path = “$DOCUMENT_ROOT/afolder/anotherfolder/”;

Directory inclusion (IncludePath)

As part of the realization of a large site, it is possible to centralize frequently included files. For this, a default directory is added to the search list of included files.

It is not created by default, to create it, you need only to create a directory “include” (without quotation marks and all lowercase letters) in the website's folder (for example: www/include).

One such directory is only usable within the site where it was created. This means the main website's directory (which is named “www/include”) is not accessible from a secondary website (like blog.domain.ext).

Example:

  • You created a file 'global.php' including different information or methods.
  • You want to access it from anywhere in your site without copying it in each subdirectory or enter the relative path to that file in each program.
  • We assume that your .php files are located in the main website (www.mydomain.ext>)
  • You have to create “www/include” (without the quotes and in lower case) and store your file “global.php” in it (it is therefore in www/include/global.php seen in FTP)
  • To call it from a .php file regardless of where it is located inside the main website, simply do:
<?php
 include("global.php"); 
 // more code to follow...
?>

or also

<?php
 require("global.php"); 
 // more code to follow...
?>

(Depending on the preferred method of inclusion)

Connection to a database

Persistent connection

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

Connection to a database using PHP

Uploading files

The upload of files is enabled. The maximum file size is 10 MB. You can rename an uploaded file using the function move_updloaded_file before the end of your script The temporary file (named phpXXXXX) will be deleted at the end of the receiving PHP script.

<form method="post" enctype="multipart/form-data" action="upload.php">
<p>
<input type="file" name="file" size="30">
<input type="submit" name="upload" value="Upload">
</p>
</form>
 
<?php
if( isset($_POST['upload']) ) // if form is submitted
{
   $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";
}
 
?>

Sending of e-mails

The function mail() of PHP is activated, but with some limitations:

  • No more than 35 recipients per call of the function
  • Size of the mails is limited to 2MB
  • Antispam detection

The mail function returns TRUE on success and FALSE if one of these conditions is not met.

We assume in this example that the domain is “domain.ext”.

<?php
 
// 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.";
}
else
{
   echo "Error: The message could not be sent.";
}
 
?>

:!: Be aware that a malicious individual can enjoy 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 piracy, and thus the suspension or cancellation of your account.

Creation of a contact form (form2mail)

We assume that the domain in this example is “domain.ext”.

Create a file “form.html” and upload it using FTP.

<html>
<body> 
<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">
</form> 
</body>
</html>

Create a second file “form2mail.php” and upload it using FTP.

<?php
 
/* 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";
}
 
?>

PHP versions

Online offers you different PHP versions:

  • The version 5.6
  • The version 7.0
  • The version 7.1
Versions prior to PHP 5.6 are deprecated, so we recommend that you update the code of your site.
If an older version is required by you, you will need to make a request to the support to use it.

The default version for “.php” is 7.1 for new hosting accounts.

For older accounts the version can be changed directly from your panel :

And then select the PHP version of your choice :

Change the PHP version of a Cloud hosting

By default all our Cloud hostings use the version 5.6 of PHP.

However, version 7.1 is also available.
To use it, you have to add a .htaccess file in the root of the concerned directory.

You have to add the following line:

AddHandler php7-fcgi php

Once you have uploaded the .htaccess file, the directory in question will use PHP 7.1.


You are able to check the PHP version used in your hosting by using the phpinfo() function.

Configuration of PHP

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

Simply upload a “.user.ini” file to the folder corresponding to your sub domain (Folder “/www” for example).
The majority of options are configurable, except for those with an impact on the resources of the server.

You can modify all values with PHP_INI_ALL changeable option you can find here :
http://php.net/manual/en/ini.list.php

Restrictions

Safe Mode

The safe mode is:

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/CGI

ASP is not supported. The execution of CGI scripts (cgi-bin) and other programs is disabled.

Known problems

Error 500

It could have several causes, here are some:

Error in the htaccess file

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

  • 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

You can stop these errors by renaming the .htaccess file to htaccessX.txt

You will then create an empty .htaccess file and add the lines one by one until you find the lines that caused the error 500.

Timeout

The execution of your script takes longer than the max_execution_time

Sending of emails

If your CMS uses the phpmailer class (XOOPS, WAnewsletter for example) you will have to update it. Replace the phpmailer directory present in your CMS with the latest version proposed here http://sourceforge.net/project/showfiles.php?group_id=26031&package_id=252700.