With the next major release of PHP just around the corner it’s time to consider setting your applications up in a testing environment to make sure that they are ready to be deployed to the latest and greatest.
Make sure your web applications are PHP 7 ready in a testing environment
Here are a few resources that should get you up and running with PHP 7 so you can test the performance of your web development projects and see if you can notice the alleged 75%+ performance increase.
Installing and Configuring PHP 7
There are currently three main ways to get a PHP 7 install up and running, depending on the technology you use to manage your development environments.
Rasmus Lerdorf has been maintaining a barebones, publicly available PHP 7 Vagrant box for quite a while. Once you get a little familiar with Vagrant, it should be fairly easy to set up for the beginner. The box is actively used by the PHP internals team for developing and testing PHP 7 so you should be able to get your application running inside of the box without many issues.
Using a docker image is a lightweight alternative to using the official vagrant box and should be easy to get up and running with some basic knowledge of docker containers. This may be a better solution for people who want to install PHP 7 on a remote server rather than locally, but also want their testing environment to be segregated from everything else that lives on the server.
Compiling from scratch is probably the hardest way to get a PHP 7 install up and running, it will however, give you the most control over your install. There is more an increased chance of breaking other things on your system if you compile and configure PHP 7 from scratch, but if you are running into problems with a particular extension this might be the best option for you, as you can simply remove it from the build.
Testing your application in PHP 7
Once you have your application setup on PHP 7 you can begin the process of testing.
If you do not have automated tests, then this is simply going to be a case of using your application and seeing what breaks. Coincidently, updating to PHP 7 is probably a good excuse for writing some automated tests that cover at least the basic and most important business logic of your application.
If you have automated tests, then the upgrade path to PHP 7 should be almost painless, simply running your test suite should bring to light the majority of incompatibilities between your codebase and PHP 7.
If you are using a static analysis service like Travis-CI or Scrutinizer-CI, then you should be able to configure the environment to run your tests and analysis on more than one version of PHP, depending on your service of choice. This is especially useful if you need to ensure backwards compatibility with PHP 5.x deployments.
Planning for the Future
If you have just started – or are about to start a new project with PHP – then it is certainly a good idea to keep PHP 7 in mind when designing your new application. New codebases shouldn’t have a problem when upgrading to PHP 7 as there are only a small number of backwards compatibility issues, which mostly only affect older code (for example, the removal of mysql_* functions).
With that in mind here are a few things to take into consideration when planning for your next project:
Projects that use a Framework
For those of us who prefer to use a pre-built framework like Symfony2, Laravel or Zend, then you are probably going to have an easy time when moving to PHP 7 as most, if not all of these frameworks have 100% of their tests passing with PHP 7.
If you are using an older framework such as Codeigniter or CakePHP – or an older version of Symfony or Zend – then you should proceed with caution. Aside from the fact these frameworks use outdated development practices, most of these frameworks have no planned compatibility patches for PHP 7 so may break when future, minor versions come down the pipeline. It’s advisable that you pick a newer framework for a new project, if possible.
Projects that do not use a Framework
If your next (or current) project is not using a pre-built framework, then to make the transition to PHP 7 easier, you may want to consider making use of some popular pre-built components. This rings especially true when dealing with common tasks such as routing, templating and database interactions.
If you are unsure what components to use then take a look at our article on picking the best components for your next PHP project.
Do you have any other suggestions, tips or tricks for migrating to the next version of PHP? Tweet us @madebymagnitude, we’d love to hear about them! Stay tuned for more articles on PHP 7 as we ourselves begin to explore the benefits of the fastest PHP version yet.