I’ve recently switched back from HHVM to PHP 5.6 because the version of HHVM I was using (3.6.6) keep hogging memory and failing to respond, and upgrading to a more recent version of HHVM is really difficult on Amazon Linux. PHP7 doesn’t work with one of my WordPress themes (Photocrati) so I can’t use that yet. Read on for the key things I did to get PHP 5.6 working on Amazon Linux 2016.03.
First I removed PHP 5.3, because having multiple versions of PHP installed can apparently cause issues.
yum remove php php-cli php-common php-fpm php-mysql php-pdo httpd httpd-tools nano
PHP 5.6 is in the Amazon repository, so installing it is simple. Note that I have opcache on its own line as you probably want to get things going with it before you install it, and installing it enables the opcache automatically.
yum install php56 php56-cli php56-common php56-fpm php56-mysqlnd php56-pdo php56-xml php56-xmlrpc php56-soap php56-xml php56-xmlrpc php56-soap php56-gd
yum install php56-opcache
Next you need to change a few files. Your values will obviously vary. This one tells PHP-FPM who to run as
vi /etc/php-fpm-5.6.d/www.conf user = tim group = www-data
This sets the session folder permissions so PHP-FPM can write to it. This is as a result of getting the error message “Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/5.6/session) in Unknown on line 0”. You can change your session.save_path but I found that setting in multiple places and wasn’t sure which to change.
chown tim:www-data /var/lib/php/5.6/session chmod 770 /var/lib/php/5.6/session
This tweaks php.ini to set your timezone
vi /etc/php.ini date.timezone = Pacific/Auckland
I still have one problem with thumbnails not being correctly created under WordPress, but I’ll update this post once I work out how to resolve that.
HHVM vs PHP 5.6 WordPress Performance
I did a bit of quick testing on my t2.micro to see how performance was with my WordPress install, caching turned off, 5 simultaneous users:
- HHVM 3.6.6 : 10 requests per second, 93ms per request
- PHP 5.6 with no opcache: 3.4 requests per second, 295ms per request
- PHP 5.6 with opcache: 8.6 requests per second, 116ms per request
Given that PHP 5.6 is more reliable than HHVM I’ll take the small performance hit. As you can see the opcache makes a huge difference, increasing performance by 150%.