BreadcrumbHomeResourcesBlog PHP Clusters Simplified With AWS EFS June 30, 2016 PHP Clusters Simplified With AWS EFSAWSZend ServerOne 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.Table of ContentsWhat Is AWS EFS Used For?PHP Clusters ChallengeAWS EFS: The Out-of-the-box SolutionAdditional ResourcesTable of Contents1 - What Is AWS EFS Used For?2 - PHP Clusters Challenge3 - AWS EFS: The Out-of-the-box Solution4 - Additional ResourcesBack to topWhat 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.Back to topPHP Clusters ChallengeManaging 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.Back to topAWS EFS: The Out-of-the-box SolutionEFS 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.PerformanceDuring the EFS preview, we were able to test the performance of EFS and compare the following scenarios:>Single PHP server, serving Wordpress with all its content from a "local" diskSingle PHP server, with static content offloaded to S3Cluster of two PHP servers, with static content offloaded to S3Cluster of two PHP servers, with static content stored on EFS and mounted on each instanceIn 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).Back to topAdditional ResourcesFollow 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 SolutionsAdditional ResourcesDeveloping Web Applications with PHP hubRunning a PHP AWS Cluster blogAutoscaling Magento With a CloudFormation Template and Zend Server blogPHP Development: Using PHP Extensions blogWriting PHP Extensions technical guideBack to top