Header

Deploying your PHP site with DeployHQ

Tips & Tricks

One of the most common technologies used on the web today, and for the past few decades, is PHP, or as it was originally known, Personal Home Page. Now, it's more commonly referred to as PHP: Hypertext Preprocessor.

PHP in essence, like any server-side language on the web, allows a website to become "dynamic" by allowing the website to change according to user interaction. That covers a wide variety of use cases; online shops, blogs, social media sites, and many more.

When it comes to the development and ultimately, the deployment of a PHP site, there are a number of ways of doing so. The more traditional way was to simply develop the website on a local computer, then upload all changes, wholesale, straight to the server using something like FTP, or a web hosting provider's built in file manager such that found in platforms like Plesk and cPanel.

Over time that process has certainly evolved, especially now it's such common practice to develop sites and apps with a version control system such as Git, which allows one or more developers to collaborate and iterate their site over time far more easily and safely.

When using version control, deployment can become trickier as you'll always want to follow what you've committed onto the server itself, i.e. if you've changed two files in the commit, only those two files, and the correct versions of them, should be uploaded.

Deployment strategies

With this in mind then, a more precise deployment strategy will be required for ensuring your PHP site is kept up to date. There are a number of options available that can be run straight from your command line, such as Capistrano, but as this requires base knowledge and some degree of setup, a more simplified deployment platform might be preferable.

Using DeployHQ, a dedicated web-based deployment platform, you can connect to a Git repository and as many servers as you wish to deploy your PHP site. Out the box, DeployHQ's strategy will always follow changes from your commits, and only upload the necessary changes each time.

This helps to keep deployment time short, and makes the process for more manageable. Deployments can also be triggered automatically from the major repository hosts, using a simple webhook request each time a commit is pushed.

For a simple, direct local → Git → server file transfer strategy, that's pretty much all you need to do.

However, DeployHQ has a number of additional features that more advanced PHP sites and strategies can take advantage of.

Using third party dependencies

One very commonly used PHP framework is Composer, which allows developers to use third party dependencies, or libraries of code maintained by other development teams, across one, some or even all of their sites.

When developing with a tool like Composer, very often the simple process of:

composer install

Will be run during development to fetch those third party libraries so that they can be used in the site. As the libraries will add a lot of additional files onto the codebase, it's often better to not commit the files to Git, but only install them when needed.

With DeployHQ's Build Pipeline, you can achieve this aim by simply running composer install as a Build Command, during the course of a deployment. This runs on our own servers, and as with Git, only files changed since the last build (i.e. the last time you ran composer install in the previous deployment) will be uploaded.

Further commands and tasks can be run too if you wish, such as compiling CSS and JavaScript, running application tests and more, straight from the build pipeline.

Running commands on the web server

More advanced sites might also have processes that run on the web server itself, such as job processing workers, or a backend database. As such, tasks akin to the build pipeline may be required, such a database migrations (commands to change the structure of a database), or commands to start, stop or restart a running process.

This is easily achieved by the use of DeployHQ's SSH commands feature. Commands can be set to run before, or after the files are transferred, depending on the nature of the command that's required.

You might for example have a simple command to stop a web process before the files are transferred, and a second command to start it up again once they are finished.

Further reading

These are just some of the aspects of DeployHQ that can help with optimising your PHP deployment workflow, and we'd recommend looking at the following documentation that outlines further useful features:

  • Stop unwanted files from your repository being uploaded to your server with Excluded Files
  • Keep sensitive files and secrets away from your repository using Config Files
  • Setup connections with popular services for deployment notifications and other useful tasks with our Integrations

Otherwise, if you have any questions about the deployment of your PHP sites, do get in touch.

A little bit about the author

I'm Adam W, or as everyone prefers to call me - Batman. I get a lot of satisfaction out of helping our customers and am committed to making their customer experience as positive as possible. When not offering support to our customers, you'll find me gaming, listening to music or running.

Proudly powered by Katapult. Running on 100% renewable energy.