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
- PHP environment variables
- Important PHP files
- About rewrites
- FAQs
Prerequisites
- This article assumes you already have an Engine Yard account. If not, see Sign up for an Engine Yard Account.
- If you have a previous PHP environment, then you need to know your current Stack version before you upgrade to the May 14th stack release (or later). See Why your current stack affects your PHP upgrade path. Remember that every environment where you intend to use PHP on Engine Yard Cloud is affected.
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
-
On the Engine Yard Cloud dashboard, click
-
Configure the PHP application.
- 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.
- Click
-
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.
- Click
-
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.
- Click
- 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
- Open
/data/APPNAME/shared/config/env.custom
and see the example at the top of that file. - Add your custom variables and save the file.
-
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:
- Install the
dev-php/pecl-ssh2
package from our custom Chef cookbook. - 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"}]
- Include the custom cookbook in the main cookbook recipe,
main/recipes/default.rb
:require_recipe "packages"
- 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 settingE_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?
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.
Priyanka Bhotika
Comments