Install PHPNG (next generation) on Ubuntu 14.04 Trusty Tahr
You might have heard of PHPNG (next generation). PHPNG is the new approach to dramatic speedup website performance, it aims to better performance and memory usage efficiency to PHP. It is a new PHP branch based on a refactored Zend Engine.
Spin up a Digital Ocean Droplet
The easiest (and probalby fastest) way to test PHPNG, is to spin up a new Digital Ocean droplet with a Ubuntu 14.04 x64 Linux Distribution.
Install required packages
Install some packages to build PHPNG.
Note: All of the following shell commands should be executed as root, or prefixed with sudo.
Install correct version of bison
Since the distro package of bison1 isn’t the correct version, you need to build it from source.
Clone PHPNG source
Clone the PHPNG source repository and checkout the phpng branch.
Build and install PHPNG
Create php.ini
Create a new file /etc/php.ini and add the following lines:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
max_execution_time=600
memory_limit=128M
error_reporting=0
display_errors=0
log_errors=0
user_ini.filename=
realpath_cache_size=2M
cgi.check_shebang_line=0
zend_extension=opcache.so
opcache.enable_cli=1
opcache.save_comments=0
opcache.fast_shutdown=1
opcache.validate_timestamps=1
opcache.revalidate_freq=60
opcache.use_cwd=1
opcache.max_accelerated_files=100000
opcache.max_wasted_percentage=5
opcache.memory_consumption=128
opcache.consistency_checks=0
date.timezone = Europe/Brussels
Test installation
Check if your installation succeeded:
You can try running composer update on a project and see the performance gain!
Run FastCGI server using CGI SAPI or FPM
Create a shell script (fpm.sh) with the following lines:
1
2
#!/bin/bash
PHP_FCGI_CHILDREN=4 PHP_FCGI_MAX_REQUESTS=0 php-cgi -b /tmp/fcgi-php
Executing that will create a socket on /tmp/fcgi-php.
PHP_FCGI_CHILDREN
will launch 4 child processes to actually handle the requests.PHP_FCGI_MAX_REQUESTS
tells how many requests to serve before respawning fcgi, 0 means unlimited.
PHPNG and Nginx
You can create a simple virtual host using your new socket to process php.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
upstream phpfcgi {
server unix://tmp/fcgi-php;
}
server {
listen 80;
root /var/www/web;
server_tokens off;
index index.php;
location ~* \.php$ {
try_files $uri =404;
fastcgi_pass phpfcgi;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
Enjoy your blazing fast PHPNG setup!
-
Bison is a general-purpose parser generator that converts an annotated context-free grammar into a deterministic LR or generalized LR (GLR) parser employing LALR(1) parser tables. ↩
Thanks for reading
Feel free to leave a comment if you have remarks or like this post