Deployment of web applications is a process where application is uploaded from your development machine or the source code repository (Git) to a web server and is made accessible to users.
Deploying PHP application to production or staging environment might not be so obvious task at first and requires some additional attention.
During deployment, the source code files are transferred with some of the following additional steps:
Modern deployments should be as simple, fast and be able to made often during the application life time to meet the requirements. For example, if you change only small portion of your code, only the changed files should be uploaded and not all others. One of the modern deployment approaches is also atomic deployment. It provides switching ability between different deployed versions and web server uses symbolic link to the latest version location.
When uploading application from the development to production you also want to ensure that tests pass and that application works as expected. This step adds deploying application to another step, for example, a stage.
Application life cycle generally consists of the following steps:
This is where you locally write code, integrate functionality, fix bugs, run tests, commit and push code to a versioning system such as Git.
Pick the tools that you and your team find comfortable to work with and inspect the available infrastructure options. You will not be able to use a single approach for all of your projects. Many projects have their own edge cases and limits which you must take into account when picking the build and deployment strategy.
FTP is the most basic file transfer approach you might have started with. It is the easiest way of transferring application files to a web server by using FTP protocol with some FTP client such as FileZilla or similar. FTP is simple and convenient, but has many weaknesses such as security risks, lack of versioning options and also it can be slow with a lot of files. Most shared hosting options provide FTP to upload files to production.
The git-ftp provides Git version control system with FTP deployment.
Below are listed some more advanced and convenient deployment methods. You will need some prerequisite knowledge to link the basic deployment such as FTP and further explained methods:
System administration is often a very large chapter of its own and will not be covered here in details.
When working with Git, you can use it to deploy your application as well.
In short the deployment procedure is the following:
git pulland checkout possible specific application version
If using GitHub, Bitbucket, GitLab or similar Git hosting service, you can add the deployment SSH key in the repository.
Deployer is a PHP cli application which can deploy your
PHP application over multiple protocols, SSH being widely used. After installation,
a separate project specific
deploy.php file is used to deploy the application
from the Git repository to server via command line.
Docker deployment strategy can be used in two ways:
By building custom images with application code in the images and deploying them to Docker Registry.
This is probably the most convenient way to use Docker in production. However Docker Registry with custom images needs to be used.
By using Git on the production server and using volumes for code. Images can be build on the server itself or downloaded from Docker Registry.
Some useful resources to run Docker in production:
Jenkins provides continuous integration and can be used to deploy application into production. The Jenkins ecosystem provides a multitude of plugins to adjust your application life cycle to your needs. It can be even used together with Docker to build images and run tasks in containers.
Some limited free and paid options you might want to check out if you want to have more elegant and less “hacky” solutions:
To explore more about deployments, check also some of the following resources: