====== 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===== Simple Hosting currently offers PHP 7.1 instances with MySQL, PostgreSQL or MongoDB. We also support existing PHP 7, PHP 5.6 and PHP 5.4 instances. PHP 5.5 is not available. Check out the [[en:simple:php|Simple Hosting PHP settings list]] and see what PHP features we support. =====General functioning===== Your instance can host PHP-powered websites. You can register each of your websites 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: [[https://www.gandi.net/admin/hosting/paas/management | Web (gandi.net)]], [[https://github.com/Gandi/gandi.cli|command-line (Gandi CLI)]] or [[http://doc.rpc.gandi.net|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 [[https://getcomposer.org/|Composer]] to manage dependencies on Simple Hosting by adding the "composer.json" and "composer.lock" files in your project's root folder. To get Simple Hosting to install your dependencies, you'll need to use the "[[https://wiki.gandi.net/en/simple/git|Git+SSH]]" workflow to deploy your code, instead of uploading your files with sFTP. **Instructions:** - Place your ''composer.json'' file in your project's root folder - Run Composer to install the dependencies locally - Add both Composer files, ''composer.json'' and ''composer.lock'' to your git tree - [[https://wiki.gandi.net/en/simple/git#create_a_repository|Push your code to your VHOST's git repository]] - [[https://wiki.gandi.net/en/simple/git#deploy_your_code|Deploy the code with SSH]] Check out our [[https://wiki.gandi.net/en/tutorials/simple/php/composer|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.7 (Percona) is currently available to use with PHP instances on Simple Hosting. We also support MySQL 5.6 (Percona) and MySQL 5.5. 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 [[ en:simple:mysql | 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// connect_error) { error_log("Connection to MySQL failed: " . $conn->connect_error); return "NOT WORKING"; } return "OK"; }; ?> PHP MySQL on Simple Hosting

MySQL connection: .

=== PostgreSQL === PostgreSQL version 9.6 is currently available with PHP. We also support PostgreSQL 9.4 and 9.2 in older instances. 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 [[en:simple:posgtresql | 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 PostgreSQL on Simple Hosting

PostgreSQL connection: .

=== MongoDB === MongoDB 3.2 is the version currently available for PHP instances on Simple Hosting. We also support MongoDB 2.4 in older instances. 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. [[:en:simple:mongodb | 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') For PHP 5.6, PHP 7 and PHP 7.1 instances, you'll have to install the client-library yourself to use the pre-installed ''php-mongodb'' driver. [[#dependency_management | The recommended way to do this is to use Composer]] and add ''mongodb/mongodb ^1.0.0'' as a dependency and then [[en:simple:git | deploying your code with git+ssh]]. Below is a minimalistic code example to test the MongoDB database connection on Simple Hosting. It works with PHP 5.6, PHP 7 and PHP 7.1: //composer.json// { "require": { "mongodb/mongodb": "^1.0.0" } } //index.php// PHP and MongoDB on Simple Hosting

MongoDB connection: .

====Instance Management=== * [[en:simple:administration_of_your_instance|How to use your instance's administration page]] * [[en:simple:console|Logging into your instance with SSH]] * [[en:simple:sftp|How to log into your instance and upload files]] * [[en:simple:git|How to use git with Simple Hosting]] * [[https://github.com/Gandi/gandi.cli | Manage from the terminal with Gandi CLI ]] ===== Troubleshooting ===== * How to deal with strict headers http://httpd.apache.org/docs/trunk/en/env.html#fixheader