Giter VIP home page Giter VIP logo

example-php's Introduction

PHP Quick Start Guide

This guide will walk you through deploying a PHP application on Deis.

Prerequisites

If you do not yet have a controller or a Deis formation, please review the Deis installation instructions.

Setup your workstation

  • Install RubyGems to get the gem command on your workstation
  • Install Foreman with gem install foreman
  • Install Xampp) or MAMP PRO so that you have an environment that can run PHP

Clone your Application

If you want to use an existing application, no problem. You can also use the Deis sample application located at https://github.com/opdemand/example-php. Clone the example application to your local workstation:

$ git clone https://github.com/opdemand/example-php.git
$ cd example-php

Prepare your Application

To use a PHP application with Deis, you will need to conform to 3 basic requirements:

  1. Use Composer to manage dependencies
  2. Use Foreman to manage processes
  3. Use Environment Variables to manage configuration inside your application

If you're deploying the example application, it already conforms to these requirements.

1. Use Composer to manage dependencies

Composer requires that you explicitly declare your dependencies using a composer.json file that sits in the root directory of your project. Here is a very basic example:

{ 
	"require": { 
	    "illuminate/foundation": "1.0.*"
	},
	"minimum-stability": "dev"
}

You can then install dependencies on your local workstation with php composer.phar install:

For more information on using Composer, we recommend you read this blog post

2. Use Foreman to manage processes

Deis relies on a Foreman Procfile that lives in the root of your repository. This is where you define the command(s) used to run your application. Here is an example Procfile:

web: sh boot.sh

This tells Deis to run web workers using the command sh boot.sh.

Since PHP runs explicitly on a web server, you won't be able to use Foreman locally. Rather, test locally using Xampp or Mamp Pro.

3. Use Environment Variables to manage configuration

Deis uses environment variables to manage your application's configuration. For example, your application listener must use the value of the PORT environment variable. The following code snippet demonstrates how this can work inside your application:

port = getenv(PORT);

Create a new Application

Per the prerequisites, we assume you have access to an existing Deis formation. If not, please review the Deis installation instuctions.

Use the following command to create an application on an existing Deis formation.

$ deis create --formation=<formationName> --id=<appName>
Creating application... done, created <appName>
Git remote deis added

If an ID is not provided, one will be auto-generated for you.

Deploy your Application

Use git push deis master to deploy your application.

$ git push deis master
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 2.83 KiB, done.
Total 3 (delta 1), reused 0 (delta 0)
       PHP app detected
-----> Bundling mcrypt version 2.5.8
-----> Bundling Apache version 2.2.25

Once your application has been deployed, use deis open to view it in a browser. To find out more info about your application, use deis info.

Scale your Application

To scale your application's Docker containers, use deis scale and specify the number of containers for each process type defined in your application's Procfile. For example, deis scale web=8.

$ deis scale web=8
Scaling containers... but first, coffee!
done in 19s

=== <appName> Containers

--- web: `sh boot.sh`
web.1 up 2013-10-28T20:23:58.904Z (phpFormation-runtime-1)
web.2 up 2013-10-30T17:24:35.783Z (phpFormation-runtime-1)
web.3 up 2013-10-30T17:24:35.801Z (phpFormation-runtime-1)
web.4 up 2013-10-30T17:24:35.815Z (phpFormation-runtime-1)
web.5 up 2013-10-30T17:24:35.831Z (phpFormation-runtime-1)
web.6 up 2013-10-30T17:24:35.847Z (phpFormation-runtime-1)
web.7 up 2013-10-30T17:24:35.865Z (phpFormation-runtime-1)
web.8 up 2013-10-30T17:24:35.885Z (phpFormation-runtime-1)

Configure your Application

Deis applications are configured using environment variables. The example application includes a special POWERED_BY variable to help demonstrate how you would provide application-level configuration.

$ curl -s http://yourapp.yourformation.com
Powered by Deis
$ deis config:set POWERED_BY=PHP
=== <appName>
POWERED_BY: PHP
$ curl -s http://yourapp.yourformation.com
Powered by PHP

deis config:set is also how you connect your application to backing services like databases, queues and caches. You can use deis run to execute one-off commands against your application for things like database administration, initial application setup and inspecting your container environment.

$ deis run ls -la
total 44
drwxr-xr-x  8 root  root  4096 Oct 30 17:23 .
drwxr-xr-x 57 root  root  4096 Oct 30 17:28 ..
drwxr-xr-x  2 root  root  4096 Oct 30 17:23 .profile.d
-rw-r--r--  1 root  root    45 Oct 30 17:23 .release
-rw-r--r--  1 root  root    15 Oct 30 17:23 Procfile
drwxr-xr-x 15 14436 14436 4096 Aug 29 23:48 apache
drwxr-xr-x  2 root  root  4096 Oct 30 17:23 bin
-rwxr-xr-x  1 root  root   370 Oct 30 17:23 boot.sh
drwx------  7 14436 14436 4096 Oct 30 17:23 php
drwxr-xr-x  3 root  root  4096 Oct 30 17:23 vendor
drwxr-xr-x  5 root  root  4096 Oct 30 17:23 www

Troubleshoot your Application

To view your application's log output, including any errors or stack traces, use deis logs.

$ deis logs
Oct 30 17:27:12 ip-172-31-25-226 jagged-playroom[web.7]: 172.31.25.226 - - [30/Oct/2013:17:27:12 +0000] "GET / HTTP/1.0" 200 1579
Oct 30 17:27:12 ip-172-31-25-226 jagged-playroom[web.4]: 172.31.25.226 - - [30/Oct/2013:17:27:12 +0000] "GET / HTTP/1.0" 200 1579
Oct 30 17:27:12 ip-172-31-25-226 jagged-playroom[web.5]: 172.31.25.226 - - [30/Oct/2013:17:27:12 +0000] "GET / HTTP/1.0" 200 1579

Additional Resources

example-php's People

Contributors

bengrunfeld avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.