55
Playing with PHP on Azure A Zend experience Cédric Derue – GWAB 2014

Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Embed Size (px)

DESCRIPTION

Global Windows Azure Bootcamp : Cedric Derue playing with php on azure Sponsor Annuel: Viseo

Citation preview

Page 1: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Playing with PHP on Azure

A Zend experience

Cédric Derue – GWAB 2014

Page 2: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Web Architect @ Altran

Skills: • Zend Framework 2

• ASP.NET MVC

• JavaScript

• NoSQL

Twitter: @cderue

Cédric Derue

Page 3: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

You love PHP,

You love scripting,

You love pachyderms,

You know Windows?

Who this session is for?

Page 4: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Cloud Computing definition

Windows Azure introduction

Zend Framework 2 use case

Azure Web Sites

Azure Storage

Agenda

Page 5: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Cloud Computing origin

Arpanet

Amazon

Google

HP

Microsoft

Page 6: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Windows Azure solution

Page 7: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Choose your ressources

App

Page 8: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

A simple equation to summary Windows Azure

Blocs de

construction

applicatif

Compute Application blocks

Infra for building and deploying apps

Page 9: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Evolutive and scalable

Fault tolerance

On demand

Pay for what you use

Windows Azure benefits

Page 10: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Azure free trial

Page 11: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Windows Azure Portal

Page 12: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Windows Azure execution models

Cloud Services

Mobile Services

Virtual Machines

Web Sites

Page 13: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Virtual Machines

Highly

configurable

Windows Server

or Linux

IaaS

Scalable

Page 14: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Web Sites

.NET, PHP,

Python, Node.js,

Java

IIS

PaaS

Scalable

Page 15: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Mobile Services

Android

iOS

HTML

Hybrid

Storage

Authentication

Push

Monitoring

MBaaS

Scalable

Page 16: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Cloud Services

Highly

configurable

IIS

PaaS (Web &

Worker Roles)

Scalable

Page 17: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

How to choose the right(s) model(s)?

Page 18: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Create a new Azure Web Site

Start a new ZF2 app on Azure

Add ZF2 modules

Work with relational data on Azure

Work with non relational data on Azure

Install Windows Azure SDK for PHP

Demonstrate reversibility

PHP Azure Web Site demo

Page 19: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Create a new Web Site on Azure

Page 20: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Configuring source control

Page 21: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Explore Azure Web Site(s)

Page 22: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Managing configuration

Page 23: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Modular

Extensible

High performing

Secure

Enterprise ready

Community

Why Zend Framework 2?

Page 24: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

> composer create-project

--repository-url=

"https://packages.zendframework.com"

-s dev

zendframework/skeleton-application

<path/to/install>

> composer update

> php -S localhost:8080 -t public/ public/index.php

Initialize a new ZF2 app

Page 25: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="MyFixIt" stopProcessing="true"> <match url="^(.*)$" ignoreCase="false" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" /> </conditions> <action type="Rewrite" url="index.php" /> </rule> </rules> </rewrite> </system.webServer> </configuration>

Web.config

Page 26: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

> git remote add origin

https://[email protected]:443/zf2.git

> git remote -v

> git push origin master

Publishing with Git

Page 27: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

First sign of life

http://zf2.azurewebsites.net

Page 28: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Understanding ZF2 app structure

Page 29: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Discovering ZF2 modules

http://modules.zendframework.com

Page 30: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

{ "name": "cderue/zf2-myfixit", "description": "MyFixIt Application for ZF2", "license": "Apache License, Version 2.0", "keywords": [ "framework", "zf2", "azure" ], "homepage": "http://github.com/cderue", "minimum-stability": "alpha", "require": { "php": ">=5.3.3", "zendframework/zendframework": "2.2.*", } }

Composer

Page 31: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

ZfcUser Authentication

MyFixIt Task Management

Which modules for our demo?

Page 32: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Authentication is to verify that a person or

entity is what it claims to be.

Authentication is not authorization.

Authentication

Page 33: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Zend\Authentication principle

Storage

Zend\Authentication\AuthenticationService

Adapter

Db LDAP … Db Session …

Page 34: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

"require": {

"zf-commons/zfc-user": "dev-master" }

Install ZfcUser module

<?php return array( 'modules' => array('ZfcBase','ZfcUser') );

Post installation

Installation

Page 35: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

The MyFixIt module

Page 36: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Domain Driven Design

Dependency injection

Table Storage

Blob storage

Environment specific configuration

Reversibility

Exploring the FixIt module

Page 37: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

With Azure, data can be stored in different

systems like SQL or/and NoSQL databases,

blobs, drives, etc.

Azure provides data management services

for reporting or Big Data computing.

Working with data

Page 38: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Azure SQL Database

Azure Table Storage

Azure Blob Storage

Others…

Working with data on Azure

Page 39: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

$adapter = new Zend\Db\Adapter\Adapter( array( 'driver' => 'pdo',

'dsn' => '<dsn>' 'database' => '<mysql_db>', 'username' => '<db_user>', 'password' => '<db_user_password>',

'hostname' => '<hostname>', ) );

Access to MySQL Azure with Zend\Db

Page 40: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Store and access data with:

Blob (large binary or text data)

Table (non relational data)

Queue (messages)

Azure Storage Services overview

Page 41: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Storage in the form of tables

Flexible schema

High performance

REST API

Azure Table Storage

Page 42: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Azure Blob Storage

Account Container Blob

cedric

pictures

movies Man of Steel.avi

Beyonce.jpg

Shakira.png

Page 43: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Explore Azure Storage

Page 44: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Windows Azure SDK for PHP

Zend Framework 2 components

Symfony 2 bundles

Working with PHP on Azure

Page 45: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Windows Azure SDK for PHP

Windows Azure SDK for PHP

PHP Client Librairies

Command Line Tools

Azure Emulators

Windows Azure

REST API

Compute Storage Manage

My PHP application

Page 46: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Install Windows Azure SDK

"require": {

"microsoft/windowsazure": "*" }, "repositories": [

{

"type": "pear",

"url": "http://pear.php.net" }

],

"minimum-stability": "dev"

}

Installation

Page 47: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

When you deploy an application on the cloud,

the reversibility must be taken into account to

allow execution on premise if you decide to

leave the cloud.

Think reversibility!

Page 48: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Switch beetween two configuration files:

config/autoload/module.myfixit-

azure.local.php

config/autoload/module.myfixit-

onpremise.local.php

Switch with env specific config

Page 49: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

"require": {

"doctrine/doctrine-mongo-odm-module": "dev-master"

}

Install Doctrine ODM module

<?php

return array( 'modules' => array(

'DoctrineModule', 'DoctrineMongoODMModule'

) );

Installation

Post installation

Page 50: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

return array(

'doctrine' => array(

'connection' => array(

'server' => 'localhost',

'port' => '27017',

'user' => '<user_name>',

'password' => '<password>',

'dbname' => '<db_name>',

),

),

);

Connect to MongoDB with Doctrine

Page 51: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

It’s time to demo

Page 52: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

New Relic

Application Insights

Zend Server (PHP only)

Monitoring your cloud applications

Page 54: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Windows Azure makes all you want …

…except French Kiss!

Summary

Page 55: Global Windows Azure Bootcamp : Cedric Derue playing with php on azure. (sponsor Annuel du MUG-Lyon: Viseo)

Thank you!