Many web developers prefer to keep their projects consistently synchronized with a staging server. This enables previewing how the code works and debugging it on the server right away. Currently, Zend Studio has very limited support for such a scenario. However, the functionality of Zend Studio can sometimes easily be extended using the Eclipse platform features.
This article suggests a way to synchronize your projects with a remote Linux server using 'rsync'.
These are the main steps you need to perform:
The procedures in this article are based on the following assumptions:
Rsync in the simplest case uses SSH for communication with remote hosts. To be able to synchronize your work seamlessly with the server, you need to configure passwordless SSH authentication on the Linux server. The synchronization will take place at each Save action and you don't want to be asked for SSH password every time.
First, you need to create an authentication key pair. But before you do this, make sure that you don't have the keys already in:
The key files are usually called 'id_rsa' and 'id_rsa.pub' or 'id_dsa' and 'id_dsa.pub'. If you have these files, you probably want to use the existing keys, thus skipping step 5.
Note:
It is important to put the key files in '.ssh' because the generic SSH client (used by rsync) expects to find them in this location. Although the SSH home setting can be overridden when saving the generated keys, I believe it's a good idea to have both Zend Studio and the generic SSH client use the same directory.
Note:
Leave the Passphrase field empty. As explained earlier, we want to have fully automated authentication.
C:\> set HOME=%USERPROFILE%
C:\> cd C:\Program
Files\cwRsync\bin
C:\Program Files\cwRsync\bin> ssh
developer@staging-server
Welcome to the staging
server!
developer@staging-server:~$ pwd
/home/developer
$ ssh
developer@staging-server
Welcome to the staging
server!
developer@staging-server:~$ pwd
/home/developer
Eclipse provides the interface for creating custom action-sets that will be performed on a project during the build process. These actions can use external programs or scripts. We will utilize this functionality of Eclipse to synchronize a PHP Project with a remote Linux machine.
Listing of rsyncExclude.txt:
.project
.buildpath
.settings
.cache
.svn
.externalToolBuilders
rsyncExclude.txt
*.gif
Note:
/usr/bin/rsync is the correct path for MacOS and most Linux flavors. However, it is recommended to verify this by issuing the command which rsync in a console window.
-vcrz
–delete-after
–exclude-from=rsyncExclude.txt
.
developer@staging-server:public_html
Click New again to add a new environment viarible %HOME% which is required for proper operation of SSH:
To test the new builder, perform the following operations in the project and verify that they are reflected on the server. Each action should produce output in the Console view of Zend Studio:
Also make sure that no files or directories listed in the excludes file (rsyncExclude.txt) have been transferred to the server.
-v | Verbose. Output basic information about the operation in progress. To have more detailed output use -vv or -vvv. |
-c | Checksum. Use checksum verification rather than timestamp and size comparison to decide about the list of files to be updated. |
-r | Recursive. Scan directories recursively to synchronize all changes in the tree. |
-z | Compression. Instructs rsync to compress the file contents when transferring it to the server. |
–delete-after | Instructs rsync to delete files and directories on the server, if they don't exist in the project. Basically, this parameter replicates the deletion of a project resource to the server. |
–exclude-from=rsyncExclude.txt | Specifies the file that contains the list of resources to be ignored during the synchronization. Wildcards are allowed in this file. |
. | Synchronization source. '.' means current working directory. |
developer@staging-server:public_html | Synchronization target. In this example the path on the server is relative to the 'developer' user home directory. However, an absolute path can be specified, for example – developer@staging-server:/var/www |
Copyright © 2011 - All Rights Reserved - Softron.in
Template by Softron Technology