PHP¶
This instance family enables you to host dynamic or static websites using PHP and one of the available databases.
Prerequisites¶
You must have a file-transfer 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¶
Simple Hosting currently supports PHP 7.1 and PHP 7.2 and PHP 7.3 (default and recommended version).
General functioning¶
Your instance can host a number of PHP-powered or static HTML websites. For each of your websites, you can register each as a new Site on your Simple Hosting instance.
Each Site gets its own folder inside your instance. Files uploaded to these folders via sFTP will be served at the corresponding URLs. Each Site also get its own git repository, so you can push and deploy 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 Site) . 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 the web-based control panel or the command-line clients through the SSH emergency console.
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-based Control Panel 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 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:
Place your composer.phar file into the root of your project folder
Run Composer to install the dependencies locally
Add both Composer files,
composer.json
andcomposer.lock
to your git treePush your code to your Site’s git repository
Deploy the code with SSH
Check out our Composer tutorial for a full example.
Sites¶
Each Site that you create via the management interface at Gandi will generate a new directory in your instance.
You will upload your files via sFTP to your instance in your Site’s directory.
Here’s an example of an absolute path to a Site’s htdocs directory:
/lamp0/web/vhosts/www.yourdomainname.com/htdocs/
where “www.yourdomainname.com” is the name of the Site you specified in your instance admin page.
Logs¶
You can view your PHP and Apache logs from your instance’s Control Panel, sFTP or SSH console.
Apache Logs:¶
error.log
: Contains all errors related to the Apache Web server. It is recommended to verify these logs regularly to detect possible configuration problems (bad directives on .htaccess, missing index files, and so on).
PHP Logs:¶
admin-error.log
: PHP logs executed on the admin part of your instance.
fpm.log
: Logs related to the PHP interpreter. It’s here that you can see if the max number of PHP processor is reached.
www-error.log
:PHP logs executed on the public part of your instance.
Understanding the logs¶
Bemerkung
Logs are in the UTC time zone by default.
Apache logs
[Thu Jun 14 12:08:45.199853 2012] [mpm_event:notice] [pid 186:tid 3557842618176] AH00489: Apache/2.4.1 (Unix) configured -- resuming normal operations
[Thu Jun 14 12:08:45.199869 2012] [core:notice] [pid 186:tid 3557842618176] AH00094: Command line: '/usr/sbin/apache2 -d /srv/data/.config/apache -f /srv/data/.config/apache/apache2.conf -D lamp0-1'
[Thu Jun 14 15:08:45.213486 2012] [mpm_event:notice] [pid 186:tid
These lines indicates that the web server has been started.
PHP Logs
[08-Jun-2012 12:56:29] WARNING: [pool www] server reached max_children setting (x), consider raising it
This alert occurs when PHP-FPM has reached the maximum number of simultaneous processes for PHP. The maximum number of simultaneous process is defined in terms of the size of your instance (2 on a pack S, 4 on a M, 8 on a L …). If this error occurs too frequently, you should consider increasing the size of your instance Simple Hosting. When you see [pool www], it is the number of processes running on the public part of your instance, [pool admin] denotes the admin part of the proceedings.
[05-Jun-2012 09:08:36] WARNING: [pool admin] 'user' directive is ignored when FPM is not running as root
This alert is not an error and can be ignored.
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.7 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 version 9.4 is 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 Control Panel using 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 3.6 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 Adminer. Check out the reference article about MongoDB management on Simple Hosting to learn more.
You’ll have to install the MongoDB client library yourself to use the php-mongodb
driver pre-installed on your instance.
The recommended way to do this is to use Composer: add mongodb/mongodb ^1.0.0
as a dependency and then deploy 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>