Use PHP and GIT to Deploy a Website over FTP

I recently found this little gem of a tool built in my favorite language (PHP of course) that allows you to deploy files through FTP to a server. It makes use of GIT to know which files it should upload and which ones it should delete. It is a real time-saver compared to old-school alternative of uploading every file over FTP!

Some key features include

  • Only upload the changed files when deploying
  • Deletes deleted files from server as well
  • Works with Git Sub-modules
  • Fast
  • Easy to use Command line and easy configuration
  • Can upload to multiple servers or just 1

Download or view the project on Github:
https://github.com/banago/PHPloy

Notice: The usage examples below are pulled straight from the projects read-me file.

PHPloy Usage

As any script, you can use PHPloy globally, from your bin directory or locally, from your project directory:

Using PHPloy Globally

  1. Drop phploy into /usr/local/bin and make it executable by running sudo chmod +x phploy.
  2. Create the deploy.ini file.
  3. Run phploy in terminal.

Using PHPloy Locally

  1. Drop phploy into your project.
  2. Create the deploy.ini file.
  3. Run php phploy in terminal.

deploy.ini

The deploy.ini file hold your credentials and it must be in the root directory of your project. Use as many servers as you need and whichever configuration type you prefer.

The first time its executed, PHPloy will assume that your deployment server is empty, and will upload all the files of your project.

Multiple Servers

PHPloy allows you to configure multilple servers in the deploy file and deploy to any of them with ease. By default it will deploy to all specified servers. To specify one server run:

Or:

servername stands for the name you have given to the server in the deploy.ini configuration file.

Rollbacks

PHPloy allows you to roll back to an earlier version when you need to. Rolling back is very easy.

To roll back to the previous commit, you just run:

To roll back to whatever commit you want to, you run:

Note that there is not a short version of --rollback and also that when you run a rollback your files will revert temporarely to the version of the rollback you are running. When the deploymnet is finished, everything will go back as it was.

View files

PHPloy allows you to check out what are going to be uploaded/deleted before you actually push them. Just run:

Or:

How It Works

PHPloy stores a file called .revision on your server. This file contains the hash of the commit that you have deployed to that server. When you run phploy, it downloads that file and compares the commit reference in it with the commit you are trying to deploy to find out which files to upload.

PHPloy also stores a .revision file for each submodule in your repository.

Credits

PHPloy is developed by Baki Goxhaj, a freelance WordPress and Laravel developer from Albania. It is based on the work of Bruno De Barros. This project was taken further because the original project did not suport Git Submodues.

Download PHPloy

Get the project for yourself on GitHub here https://github.com/banago/PHPloy