Image Blog PHP Clusters AWS EFS
June 30, 2016

PHP Clusters Simplified With AWS EFS

Zend Server

One of the main challenges I used to have with hosting my site and applications on AWS, is file synchronization between the different instances when running my application. If it’s for PHP clusters that need media files available to all nodes or a simple admin UI, that also doesn't run on front-end servers and must sync uploaded media, it was always a real challenge to get the level of service, availability, and redundancy I'm used to from other AWS services when dealing with file sharing.

AWS has been working for a long time to solve this problem and they've been rolling out a new service to production called EFS - Elastic File System. EFS is a new file storage service, available on AWS for EC2 instances. EFS is available using NFSv4 protocol and grows/shrinks as you add/remove files to it. Use of EFS allows transparent usage of NFS as a regular file system mounted on the server.

What Is AWS EFS Used For?

AWS EFS is used to share files between instances and nodes of clusters. It scales very well and provides a lot of value for PHP web applications.

PHP Clusters Challenge

Managing PHP clusters can be a difficult task, especially when you store data in files that must be shared between cluster nodes. In this scenario, you used to have many solutions such as syncing files periodically between servers or setting up and managing some sort of file server (which has to be clusterized itself in case you need a HA solution).

Let’s take, for example, a very popular web application written in PHP - Wordpress. Although Wordpress saves most of it’s data in a database, there's also static content that's saved locally in files. In addition to static files that can be uploaded by the users, there are plugins and themes that are part of the local file system as well.

If we setup a cluster of two or more PHP servers, that run one Wordpress application, there is a problem with keeping these files in sync. There are several ways to solve this and we're not going to look into all of them (although this is a good idea for separate post), but let’s see how EFS solves this problem easily in a scalable way.

AWS EFS: The Out-of-the-box Solution

EFS is a file storage service that can be mounted as regular NFS filesystem. On Linux, such a filesystem can be mounted on multiple servers simultaneously. So, for our example WordPress application, we could mount that filesystem and store the /wp-content folder on it (which is a folder WordPress uses to store static content, themes, plugins, etc.).

As stated earlier, EFS is available using standard NFSv4 protocol. This means that mounting EFS on Linux is done using a simple `mount` command - the only prerequisite is installing the NFS client package that's available in almost any Linux distribution.

Since mount is done using the standard `mount` command, we can automate the mounting of EFS, to handle instance restarts, by adding the relevant entry to our /etc/fstab file.


During the EFS preview, we were able to test the performance of EFS and compare the following scenarios:>

  1. Single PHP server, serving Wordpress with all its content from a "local" disk
  2. Single PHP server, with static content offloaded to S3
  3. Cluster of two PHP servers, with static content offloaded to S3
  4. Cluster of two PHP servers, with static content stored on EFS and mounted on each instance

In our tests, we used Zend Server 8.5 with PHP 5.6 and used its deployment mechanism to simplify the creation of PHP clusters, management, and application deployment (especially on cluster).

Our test results showed that a cluster of two Zend Server nodes with static content stored on EFS performed better than the alternative of storing files on S3. It also showed that under simulated load of 50 concurrent users, the results are much more consistent (in terms of response times that didn't vary as much as other solutions).

Image Blog EFS

Additional Resources

Follow this blog for additional posts on how to use EFS with your PHP apps and how to automate and scale your application using Zend Server on AWS.

Zend Server Cloud Solutions

Additional Resources