Openshift 安装 PHP 7 + Tengine

  • 创建应用,选择Catridge: Do-It-Yourself 0.1
  • 进入新建的应用,添加 MySQL
  • SSH连接到 Openshift,Windows 下推荐使用 PuTTY
  • 运行 env 命令,查看环境变量
  • 下载 jemalloc 3.6.0 用于内存管理,Tengine 编译需要
wget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2
tar -xjf jemalloc-3.6.0.tar.bz2
rm -rf jemalloc-3.6.0.tar.bz2
  • 下载pcre,Nginx/Tengine编译需要
wget -c ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz
tar -zxvf pcre-8.41.tar.gz
rm -rf pcre-8.41.tar.gz
  • 下载Tengine并编译安装
git clone git://github.com/alibaba/tengine.git
cd tengine
./configure \
--prefix=$OPENSHIFT_DATA_DIR/nginx \
--with-pcre=$OPENSHIFT_DATA_DIR/pcre-8.38 \
--with-jemalloc=$OPENSHIFT_DATA_DIR/jemalloc-3.6.0 \
--with-ipv6 \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module=shared \
--with-http_sysguard_module=shared \
--with-http_image_filter_module=shared \
--with-http_footer_filter_module=shared \
--with-http_trim_filter_module=shared \
--with-http_memcached_module=shared \
--with-http_empty_gif_module=shared

make
make dso_install
make install
  • 下载并编译 PHP7.1.8 注意,需要 >= 30 分钟,请耐心等待
wget -c -O php-7.1.8.tar.gz http://php.net/get/php-7.1.8.tar.gz/from/this/mirror
tar -zxvf php-7.1.8.tar.gz
cd php-7.1.8

./configure \
--prefix=$OPENSHIFT_DATA_DIR/php \
--with-config-file-path=$OPENSHIFT_DATA_DIR/php/etc \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-embedded-mysqli=shared \
--enable-pdo \
--enable-fpm \
--with-zlib \
--enable-xml \
--enable-bcmath \
--with-curl \
--with-gd \
--enable-zip \
--enable-mbstring \
--enable-sockets \
--enable-ftp \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-libxml-dir=/usr \
--disable-rpath \
--enable-shmop \
--enable-sysvsem \
--enable-sysvshm \
--enable-sysvmsg \
--enable-inline-optimization \
--enable-mbregex \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--enable-ftp \
--enable-calendar \
--enable-exif \
--enable-zip \
--with-gettext \
--with-xmlrpc \
--with-xsl \
--with-bz2 \
--enable-wddx \
--enable-opcache \
--without-pear \
--disable-fileinfo

cp -f php.ini-production $OPENSHIFT_DATA_DIR/php/etc/php.ini
  • 使用以下文本替换 php-fpm.conf
;;;;;;;;;;;;;;;;;;;;;
; FPM Configuration ;
;;;;;;;;;;;;;;;;;;;;;

; All relative paths in this configuration file are relative to PHP's install
; prefix (). This prefix can be dynamically changed by using the
; '-p' argument from the command line.

;;;;;;;;;;;;;;;;;;
; Global Options ;
;;;;;;;;;;;;;;;;;;

[global]
; Pid file
; Note: the default prefix is $OPENSHIFT_DATA_DIR/php/var
; Default Value: none
pid = run/php-fpm.pid

; Error log file
; If it's set to "syslog", log is sent to syslogd instead of being written
; into a local file.
; Note: the default prefix is $OPENSHIFT_DATA_DIR/php/var
; Default Value: log/php-fpm.log
error_log = log/php-fpm.log

; syslog_facility is used to specify what type of program is logging the
; message. This lets syslogd specify that messages from different facilities
; will be handled differently.
; See syslog(3) for possible values (ex daemon equiv LOG_DAEMON)
; Default Value: daemon
;syslog.facility = daemon

; syslog_ident is prepended to every message. If you have multiple FPM
; instances running on the same server, you can change the default value
; which must suit common needs.
; Default Value: php-fpm
;syslog.ident = php-fpm

; Log level
; Possible Values: alert, error, warning, notice, debug
; Default Value: notice
;log_level = notice

; If this number of child processes exit with SIGSEGV or SIGBUS within the time
; interval set by emergency_restart_interval then FPM will restart. A value
; of '0' means 'Off'.
; Default Value: 0
;emergency_restart_threshold = 0

; Interval of time used by emergency_restart_interval to determine when
; a graceful restart will be initiated.  This can be useful to work around
; accidental corruptions in an accelerator's shared memory.
; Available Units: s(econds), m(inutes), h(ours), or d(ays)
; Default Unit: seconds
; Default Value: 0
;emergency_restart_interval = 0

; Time limit for child processes to wait for a reaction on signals from master.
; Available units: s(econds), m(inutes), h(ours), or d(ays)
; Default Unit: seconds
; Default Value: 0
;process_control_timeout = 0

; The maximum number of processes FPM will fork. This has been designed to control
; the global number of processes when using dynamic PM within a lot of pools.
; Use it with caution.
; Note: A value of 0 indicates no limit
; Default Value: 0
; process.max = 128

; Specify the nice(2) priority to apply to the master process (only if set)
; The value can vary from -19 (highest priority) to 20 (lowest priority)
; Note: - It will only work if the FPM master process is launched as root
;       - The pool process will inherit the master process priority
;         unless specified otherwise
; Default Value: no set
; process.priority = -19

; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging.
; Default Value: yes
;daemonize = yes

; Set open file descriptor rlimit for the master process.
; Default Value: system defined value
;rlimit_files = 1024

; Set max core size rlimit for the master process.
; Possible Values: 'unlimited' or an integer greater or equal to 0
; Default Value: system defined value
;rlimit_core = 0

; Specify the event mechanism FPM will use. The following is available:
; - select     (any POSIX os)
; - poll       (any POSIX os)
; - epoll      (linux >= 2.5.44)
; - kqueue     (FreeBSD >= 4.1, OpenBSD >= 2.9, NetBSD >= 2.0)
; - /dev/poll  (Solaris >= 7)
; - port       (Solaris >= 10)
; Default Value: not set (auto detection)
;events.mechanism = epoll

; When FPM is built with systemd integration, specify the interval,
; in seconds, between health report notification to systemd.
; Set to 0 to disable.
; Available Units: s(econds), m(inutes), h(ours)
; Default Unit: seconds
; Default value: 10
;systemd_interval = 10

;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ;
;;;;;;;;;;;;;;;;;;;;

; Multiple pools of child processes may be started with different listening
; ports and different management options.  The name of the pool will be
; used in logs and stats. There is no limitation on the number of pools which
; FPM can handle. Your system will tell you anyway :)

[www]
listen = var/run/php-cgi.sock

pm = ondemand

pm.max_children = 256
pm.start_servers = 8

pm.min_spare_servers = 8
pm.max_spare_servers = 32

pm.max_requests = 2048
pm.process_idle_timeout = 10s
request_terminate_timeout = 120
request_slowlog_timeout = 20

slowlog = var/log/slow.log
rlimit_files = 51200
rlimit_core = 0
  • 在 $OPENSHIFT_DATA_DIR/php/etc/php.ini 尾部追加以下内容
zend_extension=$OPENSHIFT_DATA_DIR/php/lib/php/extensions/no-debug-non-zts-20131226/opcache.so
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=4
opcache.max_accelerated_files=2048

注:$OPENSHIFT_DATA_DIR,替换为env显示的值

  • $OPENSHIFT_DATA_DIR/nginx/conf/nginx.conf 替换为以下内容
worker_processes  2;
pid        logs/nginx.pid;

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    gzip on;

    server {
        listen     $OPENSHIFT_DIY_IP:$$OPENSHIFT_DIY_PORT;
        root       $OPENSHIFT_REPO_DIR;
        index index.html index.htm index.php

        location ~ .*\.php(\/.*)*$ {
            include        fastcgi.conf;

            fastcgi_pass unix:$OPENSHIFT_DATA_DIR/php/var/run/php-cgi.sock;
        }
        
        # avoid unnecessary log
        location = /favicon.ico {
            access_log off;
            log_not_found off;
        }
    
        location = /robots.txt {
            access_log off;
            log_not_found off;
        }
    }
}

events {
    worker_connections  1024;
}

注:$OPENSHIFT开头的变量,替换为env显示的真实值

  • 重要!停止Ruby, 否则端口被占用,无法启动 Nginx
ctl_all stop
  • 修改开机启动 tengine 和 php-fpm,将$OPENSHIFT_REPO_DIR/.openshift/action_hooks/start 替换为以下内容
nohup $OPENSHIFT_DATA_DIR/nginx/sbin/nginx > $OPENSHIFT_DIY_LOG_DIR/nginx.log 2>&1 &
nohup $OPENSHIFT_DATA_DIR/php/sbin/php-fpm > $OPENSHIFT_DIY_LOG_DIR/phpfpm.log 2>&1 &
  • 修改关机文件,关闭 tengine 和 php-fpm

$OPENSHIFT_REPO_DIR/.openshift/action_hooks/stop 替换为以下内容

killall nginx
killall php-fpm
  • 重启应用使修改生效
ctl_all restart

暂无评论

发表评论

*