Playing with PHP on Azure
A Zend experience
Cédric Derue – GWAB 2014
 Web Architect @ Altran
 Skills:
•  Zend Framework 2
•  ASP.NET MVC
•  JavaScript
•  NoSQL
 Twitter: @cderue
Cédric Derue
 You love PHP,
 You love scripting,
 You love pachyderms,
 You know Windows?
Who this session is for?
 Cloud Computing definition
 Windows Azure introduction
 Zend Framework 2 use case
 Azure Web Sites
 Azure Storage
Agenda
Cloud Computing origin
 Arpanet
 Amazon
 Google
 HP
 Microsoft
Windows Azure solution
Choose your ressources
App
A simple equation to summary Windows Azure
Blocs de
construction
applicatif
Compute Application blocks
Infra for building and deploying apps
 Evolutive and scalable
 Fault tolerance
 On demand
 Pay for what you use
Windows Azure benefits
Azure free trial
Windows Azure Portal
Windows Azure execution models
Cloud Services
Mobile Services
Virtual Machines
Web Sites
Virtual Machines
Highly
configurable
Windows Server
or Linux
IaaS
Scalable
Web Sites
.NET, PHP,
Python, Node.js,
Java
IIS
PaaS
Scalable
Mobile Services
Android
iOS
HTML
Hybrid
Storage
Authentication
Push
Monitoring
MBaaS
Scalable
Cloud Services
Highly
configurable
IIS
PaaS (Web &
Worker Roles)
Scalable
How to choose the right(s) model(s)?
 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
Create a new Web Site on Azure
Configuring source control
Explore Azure Web Site(s)
Managing configuration
 Modular
 Extensible
 High performing
 Secure
 Enterprise ready
 Community
Why Zend Framework 2?
> 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
<?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
> git remote add origin
https://cderue@zf2.scm.azurewebsites.net:443/zf2.git
> git remote -v
> git push origin master
Publishing with Git
First sign of life
http://zf2.azurewebsites.net
Understanding ZF2 app structure
Discovering ZF2 modules
http://modules.zendframework.com
{
"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
 ZfcUser  Authentication
 MyFixIt  Task Management
Which modules for our demo?
 Authentication is to verify that a person or
entity is what it claims to be.
 Authentication is not authorization.
Authentication
ZendAuthentication principle
Storage
ZendAuthenticationAuthenticationService
Adapter
Db LDAP … Db Session …
"require": {
"zf-commons/zfc-user": "dev-master"
}
Install ZfcUser module
<?php
return array(
'modules' => array('ZfcBase','ZfcUser')
);
 Post installation
 Installation
The MyFixIt module
 Domain Driven Design
 Dependency injection
 Table Storage
 Blob storage
 Environment specific configuration
 Reversibility
Exploring the FixIt module
 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
 Azure SQL Database
 Azure Table Storage
 Azure Blob Storage
 Others…
Working with data on Azure
$adapter = new ZendDbAdapterAdapter(
array(
'driver' => 'pdo',
'dsn' => '<dsn>'
'database' => '<mysql_db>',
'username' => '<db_user>',
'password' => '<db_user_password>',
'hostname' => '<hostname>',
)
);
Access to MySQL Azure with ZendDb
Store and access data with:
 Blob (large binary or text data)
 Table (non relational data)
 Queue (messages)
Azure Storage Services overview
 Storage in the form of tables
 Flexible schema
 High performance
 REST API
Azure Table Storage
Azure Blob Storage
Account Container Blob
cedric
pictures
movies Man of Steel.avi
Beyonce.jpg
Shakira.png
Explore Azure Storage
 Windows Azure SDK for PHP
 Zend Framework 2 components
 Symfony 2 bundles
Working with PHP on Azure
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
Install Windows Azure SDK
"require": {
"microsoft/windowsazure": "*" },
"repositories": [
{
"type": "pear",
"url": "http://pear.php.net"
}
],
"minimum-stability": "dev"
}
 Installation
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!
Switch beetween two configuration files:
 config/autoload/module.myfixit-
azure.local.php
 config/autoload/module.myfixit-
onpremise.local.php
Switch with env specific config
"require": {
"doctrine/doctrine-mongo-odm-module": "dev-master"
}
Install Doctrine ODM module
<?php
return array(
'modules' => array(
'DoctrineModule', 'DoctrineMongoODMModule'
)
);
 Installation
 Post installation
return array(
'doctrine' => array(
'connection' => array(
'server' => 'localhost',
'port' => '27017',
'user' => '<user_name>',
'password' => '<password>',
'dbname' => '<db_name>',
),
),
);
Connect to MongoDB with Doctrine
It’s time to demo
 New Relic
 Application Insights
 Zend Server (PHP only)
Monitoring your cloud applications
http://windowsazure-trainingkit.github.io/
http://blogs.msdn.com/b/microsoft_press/archive/tags/
azure/
http://www.pluralsight.com/training/
https://github.com/WindowsAzure/azure-sdk-for-php
https://www.windowsazure.com/fr-fr/support/legal/sla/
Resources
Windows Azure makes all you want …
…except French Kiss!
Summary
Thank you!

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