PHP5.5 on Debian (Wheezy)

From HostmasterWiki
Jump to: navigation, search


Prepare[edit]

$ sudo apt-get 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.5.24.tar.gz http://de2.php.net/get/php-5.5.24.tar.gz/from/this/mirror 
$ tar xvfz php-5.5.24.tar.gz
$ cd php-5.5.24

Compile & Install[edit]

CLI[edit]

$ ./configure \
--prefix=/usr \
--sysconfdir=/etc \
--localstatedir=/var \
--disable-cgi \
--with-config-file-path=/etc/php5/cli \
--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-mysql \
--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-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-mysql \
--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 {
        rotate 7
        daily
        missingok
        notifempty
        compress
        delaycompress
        create 0640 www-data www-data
        postrotate
                [ ! -f /var/run/php5-fpm.pid ] || kill -USR1 `cat /var/run/php5-fpm.pid`
        endscript
}

php-fpm.conf[edit]

$ sudo mkdir /var/www
$ sudo mkdir -p /etc/php5/fpm
$ sudo mkdir -p /var/log/php-fpm
$ sudo chown www-data:www-data /var/log/php-fpm/
$ sudo touch /var/log/php-fpm/php-fpm.log
$ sudo chown www-data:www-data /var/log/php-fpm/php-fpm.log
$ 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 ; 
;;;;;;;;;;;;;;;;;;;;

[www]

user = www-data
group = www-data
listen.owner = www-data
listen.group = www-data
listen.mode = 0660

listen = /var/run/php5-fpm.sock
listen.backlog = 1024

pm = dynamic
pm.max_children = 64
pm.start_servers = 15
pm.min_spare_servers = 10
pm.max_spare_servers = 20
pm.max_requests = 10000

pm.status_path = /status
ping.path = /ping

;slowlog = /var/log/php-fpm/$pool.log.slow
;request_slowlog_timeout = 10s
request_terminate_timeout = 10m

chdir = /var/www
catch_workers_output = no

security.limit_extensions = .php

env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

php_admin_value[disable_functions] = exec, show_source, system, shell_exec, passthru, popen, proc_open, proc_nice, symlink, dl

php.ini[edit]

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


[PHP]

; default open-basedir
open_basedir = "/var/www/:/tmp/:/usr/lib/php/" 

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
error_log = /var/log/php-fpm/www.log

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-20121212/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=sphinx.so

; 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_*

$ ln -s /usr/share/munin/plugins/phpfpm_average /etc/munin/plugins/phpfpm_average && \
ln -s /usr/share/munin/plugins/phpfpm_connections /etc/munin/plugins/phpfpm_connections && \
ln -s /usr/share/munin/plugins/phpfpm_memory /etc/munin/plugins/phpfpm_memory && \
ln -s /usr/share/munin/plugins/phpfpm_status /etc/munin/plugins/phpfpm_status && \
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