Tag Archives: Phpcloud

Setting up a connection to the Zend Developer Cloud on Linux

Connecting with the Zend DevCloud in Linux is actually quite easy if you know how to use SFTP.  When you first created your DevCloud account you would have been prompted to download your private key.  This is a private key that is generated, but not stored, on the DevCloud.  You can then connect with the simple command

 [root@localhost ~]# sftp [email protected]
 Connecting to kschroeder.my.phpcloud.com...
 sftp> ls
 applications www
 sftp>

or also with the -i flag if your private key is not in the default location.  Note, your container cannot be in a hibernating or sleep state.  If you get an error saying “permission denied” when you connect via SFTP it means that your container is probably not running.  Simply log in at my.phpcloud.com with your credentials and your containers will automatically start to spin up.

But, as I said in a previous post, I hate having to do command line stuff for each and every file or commit.  I like things to work seamlessly.  So what I did was write a PHP script that connects to the DevCloud (or any SSH-based endpoint for that matter) and then monitors all of the files and directories for changes, such as a creation, modification or deletion event.  It utilizes the inotify functionality in the Linux kernel and, as such, it requires the inotify PECL extension to be installed.  Since it also uses SFTP you will also need the SSH2 extension (which is bundled with Zend Server).

[root@localhost test]# pecl install --force inotify
WARNING: failed to download pecl.php.net/inotify within preferred state "stable", will instead download version 0.1.4, stability "beta"
downloading inotify-0.1.4.tgz ...
Starting to download inotify-0.1.4.tgz (9,166 bytes)
.....done: 9,166 bytes
3 source files, building
running: phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
building in /tmp/pear/temp/pear-build-root6TiXuA/inotify-0.1.4
running: /tmp/pear/temp/inotify/configure
 
...
 
Build process completed successfully
Installing '/usr/local/zend/lib/php_extensions/inotify.so'
install ok: channel://pecl.php.net/inotify-0.1.4
configuration option "php_ini" is not set to php.ini location
You should add "extension=inotify.so" to php.ini

Then you need to add the extension to php.ini.

Next you need to download the INotify/Push Changes script from GitHub.  There are several arguments, all of which are necessary to make the connection.  They all follow the –option=value format.  I could have used something more elegant but I really didn’t care.  :-)  The options are

  • project_dir – The local location of your project files
  • container – The name of the container you are connecting to, such as kschroeder.my.phpcloud.com
  • username – Your username
  • remote_dir – The remote directory where your application is deployed.  It will probably be something like /.apps/http/__default__/0/cli/1.0-zdc/public.
  • pubkey – This is the file that has your public key
  • privkey – This is the file that has your public key

Calling this script would be similar to this

php ./push-changes.php --project_dir=/projects/cli/
  --container=kschroeder.my.phpcloud.com 
  --remote_dir=/.apps/http/__default__/0/cli/1.0-zdc/public
  --pubkey=/root/.ssh/id_rsa.pub --privkey=/root/.ssh/id_rsa
  --username=kschroeder

after which you will see some watches being added

Connecting to kschroeder.my.phpcloud.com
 Watching /projects/cli/public
 Watching /projects/cli

If you edit a file in your Linux editor of choice you can then watch all of the changes that are being made and being uploaded.

/projects/cli/public/index.php created
Watching /projects/cli/public/index.php
put(/projects/cli/public/index.php /.apps/http/__default__/0/cli/1.0-zdc/public/index.php)
projects/cli/public/index.php deleted
unlink(/projects/cli/public/index.php /.apps/http/__default__/0/cli/1.0-zdc/public/index.php)
Watch for /projects/cli/public/index.php removed

One of the things I would like to add would be automatic synchronization but getting the files uploaded was the first priority.  One thing that also doesn’t seem to work is replicating rm -rf.  I saw the calls being made but the unlink didn’t work.  Maybe some work for when I have more time on my hands.

Setting up a generic connection to the Zend Developer Cloud on Windows

One of the things I have royally disliked about just about every cloud based development environment out there is that the tooling they offer usually has additional steps to push code onto the development instance in the cloud.  I, personally, do not like having to Alt-Tab between windows to do basic tasks.  Heck, I don’t even like touching the mouse unless my purpose is vanquishing Shub-Niggurath.  That’s why I like the auto-uploading features in Zend Studio and also in PHPStorm.

But what if you’re working off of the command line or using some IDE that doesn’t support uploading or Git integration?

If you’re on Windows, you’re in luck.  WinSCP can watch for changes on the file system and upload any changes to the DevCloud instance.

To get started you will need an application deployed on your DevCloud instance.  Deploy one of the packaged applications and get the Git URL from the DevCloud UI.

First, get your code from the Git repository.  I used Git for Windows.  Open up a CLI window to a project directory and clone the repo.

Next you need to is create a session in WinSCP

Specify the host name of the container along with your phpcloud username.  Make sure you specify the private key for your account and ensure that you have SFTP selected as the protocol.

Now that you have the connection set up, make the connection and go to “applications” and double click on the name of the application that you just deployed.  This will then take you to a directory under the .apps directory which is where your application actually lives.

Once there, click on the “Keep remote directory up to date” button.  This will watch for changes made to the local file system.  When you do that you will need to specify the remote directory as well as the local directory so you have a sync starting point.

Once you have done that WinSCP is ready to upload files.  Any time the file changes WinSCP will automatically upload the files for you.

Connecting to the Zend Developer Cloud with PHPStorm

Just because you want to use the Zend Developer Cloud at phpcloud.com doesn’t mean that you necessarily use Zend Studio.  While I may wonder why you don’t use Zend Studio ( :-) ) I know there are a lot of other good IDE’s on the market and an IDE like PHPStorm might suit how you do your development.

So how to get started.

With Zend Studio you can deploy an existing application by dragging a project onto a target.  The Git repository, document root and all that will be created and configured to work with your new application.  PHPStorm doesn’t currently have support to deploy an existing application like that (though it should be on their radar using the Zend SDK, IMHO).  But that doesn’t mean you’re out of luck.  You just need to do it differently.

First create a new blank project using the phpcloud.com UI.

Then clone the Git repository by copying it from the phpcloud.com UI.

Take the URL and then paste it into the Clone Repository box in PHPStorm and Clone it.

The next thing you need to then do is connect PHPStorm’s deployment tool to the DevCloud.

From there you will need to set up your connecting information.

  1. This is the hostname of the container
  2. This is the document root of the application.  Technically you should be getting to it through another directory that’s a symlink, but it doesn’t show in PHPStorm so you can just go to it directly
  3. This is your private key that you either downloaded when you created your account or the private key of the public key you uploaded.

Then you need to set up the path mapping.

Map it to the URI that you stated the application was living on.

Once you’ve done that select “Automatic Upload” from the Deployment menu item.

You’re ready now to start coding.  Create a simple index.php file with a phpinfo().  Right click on the project and tell the IDE to upload the code to your container.  Any changes you made should be reflected on your remote container now every time you change a file.

*note: I found that in order for the auto-upload function to work I also needed to set my container as the default deployment *

Also!  Note that I am primarily a Zend Studio developer.  There may be other ways of doing this in an easier manner.  Feel free to suggest them in the comments.

Connecting to PHPCloud.com through Zend Studio 9

PHPCloud.com is the landing page for our new cloud offering.  Using the Zend Application Fabric you can build your applications in the same environment as you will be deploying your apps to.  The application is built on my.phpcloud.com and you can then deploy it onto any platform where the Fabric is supported.

But how do you get started?  Phpcloud.com has been built in a way where you can connect with any IDE.  With Zend Studio 9 that connectivity has been built directly in to the IDE.

Getting started is actually quite easy.

Step 1 – Create a new project

Step 2 – Give that project a name!

Unlike with local development it really doesn’t matter where you put the project, it’s not going to be deployed locally anyway.  By default you will be given two options, the document root of the local server or the workspace.

 

Step 3 – Configure deployment options

This is where you connect up with phpcloud.  You are not going to be deploying to a production server.  The DevCloud (the thing you’re connecting to) is NOT a production box (I will go over this many times until you GET IT! :-) ) .  The first time you deploy your application it will do a full deployment to phpcloud.com it will do a full deployment.  Then as part of that deployment an SFTP connection will be set up and any time you save a file it will automatically uploaded.  The first full deployment is not done now, it is done later on.  This just sets it up.

If you do not have an existing PHPCloud.com connection set up for Studio you will need to enter in the username and password for PHPCloud.com as well as specifying your private key.  If you forgot to save the one that you were given you can always generate a new one from the UI.

 

 

 

Step 4 – Write Code

Ahhh.  Geek nectar.  Code.  Write some code.  If you have already deployed your application this code will automatically be uploaded to your container.

 

 

Step 5 – Launch the app

On the deployment page (double-click deployment.xml) click on the Launch a PHP application link.

Step 6 – Specify deployment params

Prior to launching the application you will need to specify the container that you want to deploy to as well as the URL.

 

Step 7 – Admire your work

Once the application has deployed it will be brought up in Studio’s default browser.

 

 

 

 

 

 

Connecting to your database in Zend Developer Cloud (Stupid Easy Remix)

Connecting to the database in the Zend Developer Cloud is quite easy.  You just need the container name, database name, username and password.  But what if you changed containers or your password?

If you want to make your application able to be easily moved between containers (and you should) here is a stupid easy way to do it.  Use get_cfg_var().

For example

1
2
3
4
5
6
7
8
9
10
11
$dsn = sprintf(
	'mysql:dbname=%s;host=%s',
	get_cfg_var('zend_developer_cloud.db.name'),
	get_cfg_var('zend_developer_cloud.db.host')
);
 
$db = new PDO(
	$dsn,
	get_cfg_var('zend_developer_cloud.db.username'),
	get_cfg_var('zend_developer_cloud.db.password')
);

Easy.

fatal: The remote end hung up unexpectedly

If  you are using phpcloud.com and are experiencing errors with git that look like this

git push
Password:
Counting objects: 722, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (711/711), done.
error: RPC failed; result=22, HTTP code = 411
fatal: The remote end hung up unexpectedly
Writing objects: 100% (719/719), 1.34 MiB | 1.32 MiB/s, done.
Total 719 (delta 340), reused 0 (delta 0)
fatal: The remote end hung up unexpectedly
Iatal: expected ok/error, helper said ’2004??LEOx?nq?; <
|DP?n,?U?EԎs?m?WX?G?Tl??jA?/?’

and you are trying to push large files (not sure what is defined as “large”) you may need to change some git settings.

on Windows use
[http]
postBuffer = 524288000

On Linux use
git config http.postBuffer 524288000

This is thanks to Boaz.  He posted the solution on our GetSatisfaction page.

What is phpcloud.com?

Well that’s a stupid question, isn’t it?  It’s “Development done right”, “Fast, Elastic, Dependable” and on “Any Cloud”, right?

If you are unclear as to what phpcloud.com is, what the Zend Application Fabric is and what the DevCloud is then this is a good post for you.

Before I say what it is, let me say what it is not.  It is NOT a hosting platform.  It is not intended for production usage.  It is intended to give you a quick DEVELOPMENT environment.  I use caps because I think this is the biggest source of confusion for people.  We have a path to production, but the containers that you will be working in are intended for development use and the functionality you will see in the future is going to reflect that.

First off is the Zend Application Fabric.  You may think about it as simply Zend Server.  While that might be true to some extent it is not complete.  Yes, the fabric runs on Zend Server but it is more than simply “Zend Server in the cloud”.  Think of a weaving loom.  One thread is just one thread.  Put two together and you have, well, two threads.  The Zend Application Fabric is kind of like the loom.  It keeps the whole application together and gives it structure without you doing much.  The fabric it creates can shrink or contact based on the needs of the time.  It’s kind of like your weaving loom were creating Marty McFly’s jacket in Back To The Future 2.

What it comes down to is that the Fabric is a combination of server components, APIs and runtimes.  The fabric is watching your application and responding to its needs.

The Zend Application Fabric is implemented in production solutions by installing Zend Server and integrating it into your environment, or by working with one of our cloud partners such as Amazon, IBM, Rackspace or Rightscale.  The key part is the integrating part.  That’s why we didn’t want to just call it “Zend Server in the Cloud”.  We intend for it to be more than just a place to run PHP or get error introspection but rather have it integrated into the automation in your infrastructure whether that automation is handled internally or by some kind of cloud management service.  But if your infrastructure can run Zend Server it can run the Fabric.

OK cool.  So if that’s for production what is the DevCloud?  The DevCloud is a slice of the Fabric running in the cloud.  A thread of the fabric, as it were.  It won’t scale, it’s not meant for hosting (though some people have tried) and it won’t give you the same freedom that you might be used to in local development.  But wait!  Isn’t that a bad thing?!  Well, not really.  Think of this for a bit.  How much crap has gone into PHP applications because people could do whatever it is they felt like doing at the time?  Anarchy, as fun as it may be, does not work.  Not in real life and not in software development.  Have a defined, predictable environment makes for easy transferal of skills and stable environments.  For example, there are a bunch of PECL extensions that are perfectly stable but many that are not or are unsupported.  Depending on an unsupported extension in a production environment is generally a bad thing.  And for any type of fabric mixing materials is generally not good.  For example, you wouldn’t mix kevlar threads with water soluble basting threads.  As more PHP development moves into the cloud I believe that PHP developers are going to have to become less used to hacking things together.  If you keep hacking things that means you have to manage them and if you’re managing them they you’re losing the benefits of the cloud.

And phpcloud.com?  That’s the place to start.  You do your development off of the infrastructure in phpcloud.com.  The infrastructure is built on the Zend Application Fabric.  Therefore when you deploy to your production environment, based off of the Zend Application Fabric, you have the same environment that you built it on.

So, the Fabric is the loom, DevCloud is a thread spool and phpcloud.com is the lever you pull to start.

Web Analytics