PHP Instance

This instance family is for webmasters that would like to host dynamic websites that are built using PHP.

Prerequisites

  • Knowledge of php and the HTTP protocol,
  • You must have a file-transferring client that can upload files via SFTP (like FileZilla)
  • Or git and an SSH client to push and deploy code from the command line

Version support

We currently support PHP 7, PHP 5.6 (default and recommended version) and PHP 5.4 (legacy version, not recommended for new instances). PHP 5.5 is not supported.

Check out the Simple Hosting PHP settings list for more details on language support.

General functioning

Your instance can host an unlimited number of PHP-powered websites. For each of your websites, you can register each as a Web Address, or VHOST, on the Simple Hosting service.

Each Web Address of VHOST gets its own folder inside your instance. Files uploaded to these folders via sFTP will be served at the corresponding URLs. Each VHOST also get its own git repository, so you can push code to each one independently.

The number of requests your instance can serve is only limited by its Size, which you can upgrade at any time to accommodate more visitors. You can also make use of the platform's free built-in HTTP caching service to get maximum performance.

You can also create an unlimited number of databases and database users on each instance (for example, one database and one database user per website) . You are only limited by the storage space available on your instance, which you can also increase at any time. All databases can be managed from web-based or command-line interfaces.

Your instance's settings (such as restart, renew, upgrade, VHOSTS and snapshots) can be managed from three types of interfaces using your free Gandi account: Web (gandi.net), command-line (Gandi CLI) or API.

Each instance also gets its own username (generated by the platform) and password (chosen by you). These credentials are used to access all of the instance's dedicated management interfaces:

  • Web and SSH console for process, database, logs and file management
  • sFTP and git+SSH for files and dependencies management

You can also login to sFTP, git and SSH using SSH keys instead of the password.

More details can be found in the other sections below.

Dependency management

You can use Composer to manage dependencies on Simple Hosting by adding the “composer.json” and “composer.lock” files to your project's “htdocs/” folder.

To get Simple Hosting to install your dependencies, you'll need to use the ”Git+SSH” workflow to deploy your code, instead of uploading your files with sFTP.

Instructions:

  1. Place your composer.json file in the htdocs/ folder
  2. Run Composer to install the dependencies locally
  3. Add both Composer files, htdocs/composer.json and htdocs/composer.lock to your git tree

Check out our Composer tutorial for a full example.

VHOSTs

Each Web Address that you create via the management interface at Gandi will generate a new vhost directory in your instance, that you will see when you log into your server.

You will upload your files via sFTP to your instance in the directory of your vhost (website address) .

In case you need to know, the absolute path to your htdocs directory is:

 /lamp0/web/vhosts/www.yourdomainname.com/htdocs/

where ”www.yourdomainname.com” is the name of the Web Address (VHOST) you specified in your instance admin page, or at creation time.

Logs

You can view your logs (php, apache) from your instance's administration page.

Databases

You can choose among three types of databases: MySQL, PostgreSQL or MongoDB.

You can manage all of them via their web management interfaces (PHPMyAdmin, phpPgAdmin or RockMongo, respectively) or via their command-line interfaces, accessible through the SSH console.

MySQL

MySQL 5.5 is available to use with PHP instances on Simple Hosting.

You can connect to the MySQL database service on localhost. The default user is root and no password is required by default. However, you should create safe credentials for real-world usage. You can also use the default_db database for fast setups and testing purposes.

You can create as many users and databases as you need; you're only limited by your disk space, which you can increase at any moment up to 1 TB.

You can manage your MySQL database with the standard shell tools (mysql, mysqldump, etc.) via the SSH console, or from the web admin console with PHPMyAdmin. Check out the reference article about MySQL management on Simple Hosting to learn more.

PHP instances come with pre-installed libraries to access your MySQL database from your code : mysql, mysqli and PDO.

Below is a minimalistic PHP code example to test the database connection on Simple Hosting using the default connection settings:

index.php

<?php
 
  function test_mysql_conn() {
    $mysql_server = 'localhost';
    $mysql_user = 'root';
    $mysql_pass = '';
    $mysql_db = 'default_db';
 
    $conn = new mysqli($mysql_server, $mysql_user, $mysql_pass, $mysql_db);
    if ($conn->connect_error) {
      error_log("Connection to MySQL failed: " . $conn->connect_error);
      return "NOT WORKING";
    }
    return "OK";
  };
 
?>
<html>
  <head>
    <title>PHP MySQL on Simple Hosting</title>
  </head>
  <body>
    <p>MySQL connection: <?php echo test_mysql_conn(); ?>.</p>
  </body>
</html>

PostgreSQL

PostgreSQL versions 9.4 and 9.2 are both available for Simple Hosting with PHP.

Your instance's PostgreSQL service will be reachable on localhost, at port 5432. By default, you can use the hosting-db user without a password to connect to the default database, called postgres. We recommend that you create secure credentials for real-world usage.

You can create as many users and databases as you need; you're only limited by your disk space, which you can increase at any moment up to 1 TB.

You can manage your PostgreSQL database with the standard shell commands via the SSH console (psql, pg_dump, etc.), or from the Web admin panel with phpPgAdmin. Check out the reference article about PostgreSQL management on Simple Hosting to learn more.

PHP instances come with pre-installed libraries to access your PostgreSQL database from your code : php-postgresql and PDO.

Below is a minimalistic PHP code example to test the database connection on Simple Hosting using the default settings:

index.php

<?php
 
  function test_pg_conn() {
    $pg_conn_string = "host='localhost' user='hosting-db' dbname='postgres'";
    $conn = pg_connect($pg_conn_string);
    $conn_status = pg_connection_status($conn);
    if ($conn_status === PGSQL_CONNECTION_OK) {
      return OK;
    } else {
      error_log("Connection to PostgreSQL failed: " . $conn_status);
      return "NOT WORKING";
    };
  };
 
?>
<html>
  <head>
    <title>PHP PostgreSQL on Simple Hosting</title>
  </head>
  <body>
    <p>PostgreSQL connection: <?php echo test_pg_conn(); ?>.</p>
  </body>
</html>

MongoDB

MongoDB 2.4 is the version currently available for PHP instances on Simple Hosting.

In MongoDB-type instances, the MongoDB database service is available on localhost at port 27017. No user and password are required by default, but you should create safe credentials for real-world usage.

You can create as many users and databases as you need; you're only limited by your disk space, which you can increase at any moment up to 1 TB.

You can manage your MongoDB database from the standard mongo shell via the SSH console, or from the Web admin panel with RockMongo. Check out the reference article about MongoDB management on Simple Hosting to learn more.

On PHP 5.4 instances, you could use the pre-installed php-mongo driver and its associated libraries, such as MongoClient: :

$mongo_conn = new MongoClient('mongodb://localhost:27017/myapp-production')

Starting with PHP 5.6 instances, you'll have to install the client-library yourself to use the pre-installed php-mongodb driver.

The recommended way to do this is to use Composer and add mongodb/mongodb ^1.0.0 as a dependency and then deploying your code with git+ssh.

Below is a minimalistic code example to test the database connection on Simple Hosting starting with PHP 5.6:

composer.json

{
  "require": {
    "mongodb/mongodb": "^1.0.0"
  }
}

index.php

<?php
 
  require 'vendor/autoload.php';
 
  function test_mongo_conn() {
    $mongo_url = 'mongodb://localhost:27017';
    $mongo_conn = new MongoDB\Client($mongo_url);
    if ($mongo_conn) {
      return "OK";
    } else {
      return "NOT WORKING";
    };
  };
 
?>
<html>
  <head>
    <title>PHP 5.6 MongoDB on Simple Hosting</title>
  </head>
  <body>
    <p>MongoDB connection: <?php echo test_mongo_conn(); ?>.</p>
  </body>
</html>

Instance Management

Troubleshooting

Last modified: 06/15/2016 at 16:57 by Alexandre L. (Gandi)