PHP5.6 on Ubuntu (14.04)

From HostmasterWiki
Jump to: navigation, search


Prepare[edit]

$ sudo apt install \
make \
gcc \
g++ \
libicu-dev \
libssl-dev \
libxml2-dev \
libcurl4-openssl-dev \
libjpeg-dev \
libvpx-dev \
libpng12-dev \
libfreetype6-dev \
libc-client2007e-dev \
libmcrypt-dev \
libxslt1-dev \
libbz2-dev
 
$ wget -O php-5.6.15.tar.gz http://de2.php.net/get/php-5.6.15.tar.gz/from/this/mirror
$ tar xvfz php-5.6.15.tar.gz
$ cd php-5.6.15

Compile & Install[edit]

CLI[edit]

$ ./configure \
--prefix=/usr \
--sysconfdir=/etc \
--localstatedir=/var \
--disable-cgi \
--with-config-file-path=/etc/php5/cli \
--with-config-file-scan-dir=/etc/php5/cli/conf.d \
--with-libxml-dir \
--with-openssl \
--with-pcre-regex \
--with-zlib \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-exif \
--enable-ftp \
--with-gd \
--with-vpx-dir \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--with-gettext \
--with-imap \
--with-imap-ssl \
--with-kerberos \
--enable-bcmath \
--enable-mbstring \
--with-mcrypt \
--with-mysqli \
--with-pdo-mysql \
--enable-shmop \
--enable-soap \
--enable-sockets \
--with-xmlrpc \
--with-xsl \
--enable-zip \
--with-iconv-dir \
--with-pear \
--enable-intl \
--enable-opcache \
--enable-pcntl
 
$ make
$ sudo make install
$ make clean

FPM[edit]

$ ./configure \
--prefix=/usr \
--sysconfdir=/etc \
--localstatedir=/var \
--disable-cli \
--disable-cgi \
--without-pear \
--enable-fpm \
--with-config-file-path=/etc/php5/fpm \
--with-config-file-scan-dir=/etc/php5/fpm/conf.d \
--with-libxml-dir \
--with-openssl \
--with-pcre-regex \
--with-zlib \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-exif \
--enable-ftp \
--with-gd \
--with-vpx-dir \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--with-gettext \
--with-imap \
--with-imap-ssl \
--with-kerberos \
--enable-bcmath \
--enable-mbstring \
--with-mcrypt \
--with-mysqli \
--with-pdo-mysql \
--enable-shmop \
--enable-soap \
--enable-sockets \
--with-xmlrpc \
--with-xsl \
--enable-zip \
--enable-intl \
--enable-opcache \
--with-iconv-dir
 
$ make 
$ sudo make install
$ sudo cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
$ sudo chmod +x /etc/init.d/php-fpm
$ sudo update-rc.d php-fpm defaults

Install[edit]

logrotate[edit]

$ sudo nano /etc/logrotate.d/php-fpm


/var/log/php-fpm/*.log /var/www/*/logs/phperror.log /var/www/*/logs/slow.log {
        rotate 7
        daily
        missingok
        notifempty
        compress
        delaycompress
        nocreate
	sharedscripts
        postrotate
                [ ! -f /var/run/php5-fpm.pid ] || kill -USR1 `cat /var/run/php5-fpm.pid`
        endscript
}

php-fpm.conf[edit]

$ sudo mkdir -p /var/www /etc/php5/fpm /var/log/php-fpm
$ sudo rm /etc/php-fpm.conf.default
$ sudo nano /etc/php-fpm.conf


;;;;;;;;;;;;;;;;;;;;;
; FPM Configuration ;
;;;;;;;;;;;;;;;;;;;;;
 
[global]
pid = /var/run/php-fpm.pid
error_log = /var/log/php-fpm/php-fpm.log
log_level = warning
 
emergency_restart_threshold = 10
emergency_restart_interval = 1m
process_control_timeout = 10s
 
daemonize = yes
 
rlimit_files = 8192
rlimit_core = 0
 
events.mechanism = epoll
 
;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ; 
;;;;;;;;;;;;;;;;;;;;

php.ini[edit]

$ sudo nano /etc/php5/fpm/php.ini


[PHP]
 
; default open-basedir
open_basedir = "/var/www/:/tmp/:/usr/lib/php/" 
 
disable_functions = exec, show_source, system, shell_exec, passthru, popen, proc_open, proc_nice, symlink, dl
 
engine = On
short_open_tag = On
asp_tags = Off
precision = 14
y2k_compliance = On
 
output_buffering = 4096
zlib.output_compression = On
zlib.output_compression_level = 9
 
implicit_flush = Off
serialize_precision = 100
 
allow_call_time_pass_reference = Off
safe_mode = Off
expose_php = Off
 
max_execution_time = 600
max_input_time = 600
memory_limit = 256M
 
display_errors = Off
display_startup_errors = Off
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = Off
html_errors = Off
 
log_errors = On
error_reporting = E_ALL
 
variables_order = "GPCS" 
request_order = "GP" 
register_globals = Off
register_long_arrays = Off
register_argc_argv = Off
auto_globals_jit = On
 
magic_quotes_gpc = Off
magic_quotes_runtime = Off
magic_quotes_sybase = Off
 
default_mimetype = "text/html" 
always_populate_raw_post_data = Off
 
include_path = ".:/usr/lib/php:/usr/lib/php/Smarty" 
 
enable_dl = Off
cgi.fix_pathinfo=1
 
file_uploads = On
upload_tmp_dir = /tmp/
upload_max_filesize = 50M
max_file_uploads = 20
post_max_size = 50M
 
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 10
 
[Date]
date.timezone = UTC
 
[mail function]
mail.add_x_header = Off
 
[mysqlnd]
mysqlnd.collect_statistics = Off
mysqlnd.collect_memory_statistics = Off
 
[Session]
session.gc_maxlifetime = 86400
 
; OPCACHE
zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20131226/opcache.so
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=10000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
opcache.use_cwd=1
 
; EXTENSION SECTION
extension=igbinary.so
extension=apcu.so
extension=memcached.so
extension=imagick.so
extension=geoip.so
extension=ssh2.so
 
apc.serializer=igbinary
apc.shm_size=512M
memcached.serializer=igbinary
 
; VHOST SECTION
[HOST=yourdomain.com]
open_basedir = "/var/www/yourdomain.com/www/:/tmp/:/usr/lib/php/"

Munin[edit]

$ sudo apt-get install libwww-perl
$ cd /usr/share/munin/plugins
$ sudo wget https://github.com/tjstein/php5-fpm-munin-plugins/archive/master.zip
$ sudo unzip master.zip
$ sudo mv php5-fpm-munin-plugins-master/* ./
$ sudo rm -rf php5-fpm-munin-plugins-master master.zip
$ sudo chmod +x phpfpm_*
 
$ sudo ln -s /usr/share/munin/plugins/phpfpm_average /etc/munin/plugins/phpfpm_average && \
sudo ln -s /usr/share/munin/plugins/phpfpm_connections /etc/munin/plugins/phpfpm_connections && \
sudo ln -s /usr/share/munin/plugins/phpfpm_memory /etc/munin/plugins/phpfpm_memory && \
sudo ln -s /usr/share/munin/plugins/phpfpm_status /etc/munin/plugins/phpfpm_status && \
sudo ln -s /usr/share/munin/plugins/phpfpm_processes /etc/munin/plugins/phpfpm_processes
 
$ sudo echo -ne "[phpfpm*]\nenv.phpbin php-fpm" > /etc/munin/plugin-conf.d/phpfpm