What Does It Take To Start Using Zend Expressive?

What Does It Take To Start using Zend Expressive?

Ever thought that it's hard to get started with Zend Expressive? Ever think you need to know Vagrant, Ansible, Docker, Puppet, Linux, and more? Nope, you don't! In this post, I'm going to show you that, while these tools can help, if you're just getting started with the framework (such as learning about it), you don't need them.

I want to be clear, before we go any further, that I'm not talking about doing fully-fledged development. Regardless of the language or language framework that you use, if you're building an application that renders anything more than something quite elementary, it's going to require more than a little bit of effort.

So what I'm talking about here is when you're just starting out and getting a feel for Zend Expressive, right up to building a test application. I'm not talking about a fully-fledged, deployed application that requires copious tests, one backed by a CI/CD pipeline.

With that said, let's continue!

Much has been said about Zend Framework over the years. It's been derided as over-engineered, overly complicated, and bloated. If there was one term that I'd heard associated with it more than any other, it would be "enterprise-y".

While I think that may well have been a deliberate choice on Zend's part (perhaps because it aligned with their corporate goals) the framework wasn't as hard as many people made out. Nor was it as bad as some have bemoaned. To be honest, I think some people revelled in denigrating it — actually I know one or two personally.

Sure, it wasn't the easiest of frameworks to get started with — especially version 1. , are historical reasons for that, such as it being built before PHP's Composer-inspired renaissance. If you were around back then, you might remember that Symfony 1 was built similarly. It was a fact of life living in a world where Composer was yet to exist.

That said, with each subsequent release, Zend Framework's become easier to start with — even if you've never used the framework before.

Now Zend Expressive, the third iteration of the framework, takes that ease of use to a whole new level. So today, I'm going to show you just how easy it is to get started; but first, let's ask two questions.

Won't I Need Docker?

Docker Logo

While Docker's a fantastic tool, whether you want to rapidly build a development environment, or to go from idea through to deployment, if you're just getting started with Zend Expressive, you don't need Docker!

Yes, it will make your life easier, and it's a tooling solution that I strongly recommend, especially over custom virtual machines.

If you're just getting started with Zend Expressive, just experimenting with it or testing it out, Docker's likely going to be overkill. It will come in handy later though.

Won't I Need Vagrant, VirtualBox, VMWare, Ansible, Puppet, and Friends?

Vagrant Logo

All of these tools are fantastic! They're tools which have been developed over many years and make it far simpler than ever to provision a virtual environment; one that's:

  • Idempotent.
  • Configured just to your needs.
  • Can mirror in production, staging, and testing, your development environment.

Also, let's not forget just how much time they can save new developers when they're getting started. Whether they're new to a company, a team, or to a codebase, these tools can provide you with a ready-to-use development environment. By doing so, the developer need only focus on learning the code, not on creating an environment fit for purpose.

However, if you're just getting started and learning Zend Expressive's foundations, you don't need them either. They'll come into their own later though, once you've gotten settled and have a specific application in mind that you want to build.

However, at the beginning they're just overkill.

So What Do I Need Then?

You might think that I've indulged in a classic bait-and-switch, when I give you the answer. However, I promise you that I've not. The answer is genuine.

All you need is to have PHP installed, at least version 5.6 — but I strongly recommend version 7. After that, you just need to run two commands, and you're up and running, ready to experiment and learn.

What are those commands? The first one is Composer's create-project command: Here's an example, where we'll create a new project based on the Zend Expressive Skeleton.

composer create-project -s rc zendframework/zend-expressive-skeleton <your project name>

This command launches the Zend Expressive Skeleton Installer and guides you through a series of questions to create a template directory structure, one ready to boot.

After that, you just need the second command one of the many Composer scripts that come with the composer.json file, in the project which the previous command generated. It launches PHP's built-in web server. If you've not used it before, the built-in web server is:

designed to aid application development. It may also be useful for testing purposes or for application demonstrations that in controlled environments. It is not intended to be a full-featured web server. It should not be used on a public network.

The following command will start it and boot your new Zend Expressive project, listening on port 8080 on localhost with ./public as the web server's directory root.

composer serve

After you've done that, you'll see the default page, which you can see an example of below, and you're ready to begin delving through the sample project's code, structure, and configuration.

But there are other commands!

That's right, in addition to the two commands that we've just stepped through, there are several others. They're worth going through, as they will help make your life developing Zend Expressive applications that much easier.

development-{disable,enable,status}

These commands, as their names imply, enable and disable development mode, and show its status. If you're not familiar with Zend Expressive's development mode, it's provided by the integrated zfcampus/zf-development-mode package.

To quote the package's README:

This package provides a script to allow you to enable and disable development mode for zend-mvc (both versions 2 and 3) and Expressive applications. The script allows you to specify configuration and modules that should only be enabled when in development, and not when in production.

A example feature that's not enabled during development mode is the configuration cache. Logically, during development, you're likely to be continuously making changes, and need to see the effects of those changes as soon as they occur. If the changes were cached, it would likely cause a lot of confusion. As a result, it's not enable during development.

clear-config-cache

Linked in with the last command is clear-config-cache. As the name implies, it clears any existing configuration cache, which by default is stored in data/config-cache.php.

cs-check and cs-fix

These two commands run PHP CodeSniffer and the PHP Code Beautifier and Fixer. If you're not familiar with them PHP_CodeSniffer:

Tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.

PHP Code Beautifier and Fixer:

PHP_CodeSniffer is able to fix many errors and warnings automatically. The diff report can be used to generate a diff that can be applied using the patch command. Alternatively, the PHP Code Beautifier and Fixer (phpcbf) can be used in place of phpcs to automatically generate and apply the diff for you.

 test, test-coverage, and upload-coverage

These three commands run the application's tests without and with code coverage enabled, and upload the coverage report information.

They're a handy set of commands, I strongly encourage you to try them out, if you've not already done so.

Zend Expressive Default Home Page

That's It!

And that's all you need to get up and running with Zend Expressive. Sure, the project that the create-project command generates is quite minimal, and doesn't make use of the multitude of available PHP extensions; such as Memcache, Redis, ElasticSearch, and so on.

However, if you just want to get up and running, if you want to see how an expressive project is composed, you need very little. I hope that this post goes some way to giving you a fresh perspective on Zend Expressive and the greater Zend Framework set of packages.

If you's like help getting started, with Zend Expressive, check out the official docs, this talk from Chris Tankersley, and the essentials book. There are loads more resources, but I recommend these three as excellent places to start.



About Matthew

Matthew Setter Matthew Setter is a PHP & Zend Framework specialist. If you're in need of a custom software application, need to migrate an existing legacy application, or want to know your current application's GPA - get in touch.

Want To Be A Zend Framework Guru?

Drop your email in the box below, and get awesome tutorialsjust like this one — straight to your inbox, PLUS exclusive content only available by email.