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
 sftp> ls
 applications www

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 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 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/'
install ok: channel://
configuration option "php_ini" is not set to php.ini location
You should add "" 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
  • 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/ 
  --pubkey=/root/.ssh/ --privkey=/root/.ssh/id_rsa

after which you will see some watches being added

Connecting to
 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.

Leave a Reply

Your email address will not be published.