Installing the memcached PHP module for PHP 7 on Plesk

To install the PHP memcached module for PHP 7 on a Plesk 12.5 server running CentOS 6.8. Please note that this should also work on CentOS 7. We’re going to need to install the libmemcached dev package first: sudo yum install -y libmemcached-devel Next install the PHP 7 dev package. Since this is a Plesk server we install the Plesk version of this package: yum install -y plesk-php70-devel After installing these, cd to a temporary directory and clone the memcached module git repo and checkout the php7 branch: cd /tmp git clone https://github.com/php-memcached-dev/php-memcached.git git checkout php7 Next build the memcached module. Make sure to use the PHP 7 version of phpize and point to the PHP 7 version of php-config in the configure command: /opt/plesk/php/7.0/bin/phpize ./configure --disable-memcached-sasl --with-php-config=/opt/plesk/php/7.0/bin/php-config make sudo make install The module has been built and installed now. Now you only have to enable it: cd /opt/plesk/php/7.0/etc/php.d echo "extension=memcached.so" > memcached.ini Finally restart the webserver for the changes to take effect: sudo apachectl restart To make sure the module is loaded you can run: /opt/plesk/php/7.0/bin/php -m memcached should show up in the list of ...

(Read more...)

Adding ReactJS components to an existing jQuery front-end

For a ZF2 project I’ve been using a traditional approach where the server-side renders the HTML. For interactive views and AJAX stuff I’ve been using jQuery, but as we all know this can get messy as soon as the views are becoming more complex. I had been playing with ReactJS already, but until now I’ve never used it in a live application. I’m planning to slowly replace some components of the views with React components. My current project structure looks like this (typical for ZF2): The main challenge I’m expecting to walk into is getting Babel and Webpack setup so my ES6 code will be converted to ES5 and my JSX is automatically converted into native JavaScript (Babel) and creating one .js file with my React code and its dependencies (Webpack). Since I don’t want to throw my existing front-end code structure overboard I need to have them play nice side-by-side. My first idea is to just create a separate folder to hold my React sources. I’ve created this folder in the root of my project folder and named it reactjs. I don’t want to put it in the public folder, since the sources shouldn’t be accessible.   First I ...

(Read more...)

Installing HHVM 3.2 on a CentOS 6.7 server with Plesk

I wanted to play with HHVM a little bit to see if the speed gain is really as impressive as the benchmarks are showing. I tried this on a VPS running CentOS 6.7 and Plesk 11.5 and did run into a dependency collision using yum: Error: Package: psa-libxml-proxy-2.7.8-13032215.x86_64 (@PSA_11_5_30-dist) Requires: libboost_program_options.so.5()(64bit) Removing: boost-program-options-1.41.0-27.el6.x86_64 (@base) libboost_program_options.so.5()(64bit) Updated By: boost-program-options-1.54.0-7.el6.x86_64 (hop5) To get around this I first installed boost: wget http://www.hop5.in/yum/el6/boost-program-options-1.54.0-7.el6.x86_64.rpm rpm -ivh boost-program-options-1.54.0-7.el6.x86_64.rpm After installing boost you can install yum to install the hhvm 3.2 package, like so: cd /etc/yum.repos.d sudo wget http://www.hop5.in/yum/el6/hop5.repo yum clean all yum install hhvm To test if hhvm is working: hhvm --version This should return something like this: HipHop VM 3.2.0 (rel) Compiler: tags/HHVM-3.2.0-0-g01228273b8cf709aacbd3df1c51b1e690ecebac8 Repo schema: c52ba40f4a246d35a88f1dfc1daf959851ced8aa To use HHVM as a FastCGI handler from Apache/Nginx I first created a simple config file in /etc/hhvm (this directory should have been created installing the hhvm package). I named my config file hhvm.hdf and the content looks like this: Server { Port = 9000 Type = fastcgi FixPathInfo = true } Log { Level = Verbose UseLogFile = true Header = true File = /var/log/hhvm/error.log Access { * { File = /var/log/hhvm/access.log Format = %{X-Forwarded-For}i %l %u %t ...

(Read more...)

ZF2 routes with parameters containing slashes

The routing system of ZF2 is pretty flexible, which is nice in case you need something custom like I did today. I needed to be able to handle some Base64 parameter data and so it’s possible that this data will contain slashes. Therefore a plain vanilla segment route like this won’t work: 'my-route' => array( 'type' => 'Segment', 'options' => array( 'route' => '/myroute/:encdata', 'defaults' => array( 'controller' => 'Application\Controller\MyController', 'action' => 'handle-enc-data', 'encdata' => null, ), ), ), When my URL would be something like this the route wouldn’t be matched because of the slash characters inside of the Base64 parameter: http://my.local/myroute/c3ViamVjdHM/X2Q9MQ== A regex route can solve this problem. It’s actually pretty simple: 'my-route' => array( 'type' => 'regex', 'options' => array( 'regex' => '/reg4p/(?.*)', 'spec' => '/reg4p/%encdata%', 'defaults' => array( 'controller' => 'Application\Controller\MyController', 'action' => 'handle-enc-data', 'encdata' => null, ), ...

(Read more...)

Events, the EventManager and ListenerAggregates in Zend Framework 2

There are a bunch of good articles on this subject on the web already, but for my own reference I put together this article listing the steps to take to set up your own custom event listeners in your ZF2 application. Start by creating a class handling the events. This class will implement the Zend\EventManager\ListenerAggregateInterface. In this example I will create a listener aggregate that takes care of sending out e-mails for different events. I like to keep my listener aggregates to be groupings of related actions in response to events. For example I would have a LogEventsListener listening to the ‘runtime_error’ event. The handler for this event would for instance make a log entry of what went wrong. At the same time I would have a MailEventsListener also listening to the ‘runtime_error’ event and send out an e-mail to the developer or administrator when a fatal error occurs in the application (random example). Besides the ‘runtime_error’ event there could be other events that either the LogEventsListener or MailEventsListener deal with. So back to the code the MailEventsListener could look like this. MyApp\Listener\MailEventsListener.php:   <?php namespace MyApp\Listener; use Zend\EventManager\EventInterface; use Zend\EventManager\EventManagerInterface; use Zend\EventManager\ListenerAggregateInterface; use Zend\ServiceManager\ServiceLocatorAwareTrait; use Zend\ServiceManager\ServiceLocatorAwareInterface; use MyApp\Config\ConfigAwareTrait; use ...

(Read more...)