Configure, Package and Deploy PHP applications using Phing and SSH

Alternative method to Teamcity, we can use simple batch files to run the phing commands and other ssh commands.

We will configure and package php application and deploy to the cloud using ssh protocol. We will use Phing tool to build the package and then use sftp and ssh commands to deploy to the server.

First download or install Phing binaries from the web. If you have manually downloaded phing binaries, you have to install it correctly so that it is accessible from terminal.

Phing utilized build.xml and other configuration files to build your project. To learn how to crete build file go to the following link

Configure, Package and Deploy Php projects : TeamCIty Part 1

deploy.sh

phing -Dbuild.env=production
sftp -b sftpcommands.txt user:host.com
ssh user:host.com < sshcommands.ssh

sftpcommands.txt

cd  path/onthe/server
put php.zip

sshcommands.ssh

cd path/to/zipfile
unzip -o php.zip
echo "Finished unzipping file"

Running deploy.sh command on the terminal will run the phing to build the project and will upload to your cloud and then explode to the appropriate location.

Terminal

cd /path/tothe/build/folder
sh deploy.sh