Are there ssh and scp tasks available for phing?
-
04-07-2019 - |
Question
I would like to do remote deployment from my build machine onto a server. The remoting can be done via ssh commands from a script, but I would rather use phing and a deploy.xml file that would do the automation.
What alternatives do I have to do ssh (and also scp) tasks from within a phing build file?
Solution
If you really need phing, then afaik there's only exec. If you are open for other tools, have a look at capistrano and my answer in "Setting up a PHP web project, the infrastructure.".
OTHER TIPS
SCPTask in Phing:
copies files to and from a remote host using scp. This task requires the PHP SSH2 extension to function...
I came across a SCP and SSH tasks for Phing yesterday. You will also need to follow the instructions for installing SSH2 for PHP. I wasn't able to get the tasks to work straight out of the box, you might. I modified my copy, if you need I can provide.
I ran into the same problem about a year ago and back then i could not find a task. I ended up doing a exec task, this way it was all in the xml file.
<exec command="scp -i keys/id_rsa myfile user@$server:myfile" dir="." />
I know this is old but there seems to be multiple broken links and some misinformation.
ScpTask: http://www.phing.info/docs/guide/stable/apcs60.html
For SemanticScuttle, we use rsync to deploy release files to the SourceForge server - also via exec. Rsync understands ssh.
For ssh, there's the ssh2 PECL extension and then Phing has the ssh and scp tasks.
- On a Mac, install libssh2 via Homebrew. On Linux, use your package manager.
sudo pecl install pecl.php.net/ssh2-0.12
You can now do this:
<?xml version="1.0"?>
<project name="test" default="test">
<target name="test">
<ssh username="vagrant" password="vagrant" host="192.168.123.456"
command="pwd" property="pwd" display="false" />
<echo>The current working directory is ${pwd}</echo>
</target>
</project>