Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

SitePoint PHP Blog:
How to Properly Deploy Web Apps via SFTP with Git
Nov 29, 2016 @ 11:53:49

On the SitePoint PHP blog there's a new tutorial posted showing you how to properly deploy applications with SFTP and Git. In their examples they build a PHP-based deployment process that uses a few handy packages to make the flow simpler than a set of manual commands.

Uploading files is an integral aspect of any deployment process, and the underlying implementation can vary depending on the type of your server.

[...] The PHPSECLIB (PHP Secure Communications Library) package has an awesome API for routine SFTP tasks: it uses some optional PHP extensions if they’re available, and falls back on an internal PHP implementation otherwise. You don’t need any additional PHP extension to use this package, the default extensions that are packaged with PHP will do. In this article, we will first cover various features of PHPSECLIB – SFTP, including but not limited to uploading or deleting files. Then, we will take a look at how we can use Git in combination with this library to automate our SFTP deployment process.

They start with a quick command (Composer) to get the phpseclib library installed but then quickly move into using it and some SSH keys to:

  • authenticate to the server with public/private keys
  • uploading a sample file
  • automating the deployment with Git, pushing only changed files from a local git repo
  • getting the contents of a specific commit
  • the actual push of the files via SFTP

There's also a few other helpful hints included showing how to manage permissions on the remote server, execute remote commands and downloading files. The post ends with links to other similar tools if you're interested in more complete approaches.

tagged: deploy application sftp git deployment tutorial phpseclib example

Link: https://www.sitepoint.com/how-to-properly-deploy-web-apps-via-sftp-with-git/

Cees-Jan Kiewiet:
Run GrumPHP git hooks within Vagrant
Jun 07, 2016 @ 12:22:11

Cees-Jan Kiewiet has a post on his site showing you how to run GrumPHP hooks in Vagrant, a tool that allows for code quality evaluation.

A couple of weeks back while attending AmsterdamPHP Mike Chernev gave a talk about GrumPHP. Very cool looking tool, but during implementation I found out it the default setup assumes running grumphp on the same machine (whether that is a VM or iron) as committing. That is a problem in my set up where all PHP related code runs in vagrant and comitting on the host using PHPStorm. Lets fix that.

The post includes the scripts you'll need to include in your Vagrant setup to execute the quality checks on commit, pre-commit and the Vagrant hook setup to run everything inside of the VM instead of locally.

tagged: grumphp hooks git vagrant commit

Link: https://blog.wyrihaximus.net/2016/06/run-grumphp-git-hooks-within-vagrant/

SitePoint PHP Blog:
Writing PHP Git Hooks with Static Review
Sep 01, 2015 @ 11:16:01

On the SitePoint PHP blog Matthew Setter introduces the use of git hooks to help with automatic static analysis of your application's code, integrating it directly into your current workflow. He shows how to use this library to make creating and installing them as easy as a single command (and they're written in PHP).

If you’ve been using Git for more than a short length of time, you’ll hopefully have heard of Git hooks. [...] There are hooks for pre- and post-commit, pre- and post-update, pre-push, pre-rebase, and so on. The sample hooks are written in Bash, one of the Linux shell languages. But they can be written in almost any language you’re comfortable or proficient with. [...] Thanks to Static Review, by Samuel Parkinson, you can now write Git hooks with native PHP, optionally building on the existing core classes. In today’s post, I’m going to give you a tour of what’s on offer, finishing up by writing a custom class to check for any lingering calls to var_dump().

He walks you through the installation of the library and helps you create a simple working example that ensures you've correctly set up your (Composer) dependencies. He explains a bit about what's involved in the StaticReview package and the three "introspection" objects initialized for each run. He ends the post by walking you through the creation of a custom, more real-world check that evaluates your code (via a simple grep) to ensure no var_dump statements were left in.

tagged: static review git hook analysis tutorial

Link: http://www.sitepoint.com/writing-php-git-hooks-with-static-review/

Three Devs & A Maybe Podcast:
The Big Five-Zero
Nov 21, 2014 @ 09:23:30

The Three Devs and a Maybe podcast has released their latest episode, #50! In the Big Five-Zero hosts Michael Budd, Fraser Hart, Lewis Cains and Edd Mann talk about a wide range of topics including web unicorns, application composition and the state of CodeIgniter 3.

This week we celebrate the 50th episode of the podcast in style, by... not even remembering it is the 50th episode till half way through (whoops). We start off discussion with our differing views on working from home, web unicorns and running shoes. Leading on from this, we bring up a couple of news topics that have been making the rounds in the PHP world recently - along with a proposed Unix command-line series that Mick is keen to do. We then move on to some of the great feedback we have received from you guys this past week, and somehow this leads to Edd rambling on about the Unix philosophy/application composition again. Finally, we discuss the state of CodeIgniter 3, how Git works under-the-hood and Objective-C/Swift's memory management model.

Other topics mentioned in this episode include:

You can listen to this latest episode either via the in-page player or by downloading the full mp3. If you enjoy the show, consider subscribing to their feed too.

tagged: threedevsandamaybe podcast ep50 news unix codeigniter3 git objectivec swift

Link: http://threedevsandamaybe.com/the-big-five-zero/

Three Devs & A Maybe Podcast:
I Want You Back
Nov 10, 2014 @ 09:19:34

The Three Devs and a Maybe podcast is back with their latest episode hosted by Michael Budd, Fraser Hart, Lewis Cains and Edd Mann. In episode #48, "I Want You Back", they talk about a wide range of topics including currency, git and passwords.

Two weeks in the making, we are finally back with another podcast installment. This week we touch upon the Unix philosophy, client drama, and shiny new MacBook Pros. We then move on to discuss the security concerns that have arisen from the introduction of contactless payment systems. Leading on from this we talk about the YubiKey and how it can be used to provide two-factor authentication, for services such as LastPass. Finally, we close with how 'tombstoning' your code trumps the dreaded commenting out every time.

You can listen to this latest episode either through the in-page player or by downloading the mp3 directly. If you enjoy the show, be sure to subscribe to their feed to get the latest episodes as their released!

tagged: threedevsandamaybe podcast ep48 security yubikey git currency

Link: http://threedevsandamaybe.com/i-want-you-back/

SitePoint PHP Blog:
Deploy Your Website Using Laravel and Git
Sep 08, 2014 @ 09:28:50

The SitePoint PHP blog has a new tutorial by James Dow showing you how to use git and Laravel for application deployment. This isn't just about deploying a Laravel application, though. It includes a method for automating processes once the deployment is complete.

You can’t be a successful web developer without using some sort of deployment workflow for your websites. It doesn’t matter how good or bad your workflow might be. If you can’t get your website up to production then your client will never pay you for your hard work. [...] I wanted something that was as easy as pushing a repository with Git. More important, I wanted to be in full control when pushing content live. I was able to find a similar workflow that used Git to handle the file transferring. On top of that I found out I could also use the PHP framework Laravel to automate the more repetitive tasks.

He starts with the server side of things, showing you how to get the git repository created and structured. He then configures Laravel with a "remote" connection for the production server so it can reach out and execute the tasks. Finally he shows how to make the route (/deploy) that's executed when the route is called. In his example route he sets up a SSH request to the production server that changes to the web server root and makes a "git pull" request to get the latest code. It's an interesting use for something like Laravel, but I wonder if it's a good fit for the deployment need. This kind of thing could pretty easily be replaced with a small shell script.

tagged: deployment laravel tutorial git ssh

Link: http://www.sitepoint.com/deploy-website-using-laravel-git/

SitePoint Web Blog:
Understanding Version Control with Diffs
May 23, 2014 @ 10:53:30

If you're relatively new to using version control, there may be one technique you've yet to get a grip on. In this new post on SitePoint.com's Web blog they introduce you to using the "diff" functionality to discover differences between versions of code.

Every project is made up of countless little changes. With a little luck, they will finally form a website, an app, or some other product. Your version control system keeps track of these changes. But only once you understand how to read them will you be able to track your project’s progress. Using the example of Git, the popular version control system, this article will help you understand these changes.

They include several screenshots and line-by-line descriptions of what each part of the output of the "git diff" command is. There's also a brief description of what each of the sections contains and how to inspect both committed and non-committed changes. There's even a link to a list of other applications that may help provide a clearer picture of the changes rather than just the command line output.

tagged: versioncontrol diff git introduction commit branch

Link: http://www.sitepoint.com/understanding-version-control-diffs

Zumba Engineering Blog:
Enforce code standards with composer, git hooks, and phpcs
Apr 15, 2014 @ 09:13:48

The Zumba Engineering blog has a new post looking at a way you can control code quality and standards with the help of Composer, git hooks and the PHP Code Sniffer (phpcs) tools.

Maintaining code quality on projects where there are many developers contributing is a tough assignment. How many times have you tried to contribute to an open-source project only to find the maintainer rejecting your pull request on the grounds of some invisible coding standard? [...] Luckily there are tools that can assist maintainers. In this post, I’ll be going over how to use composer, git hooks, and phpcs to enforce code quality rules.

These three technologies are combined together to make a more seamless experience for the developer while keeping the code quality high. Their method makes use of the "scripts" (post-install-cmd) feature of Composer to, after the installation of all packages, set up a git hook script that will run the phpcs checks on pre-commit. It's a pretty simple shell script that kicks back any errors it might find before the user can commit their changes.

tagged: code standards composer git hook phpcs codesniffer install precommit

Link: http://engineering.zumba.com/2014/04/14/control-code-quality

Lorna Mitchell:
Using Composer Without GitIgnoring Vendor/
Mar 12, 2014 @ 12:45:23

In her latest post Lorna Mitchell looks at a method, when using Composer and git, to fix an issue around subdirectories that are git repositories and git thinking they should be submodules instead.

Recent additions to the joind.in API have introduced some new dependencies so we decided we'd start using Composer to manage these - but we don't want to run composer unsupervised. I'm sure this will bring the rain of "just run composer install, it's probably mostly almost safe" criticism, but actually it's quite tricky to run Composer without excluding vendor/ from source control so I thought I'd share how we did it so that anyone who wants to do so can learn from my experience!

She starts by describing the usual use of Composer - making the "composer.json", running the install and see the "vendor" directory being added. When she tried to check in the dependencies, git gave her an error about wanting them to be submodules. Instead, she figured out a way to add a line to the .gitignore to have it disregard the "vendor/.git" directory, making it work as expected.

tagged: composer vendor install gitignore git

Link: http://www.lornajane.net/posts/2014/using-composer-without-gitignoring

Kevin van Zonneveld:
It's Almost 2014 and We Are Still Committing Broken Code
Dec 30, 2013 @ 09:19:28

Kevin van Zonneveld has a new post that, while not PHP specific, does have a handy script that will help you stop committing broken code.

Whatever the reason, it's almost 2014 and we are still committing broken code. This needs to stop because best case: Travis or Jenkins prevent those errors from hitting production and it's frustrating to go back and revert/redo that stuff. A waste of your time and state of mind, you were already working on other things. Worst case: your error goes unnoticed and hits production.

To help resolve the problem, he suggests using the "hook" system common to most version control software. In his specific example, he shows the use of a pre-commit hook that fires off a bash script on the files being committed. He includes the full code for this bash script that includes a check for PHP scripts using the built in PHP linter (the "-l" option on the command line). He also includes the commands and updates you'll need to make to get it installed on git.

tagged: git precommit hook syntax error bash script tutorial

Link: http://kvz.io/blog/2013/12/29/one-git-commit-hook-to-rule-them-all/