How to Deploy Code Using CommandLine With Git and PHPloy

How to Deploy Code Using Command-Line With Git and PHPloy

Reading Time: 4 minutes

Deploying your code onto your production, dev, or staging server is a recurring task that you should automate as much as possible.

In this article, I will demonstrate how you can deploy your code from the command-line, no matter if you’re on Mac, Linux, or Windows. It serves as the starting point to automate deployments and connect them to Git commits for example. Using Git is a prerequisite for this article.

For way too long, I have used manual file transfers via SFTP to upload the code I wrote locally to my development server at Cloudways. My workflow looked like this: I wrote a piece of code that added a certain function, opened FileZilla, logged into the development server, navigated to the correct folder, and uploaded the local code manually.

Why Should You Use Command-Line?

Just by writing this down, I see how inefficient and error-prone this approach was. It wasn’t automated. It wasn’t fast. It wasn’t safe. Especially if you’re working with a team on your code, this manual file transfer approach neither helps you speed up your development nor increases the stability of your software.

You’ll encounter situations where one developer accidentally uploads files that overwrite changes you have made, even if you’re working on the same Git or Mercurial repository. You’ll also find that developers might forget uploading their code for a day or two, causing delays in the entire project.

There’s nothing inherently bad about these challenges. We’re humans, and humans do make mistakes. It is neither a mindful act of sabotaging you nor your developer trying to overrule other devs in your team.

Errors like the ones outlined above are bound to happen if you rely on manual file transfers to deploy your code. That’s why you should strive to automate deployments as much as possible.

Automate Deployment Using Command-Line

To start implementing automated deployments from your command-line, you need to open a terminal on your local computer. The default terminals of Mac and Linux will do. For Windows users (like myself), I recommend using the Bash that comes with the Windows Subsystem for Linux (WSL).

Install PHPloy in Your Project Folder

You’re going to install a tool called PHPloy into your project folder (or you can install it globally on your computer). I’m using Composer in this example, so if you don’t have Composer installed yet, please follow the official documentation. Only continue reading if you have Composer up and running.

In this example, I’m installing PHPloy into a plugin folder for a WP plugin I’m currently working on. In the terminal I’m navigating to that folder and then running the following command:




This article was written by Jan Koch and originally published on The Official Cloudways Blog.

Disclosure: Some of the links in this post are "affiliate links." This means if you click on the link and purchase the product, We may receive an affiliate commission.

Leave a Comment

Your email address will not be published. Required fields are marked *

Show Your ❤️ Love! Like Us
Scroll to Top