This remote file synch method works for any version of Zend Studio. I originally started doing it in v7.2, and I just carried it forward. It relies on rsync which is part of the standard Unix distribution. If you are running Linux or MACOSX, you most likely already have it as /usr/bin/rsync (do a "which rsync" to verify it's installed and note down the location). If you are running windows, you'd have to install it. There is a version for windows, but I have not tested it.
I first tried using the built in remote server functionality in Zend Studio 7.2. You can access this by going to the "Servers" tab which is in the lower right corner of the default PHP perspective. If you select servers and then connection, you can configure a remote server. You can then highlight the project, right click it to get the right click menu, and select Team|Share Project, and away you go. The problem with this is it's not very configurable, and it insists on instantiating the project directory "SuperCoolTool" (or whatever) on the remote server, which is probably not what you want. Also, if you select any files to publish initially, they ignore the local file path and end up going into the server's base directory. While this would have been nice to have, it clearly wasn't ready for prime time in v7.2.
You'll generally manage an AWS EC2 box through SSH with RSA keys. If you haven't used an RSA key before on your current machine, then you need to set it up. There's a ton of info on that out there, so I am not going to go into that here. For this sync method to work, you need to be able to SSH into the target server using a public/private key pair, and I assume you already have this setup for the remainder of this tutorial.
Go to a command prompt, and execute:
ssh remote_username@remote_server
You should be sitting in the base user directory for "remote_username" on the remote machine (remote server=either the IP address or domain if you have it aliased in /etc/hosts). If you get access denied, you don't have your public key setup properly. So you need to fix it before proceeding.
While you are on the remote server, navigate to the base directory when you want your synched code to end up (maybe "site/root" or whatever) and make a note of the path.
The final server name you will use for rsync is:
remote_username@remote_server:site/root
so make a note of it.
You need to advise Zend Studio where those SSH keys are to use them. Go to the "Zend Studio" on the menu bar and open the "Preferences" menu. Select SSH2, and then (under the General Tab), select the SSH2 home directory which should already exist if you have working SSH and is located in your /Users/username/.ssh directory.
Select "Add Private Key" and select your private key which is probably named "id_rsa" (I imagine you can use id_dsa as well. I have both on my machine).
Hit "Apply" and then "OK" and quit out of the menu.
Now we are going to configure rsync so it will run automatically in the background any time we make any change to a file in our project.
Since we likely don't want every single file change to be mirrored, we need an exclusion list of files we don't want Zend Studio to mess with.
So, create an exclusion file in the base of your Zend Studio project.
Name the file: rsyncExclusion.txt.
It should contain the following:
.htaccess
.settings
.project
.buildpath
.settings
.cache
.svn
Rakefile.rb
Gemfile
Gemfile.lock
.externalToolBuilders
*.gif
/test/
/tools/
docroot
app.ini
Save it. You will probably need to adjust this later, but it's a decent start.
Highlight the project. Right click it. Select properties from the right click menu. Navigate to Builders. Select the "New..." button on the right side of the dialog box. Select "Program" as the option. This produces another dialogue box.
In the "Main" tab (default starting point)
Name: New Builder of some kind (whatever you want)
Location: user/bin/rsync
Working Directory: (select the "Variables... button and choose "build_project"
Arguments: (going to run through these in a second)
-vcrz
--copy-links
--delete-after
--exclude-from=rsyncExclude.txt
.
remote_username@remote_server:site/root
(Before you proceed further, you may want to change "-vcrz" to "-nvcrz" for testing.
-n = dry run (won't actually alter any files)
-v = verbose error messages
-c = use a checksum to identify files (vs name and date)
-r = recurse subdirectories and synch everything
-z = compress the file stream for better performance
--copy-links copy any symbolic links on the local copy as real directories on the remote server
--delete-after delete any files on remote server that are not on the local one
--exclude-from=rsyncExclude.txt
In the "Build Options" tab (tick the following):
Allocate Console
Launch in background
After a "Clean"
During manual builds
During auto builds
During a "Clean"
Uncheck anything else and hit OK
This should start synching immediately.
As noted, rsyncExclude.txt is a file in the base of your project. It has all file exclusions you want. Anything in the list will be excluded from synch. So if .htaccess is on the remote machine, but not on the local one, it will not be deleted IF IT IS ON THE LIST. Otherwise, kiss it goodbye. If you don't put the "--delete-after" option in there, it will not delete files remotely when you delete them locally.
Let's go over the exclude format a bit:
/tools/
docroot
app.ini
The option I have used here will only exclude tools/ if it is in the base directory
If you want any directory named tools excluded even if it's not at the base, it would be:
tools/
"docroot" in the list above is meant to protect a link such as:
ln -s public docroot
that is only on the remote server and not on the local one.
As can be seen by this example, you can protect files from deletion from the server as well as prevent inclusion from the local machine with the same list.
Once you hit okay, Zend Studio will now manage the file process in the background. Any trouble you run into can likely be solved by adjusting the file exclusion list (assuming you actually had SSH working before you started attempting rsync). I have found this to be a very reliable method of keeping a remote server in sync, and it doesn't require the remote server to be setup beforehand. You can bring it online later in the project without any problems, and it doesn't clutter up your Zend interface with file status icons.
No comments:
Post a Comment