Blog » Deploying PHP projects revisited

Deploying PHP projects revisited

In the Deploying PHP projects post, I showed a simple way of deploying a PHP project to a server. There is one particular limitation with the way that works, however, and that is you must have permissions on the server to perform the git clone process. This isn't ideal, as the server shouldn't be given such permissions to be cloning your site code. Ideally, the site code would be packaged locally then uploaded to the server.

Fortunately the local recipe with Deployer lets us accomplish this.

Assuming you've already got things running from the last post, we can add another Composer package that adds some additional deployment recipes, including the "local" one we are interested in:

composer require --dev "deployphp/recipes:~3.0"

And now we adjust the deploy.php script to be the following:

require 'vendor/deployer/deployer/recipe/common.php';
require 'vendor/deployphp/recipes/recipes/local.php';

server('main', '', 22)
  ->env('deploy_path', '/path/to/site')

set('repository', '');
set('keep_releases', 2);
set('shared_dirs', ['assets']);

env('local_deploy_path', '/tmp/mysite_release');

task('deploy:upload_release', function() {
  upload(env('local_release_path'), env('release_path'));
})->desc('Upload local to remote');

task('silverstripe:migrate', function() {
  run('php {{release_path}}/framework/cli-script.php dev/build flush=1');
})->desc('Run SilverStripe migration');

task('deploy', [
])->desc('Deploy project');

after('deploy', 'success');

This is mostly the same as the last script, but contains additions to "deploy locally" then upload to the target server. The specific tasks that represent each step of the deployment are listed explicitly in the order we need them. Documentation on using the local recipe is available.