Archive for December 14th, 2016

Increasing php 5.6 performance of ec2 instance with opcache and php-fpm

We have installed Apache 2.4 and php 5.6 while migrating from windows server to aws and things have been running pretty good on t2.micro instance for the web server and RDS instance for the database. However, it can run better and this is where opcache and php-fpm come into play.

To install php-fpm and opchache for php 5.6 on amazon linux, simply run:


sudo yum install php56-fpm
sudo yum install php56-opcache

You would need to have proxy and proxy_fcgi for php-fpm, check if those are enabled:


httpd -M | grep proxy

if not, enable:


sudo a2enmod proxy proxy_fcgi

To enable php-fpm we had to edit our vhosts to include this configuration:


vi /etc/httpd/conf.d/vhost.conf


<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>

For reference, more details on configuration here.

start php-fpm, restart apache


sudo service php-fpm restart
sudo service httpd restart

Opcache gave us a significant performance boost.