Knowledge Base/Engine Yard Cloud Documentation/Deploy your Application

Deploy Your PHP Application on Engine Yard Cloud

Keri Meredith
posted this on April 03, 2013 05:46 PM

Updated: November 20th, 2013

This document describes how to deploy a PHP application on Engine Yard Cloud.

Get started with PHP on Engine Yard Cloud

Prerequisites

Configure a PHP application environment

Important: We recommend testing in a staging environment before applying changes in a production environment.

To configure a PHP application environment

  1. On the Engine Yard Cloud dashboard, click AddApplicationButton.png

  2. Configure the PHP application.

    PHPAppConfig.png

    • Application Language: PHP
    • Git Repo URI: Click to select our sample HowTo app or enter git information for your own app.
    • Application Name: Enter a unique name for your app (with no spaces).
    • Web Root: The default of public/ is a good practice for security reasons.
  3. Click CreateApplicationButton.png
  4. Configure the environment for the app.

    Note: Do not add a PHP app to an existing non-PHP environment.

    • Framework Environment: Your selection populates PHP_ENV. For example, if you choose production, this is the equivalent to entering the environment variable PHP_ENV=production in the command line.
    • App Server Stack: PHP-FPM is available for PHP apps.
    • Stack: The default is Engine Yard Gentoo 12.11 (stable-v4).
    • Database: You can select PostgreSQL, MySQL, or No Database.
    • Environment Options: If you need help with the remaining selections, see Create an Environment.
  5. Click CreateEnvironmentButton.png
  6. On the Configuration page, select the instances you need.

    You can create a single or multi-instance environment. See Boot your environment if you need more information.

  7. Click BootConfigButton.png
  8. Deploy your application.

PHP environment variables

Each PHP framework has a different path and format for application configuration. Engine Yard Cloud exposes database and environment variables to PHP applications.

To use the default variables

  • DB_USER: User name to connect to the database.
  • DB_PASS: Password to connect to the database.
  • DB_HOST: Public host name of the database master.
  • DB_NAME: Database name.
  • PHP_ENV: Environment (e.g., production, staging, development).

These variables can be accessed as follows. For example, to get the database host name:

$_SERVER["DB_HOST"]

Note: In some situations (for example, when using an ini file with parse_ini_file()) you'll need to use the curly brace variable syntax:

${_SERVER["DB_HOST"]}

To add your own custom variables

  1. Open /data/APPNAME/shared/config/env.custom and see the example at the top of that file.
  2. Add your custom variables and save the file.
  3. Click Apply on the application's environment page.

    Your custom variables will persist.

Install and Enable PHP Extensions

Install and enable the SSH2 extension to provide bindings to the libssh2 library.

To install and enable PHP extension:

  1. Install the dev-php/pecl-ssh2 package from our custom Chef cookbook.
  2. In the cookbook, update packages/attributes/packages.rb with the package that you want to install:

    default[:packages] = [{:name => "dev-php/pecl-ssh2", :version => "0.11.3-r1"}]

  3. Include the custom cookbook in the main cookbook recipe, main/recipes/default.rb:

    require_recipe "packages"

  4. Upload and apply the cookbooks.

For more information on using custom Chef with Cloud, see Customize Your Environment with Chef Recipes

Important PHP files

Here are the paths to some frequently used files.

To access config files

  • PHP config/etc/php/[cgi,cli,fpm]-php5.4/php.ini
  • Extension configs/etc/php/[cgi,cli,fpm]-php5.4/ext-active/*.ini
  • PHP-FPM global config/etc/php-fpm.conf
  • PHP-FPM pool config (per app)/data/REPLACE_WITH_APPNAME/shared/config/fpm-pool.conf

To access log files

  • PHP error log/var/log/php.error.log with the following setting E_ALL & ~E_DEPRECATED & ~E_STRICT
  • FPM error log/var/log/engineyard/php-fpm/error.log

About rewrites

The default rewrite logic works for most PHP applications:

  • If the file does not exist, then rewrite the request to index.php.
  • If a user tries to access /config and you have not set a web root, then a 404 error occurs. This is best practice for security since configs are in that directory.

FAQs

You might have these questions about PHP on Engine Yard Cloud.

Can I still use Orchestra PHP Cloud?

No; the Orchestra PHP Cloud product end of life (EOL) was August 30, 2013. If you need help, contact Engine Yard Support.

What about the Engine Yard preview with PHP?

We are excited about the upcoming preview, which will give you a glimpse into the new user experience and future of Engine Yard Cloud. The first preview uses PHP and will be your chance to provide feedback.

What are the tech stack components for PHP on Engine Yard Cloud?

You can view our deployed phpinfo app for full stack details. Or here's a quick overview:

  • Load balancer: HAProxy
  • Web server: Nginx
  • App server (CGI gateway): PHP-FPM
  • PHP extensions: bcmath, bz2, calendar, ctype, curl, date, dba, dom, ereg, exif, fileinfo, filter, ftp, gd, gettext, hash, iconv, imap, intl, json, libxml, mbstring, mcrypt, memcache, mhash, mongo, mysql, mysqli, mysqlnd, openssl, pcntl, pcre, PDO, pdo_mysql, pdo_pgsql, pdo_sqlite, pgsql, Phar, posix, pspell, readline, redis, Reflection, session, SimpleXML, snmp, soap, sockets, SPL, sqlite3, standard, tokenizer, xml, xmlreader, xmlrpc, xmlwriter, xsl, zip, zlib
  • Database options: MySQL 5.5, PostgreSQL 9.2, No Database (and including Riak and MongoDB as utility instances)
  • Engine Yard Gentoo 12.11 - This is the default stack for GA PHP.
  • MySQL 5.5 - This is the default version for MySQL. (MySQL 5.0 is no longer supported with GA PHP.)
  • 64 bit only - (optional) If you have had an Engine Yard account for a while and have access to 32-bit instances, you might want this. If you do not currently have any 32-bit instances deployed, then we can set this for you. Contact Engine Yard Support for help with this option.

What if I really need PHP 5.3?

The default version of PHP on Engine Yard Cloud is 5.4. If you need PHP 5.3, you can check out this doc or contact Engine Yard Support.

Can you use Chef with PHP on Engine Yard Cloud?

Yes; we've created this basic repo: https://github.com/engineyard/ey-cloud-recipes-chef-10 (from our previous repo that used .06) and have included a PHP 5.3 downgrade recipe in case you need it. You can clone this repo and then add recipes using standard Chef 10 best practices.

Are deploy hooks supported with PHP on Engine Yard Cloud?

Yes; deploy hooks are supported, they just need to be written in Ruby. See Use Deploy Hooks for more information.

Do all the Engine Yard Cloud add-ons work with PHP?

These add-ons work out-of-the-box:

  • Blitz.io
  • LogEntries
  • AppFirst
  • DynECT
  • StillAlive

These add-ons should work for integrated billing but require manual configuration in your app and may fail if the credentials were to change:

  • Mailgun
  • SendGrid
  • MongoLab
  • MongoHQ
  • Librato Metrics
  • IronWorker
  • IronMQ
  • Cloudinary
  • StatsMix

If you have feedback or questions about this page, add a comment below. If you need help, submit a ticket with Engine Yard Support.