While working with a client recently, I found that deploying to WP Engine with Git had stopped working.
The Symptom
The following appeared on the command line when I ran git push production
remote: - warning: syntax Error Found in wp-content/vendor/composer/autoload_static.php ...
remote: - failed: we detected a PHP syntax failure.
The Problem
The file autoload_static.php
is only executed if the website is running PHP 5.6
or above because it uses things that break in older versions of PHP. WP Engine checks all the PHP files when they are deployed using git push for code that could break the site in version PHP 5.3
. Since we are uploading code that would break the site (if it ever ran, which it won’t but WP Engine can’t tell that), WP Engine stops the upload.
The specific code in question is generated by Composer version 1.1.0
or above where optimizations were made for PHP 5.6
and above in autoload_static.php
. These optimizations include using concatenation when declaring default class properties in PHP, which was not available until 5.6
. See http://stackoverflow.com/questions/5847905/cannot-use-concatenation-when-declaring-default-class-properties-in-php
The Solution
As Taylor McCaslin from WP Engine commented below, in December 2016 WP Engine added support for the Git flag
–push-option=nolint
(alternative syntax -o nolint
).
So instead of
git push production master
you would run
git push -o nolint production master
Minimum Required Git Client Version
The support for -push-option was added to the Git client in version 2.10.0. If you are running an earlier version of Git, this fix will not work (see alternative solution).
You can determine what version of the Git client you are using by running
git --version
from the command line.
Alternative Solution
If using -push-option=nolint flag is not an option (e.g. you’re stuck using an earlier version of Git), you can also solve this issue by not deploying the offending file with Git push. This is done by deleting the file
$ git remove wp-content/vendor/composer/autoload_static.php
and adding it to your .gitignore
file.
wp-content/vendor/composer/autoload_static.php
Why am I Deploying the Vendor Directory with Git?
Generally, the Composer vendor
directory should not be included in the Git repo but since I can not run Composer on the WP Engine server, it is included on this project. Another option would be manually SFTPing the vendor
directory while excluding it entirely from the Git repo, which may be a better solution in this case but does create an odd requirement for deployment.
Hi Sal,
I’m a Product Manager at WP Engine focused on Developer Tools. First off, thanks for taking the time to write a workaround post! We always love seeing customers finding workarounds, and are always on the lookout for these types of posts in hopes we can make offical solutions to troubled workflow issues.
I wanted to let you know about a new feature we rolled out in late December which should help you here:
Our git server now allows you to bypass the php lint if needed to make php code deployments less strict with the –push-option=nolint flag. Simply format this option in your git push command:
$ git push –push-option=nolint
Or
$ git push -o nolint production master
If you receive and error when including the –push-option or -o flag, you may need to update your git version locally. You can download that directly from git here: https://git-scm.com/downloads
Hope this helps!
Thanks Taylor, I’ve updated this article to include the information you provided. Thanks for sharing.