At Launchdeck, we help developers automate their builds and deployments. Deployment is the process of uploading the application from your local machine or a source code repository (Git) to a server and making it available to users. In this article, we will show you how to easily deploy a PHP application to your server.
What goes into deploying a PHP application?
Every application is different, as is the process. During PHP deployment, the files are uploaded to your server with the following most common steps:
- Clone the repository or checking out specific version of the application from the code repository
- Download dependencies (Composer)
- Deploy code to server (FTP, SFTP, SSH)
- Optional: Run shell commands on your server, like restarting services or running database migrations (SSH server only)
Launchdeck offers two distinct deployment strategies:
- FTP and SFTP deployments:
Upon first publish, all files will be uploaded one by one. For every subsequent publish, only files changed since the last version will be updated in-place on your server.
- Atomic deployments:
Fast, zero-downtime deployments requiring SSH access. Uploads the entire release as a single package and extracts it on the server. Once you hit publish, a symlink will be made to point to the new release. Find out more on how zero downtime atomic deployments work.
As we proceed, we'll assume you're familiar with Git and have all your application sources in a repository, except for compiled files and third party dependencies installed using a package manager.
The best way to deploy a PHP website or application
There are several ways to deploy a PHP website to your server. We’ve covered various ways in another article: "Different ways to deploy a website using Git". The most convenient and simple way is as follows:
Connect your Git repository to Launchdeck
The first step in deploying your PHP project is to connect the Git repository. You can easily connect a Github or Bitbucket account and choose from the list of repositories available within the account. Or if you're using a different Git provider, like Gitlab or a self-hosted server, you can choose the Private/Hosted Git server option.
All files within this repository are uploaded to your server. Launchdeck will also attempt to add a webhook to your repository so that when you push new commits, they'll show up in Launchdeck automatically. Depending on the deployment strategy you’re using, Launchdeck will upload either the files changed since the last version, or a fresh new release containing the new version in full (for atomic deployments).
Download dependencies and compile assets
Launchdeck allows you to define "build steps" using a simple YAML format. Hit the button “Auto suggest build automation” and we will automatically suggest a build config based on the contents of your repository. For a PHP application, such a configuration might look something like:
build: - composer install - npm install - gulp
More info: How to automate your build process
Deploy files to the server
All files from your repository and the files generated during the build phase can now be uploaded to the server via:
Optional: Run SSH commands on your server
In addition to the build commands, you may want to execute some commands on your server after every deployment. SSH commands are useful in a variety of situations, including:
- Automatically running migration scripts after deploying a new version
- Clearing application cache(s) when a new version goes live
- Restarting a server process or service after uploading the latest sources
More info: Docs about SSH commands