Docker环境下编译安装PHP7.1.4 Nginx1.12.0

基础准备

yum provides ifconfig
yum install -y net-tools vim wget unzip

工具安装(gcc-c++在编译libmcrypt时用到)

yum install -y make \
gcc \
gcc-c++ \
autoconf \
cmake \
libxml2-devel \
openssl-devel \
bzip2-devel \
libcurl-devel \
libpng-devel \
libjpeg-turbo-devel \
libwebp-devel \
libXpm-devel \
freetype-devel \
gmp-devel \
unixODBC-devel \
readline-devel \
net-snmp-devel \
expat-devel \
libxslt-devel
ln -s /usr/lib64/libexpat.* /usr/lib/

mkdir -p /data/soft
cd /data/soft

wget -c http://cn2.php.net/distributions/php-7.1.4.tar.gz
tar zxvf php-7.1.4.tar.gz

cd /data/soft
wget -c https://github.com/htacg/tidy-html5/archive/master.zip -O tidy-html5.zip
unzip tidy-html5.zip -d tidy-html5
cd tidy-html5/tidy-html5-master/
cd build/cmake/
cmake ../..
make
make install
cd ../../../../

如果要编译到PHP里,还要cd 到PHP的目录代码把ext/tidy/*.c的代码里的 "buffio.h" 转成 "tidybuffio.h"
cd /data/soft/php-7.1.4/
sed -i 's/buffio.h/tidybuffio.h/' ext/tidy/*.c

centos源不能安装libmcrypt-devel,由于版权的原因没有自带mcrypt的包

wget -c http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download -O ./libmcrypt-2.5.8.tar.gz
编译
tar zxvf libmcrypt-2.5.8.tar.gz 
cd libmcrypt-2.5.8/ 
./configure 
make 
make install 
/sbin/ldconfig 
cd libltdl/ 
./configure --enable-ltdl-install 
make 
make install 
cd ../../

正式编译

php -i |grep ini
编译的php.ini的默认位置是指定目录下的

cd php-7.1.4


./configure --sysconfdir=/etc --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-fpm  --with-fpm-user=nginx --with-fpm-group=nginx \
--enable-bcmath \
--enable-calendar \
--enable-exif \
--enable-ftp \
--enable-mbstring \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem --enable-sysvshm --enable-sysvmsg \
--enable-wddx --with-libexpat-dir \
--enable-zip \
--with-bz2 \
--with-curl \
--with-zlib \
--with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-webp-dir --with-xpm-dir --with-freetype-dir \
--with-gettext \
--with-gmp \
--with-mcrypt \
--with-mhash \
--with-unixODBC=/usr \
--with-pdo-odbc=unixODBC,/usr \
--with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
--with-openssl \
--with-readline \
--with-snmp \
--with-tidy \
--with-xmlrpc \
--with-xsl \
--with-freetype-dir \
--enable-opcache

pthreads (需要线程安全支持)

要使用 pthreads 扩展,需要构建 PHP 时启用 ZTS (Zend Thread Safety)。(--enable-maintainer-zts 选项, Windows 平台为 --enable-zts)

编译安装

make
make install
    
Installing shared extensions:     /usr/local/lib/php/extensions/no-debug-non-zts-20160303/
Installing PHP CLI binary:        /usr/local/bin/
Installing PHP CLI man page:      /usr/local/php/man/man1/
Installing PHP FPM binary:        /usr/local/sbin/
Installing PHP FPM defconfig:     /etc/
Installing PHP FPM man page:      /usr/local/php/man/man8/
Installing PHP FPM status page:   /usr/local/php/php/fpm/
Installing phpdbg binary:         /usr/local/bin/
Installing phpdbg man page:       /usr/local/php/man/man1/
Installing PHP CGI binary:        /usr/local/bin/
Installing PHP CGI man page:      /usr/local/php/man/man1/
Installing build environment:     /usr/local/lib/php/build/
Installing header files:          /usr/local/include/php/
Installing helper programs:       /usr/local/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/lib/php/
[PEAR] Archive_Tar    - already installed: 1.4.2
[PEAR] Console_Getopt - already installed: 1.4.1
[PEAR] Structures_Graph- already installed: 1.1.1
[PEAR] XML_Util       - already installed: 1.4.2
[PEAR] PEAR           - already installed: 1.10.3
Wrote PEAR system config file at: /etc/pear.conf
You may want to add: /usr/local/lib/php to your php.ini include_path
/data/soft/php-7.1.4/build/shtool install -c ext/phar/phar.phar /usr/local/bin
ln -s -f phar.phar /usr/local/bin/phar
Installing PDO headers:           /usr/local/include/php/ext/pdo/

需要pecl安装的扩展

https://github.com/php7-extensions 有较多php7扩展

memcache
memcached
redis
igbinary
imagick
xhprof

memcache 有github包

cd /data/soft
wget -c https://codeload.github.com/websupport-sk/pecl-memcache/zip/NON_BLOCKING_IO_php7 -O pecl-memcache.zip
unzip pecl-memcache.zip
cd pecl-memcache-NON_BLOCKING_IO_php7/
/data/server/php7/bin/phpize
./configure --with-php-config=/data/server/php7/bin/php-config 
make
make install
cd ../

memcached 原生支持

wget -c https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
tar zxvf libmemcached-1.0.18.tar.gz
cd libmemcached-1.0.18
./configure
make
make install
cd ../



wget -c http://pecl.php.net/get/memcached-3.0.3.tgz
tar zxvf memcached-3.0.3.tgz
cd memcached-3.0.3
phpize
./configure --with-php-config=php-config --disable-memcached-sasl
make
make install
cd ../

redis 原生支持

wget -c http://pecl.php.net/get/redis-3.1.2.tgz
tar zxvf redis-3.1.2.tgz 
cd redis-3.1.2
phpize
./configure --with-php-config=php-config 
make
make install
cd ../

igbinary 原生支持

wget -c http://pecl.php.net/get/igbinary-2.0.1.tgz
tar zxvf igbinary-2.0.1.tgz
cd igbinary-2.0.1
phpize
./configure --with-php-config=php-config 
make
make install
cd ../

imagick 原生这个也可以用 也有github包

安装ImageMagick 
wget -c ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz

tar zxvf ImageMagick.tar.gz 
# 这个名字会变
cd ImageMagick-6.9.1-0/
./configure 
make 
make install 
cd ../ 

wget -c http://pecl.php.net/get/imagick-3.4.3.tgz
tar zxvf imagick-3.4.3.tgz
cd imagick-3.4.3
phpize
./configure --with-php-config=php-config 
make
make install
cd ../

swoole 原生支持

wget -c http://pecl.php.net/get/swoole-1.9.9.tgz
tar zxvf swoole-1.9.9.tgz
cd swoole-1.9.9
phpize
./configure --with-php-config=php-config 
make
make install
cd ../

xhprof 原生暂时没有pecl包,https://github.com/Yaoguais/phpng-xhprof 目前可以用

wget -c https://codeload.github.com/Yaoguais/phpng-xhprof/zip/master -O phpng-xhprof.zip
unzip phpng-xhprof.zip
cd phpng-xhprof-master
phpize
./configure --with-php-config=php-config 
make
make install
cd ../

PHP配置

在PHP源码目录下

cd /data/soft/php-7.1.4

cp php.ini-production /etc/php.ini
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm.service
cp /etc/php-fpm.conf.default /etc/php-fpm.conf
cp /etc/php-fpm.d/www.conf.default /etc/php-fpm.d/www.conf
mkdir -p /etc/php.d


vim /etc/php.ini
;expose_php = On
expose_php = Off

;short_open_tag = Off
short_open_tag = On

post_max_size = 30M
upload_max_filesize = 30M

date.timezone = Asia/Shanghai

编辑完保存


echo -e "[opcache]\nzend_extension=opcache.so\nopcache.enable=1\nopcache.enable_cli=1" > /etc/php.d/opcache.ini
echo "extension=igbinary.so" > /etc/php.d/igbinary.ini
echo "extension=imagick.so" > /etc/php.d/imagick.ini
echo "extension=memcached.so" > /etc/php.d/memcached.ini
echo "extension=memcache.so" > /etc/php.d/memcache.ini
echo "extension=redis.so" > /etc/php.d/redis.ini
echo "extension=swoole.so" > /etc/php.d/swoole.ini
echo "extension=phpng_xhprof.so" > /etc/php.d/phpng_xhprof.ini

php -m |grep -E "OPcache|igbinary|imagick|memcache|memcached|redis|xhprof|swoole"

php -v看一下
PHP 7.1.4 (cli) (built: Aug 11 2016 02:14:40) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.1.4, Copyright (c) 1999-2016, by Zend Technologies


vim /etc/php-fpm.d/www.conf

把php-fpm产生的文件用户组改成nginx 
user = nginx 
group = nginx

如果小内存设置为动态,如果是公司内存大,设置static可以在高并发有不错的表现
pm = static 
pm.max_children = 128  (内存量/30) 4G  64/128  8G 128/256

; listen = 127.0.0.1:9000
listen = /var/run/php-fpm.sock

; 如果用上面这个 nginx要如下配置
; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;

;request_slowlog_timeout = 0
;request_slowlog_timeout = 1s
;slowlog = /var/log/php-fpm/www-slow.log

;connect() to unix:/data/server/php7/var/run/php-fpm.sock failed (13: Permission denied) 开启下面几行
listen.owner = nginx
listen.group = nginx
listen.mode = 0660

systemctl enable php-fpm
systemctl start php-fpm

php -m 如下扩展

[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
igbinary
imagick
json
libxml
mbstring
mcrypt
memcache
memcached
mysqli
mysqlnd
odbc
openssl
pcntl
pcre
PDO
pdo_mysql
PDO_ODBC
pdo_sqlite
Phar
posix
readline
redis
Reflection
session
shmop
SimpleXML
snmp
soap
sockets
SPL
sqlite3
standard
swoole
sysvmsg
sysvsem
sysvshm
tidy
tokenizer
wddx
xhprof
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

安装 Nginx

cd /data/soft

新建 nginx 用户
/usr/sbin/groupadd nginx
/usr/sbin/useradd -g nginx nginx

## 随便安装一下
wget -c http://nginx.org/download/nginx-1.12.0.tar.gz
tar zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0
mkdir -p /var/cache/nginx

### 伪装NGINX
vim src/core/nginx.h
    #define NGINX_VERSION      "1.10.1"
    #define NGINX_VER          "nginx/" NGINX_VERSION
    修改成
    #define NGINX_VERSION      "1.0"
    #define NGINX_NAME         "BServer"
    #define NGINX_VER          NGINX_NAME "/" NGINX_VERSION

vim src/http/ngx_http_header_filter_module.c
    static char ngx_http_server_string[] = "Server: nginx" CRLF;
    修改成
    static char ngx_http_server_string[] = "Server: " NGINX_NAME CRLF;

vim src/http/ngx_http_special_response.c
    "<hr><center>nginx</center>" CRLF
    修改成
    "<hr><center>" NGINX_NAME "</center>" CRLF

安装需要的工具及类库
yum install -y gcc pcre-devel openssl-devel zlib-devel

## 默认安装
./configure --prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-threads \
--with-stream \
--with-stream_ssl_module \
--with-http_slice_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-http_v2_module


make
make install


Configuration summary
  + using threads
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/etc/nginx"
  nginx binary file: "/usr/sbin/nginx"
  nginx modules path: "/etc/nginx/modules"
  nginx configuration prefix: "/etc/nginx"
  nginx configuration file: "/etc/nginx/nginx.conf"
  nginx pid file: "/var/run/nginx.pid"
  nginx error log file: "/var/log/nginx/error.log"
  nginx http access log file: "/var/log/nginx/access.log"
  nginx http client request body temporary files: "/var/cache/nginx/client_temp"
  nginx http proxy temporary files: "/var/cache/nginx/proxy_temp"
  nginx http fastcgi temporary files: "/var/cache/nginx/fastcgi_temp"
  nginx http uwsgi temporary files: "/var/cache/nginx/uwsgi_temp"
  nginx http scgi temporary files: "/var/cache/nginx/scgi_temp"

配置自启动

vim /usr/lib/systemd/system/nginx.service

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target


systemctl enable nginx
systemctl start nginx

配置服务器

mkdir -p /etc/nginx/conf.d/


vim /etc/nginx/nginx.conf
#user nobody;
user nginx;
worker_processes  1; # 看看是几核,设置为几
error_log  /data/server/nginx/var/log/nginx/error.log warn;
pid /data/server/nginx/var/run/nginx.pid;

把

http {
    server_tokens off;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';


    access_log  /var/log/nginx/access.log  main;

    gzip on; 
    gzip_min_length 1k; 
    gzip_buffers 16 64k; 
    gzip_http_version 1.1; 
    gzip_comp_level 6;  
    gzip_types text/plain application/x-javascript text/css application/xml; 
    gzip_vary on; 

    client_max_body_size 30M;

    include /etc/nginx/conf.d/*.conf;
}

mkdir -p /var/www
vim /etc/nginx/conf.d/apps.conf

server {
    listen 80;
    server_name localhost;

    #charset utf-8;

    root /var/www;
    index index.php index.html index.htm;

    location / {
        if (!-f $request_filename) {
            rewrite ^/(.+)$ /index.php?$1& last;
        }
    }

    location ~ \.php$ {
        # fastcgi_pass 127.0.0.1:9000;
        fastcgi_pass unix:/var/run/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

安装 mysql5.7

wget -c https://repo.mysql.com/mysql57-community-release-el7-11.noarch.rpm
yum localinstall mysql57-community-release-el7-11.noarch.rpm

yum install -y mysql-community-server

systemctl enable mysqld
systemctl start mysqld

查看临时密码
grep 'temporary password' /var/log/mysqld.log

mysql -uroot -p


set password = password('Mark*123456')
alter user 'root'@'localhost' password expire never;
flush privileges;
exit

mysql -uroot -pMark*123456


grant all privileges on *.* to apps@'%' identified by 'Mark*123456'; 
alter user 'apps'@'%' password expire never;
flush privileges;

安装 memcached

yum install -y memcached

systemctl enable memcached
systemctl start memcached
systemctl stop memcached

安装 redis

yum install -y epel-release

yum install -y redis

systemctl enable redis
systemctl start redis
systemctl stop redis
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,542评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,596评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,021评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,682评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,792评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,985评论 1 291
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,107评论 3 410
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,845评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,299评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,612评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,747评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,441评论 4 333
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,072评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,828评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,069评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,545评论 2 362
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,658评论 2 350

推荐阅读更多精彩内容

  • 一、MemCache简介 session MemCache是一个自由、源码开放、高性能、分布式的分布式内存对象缓存...
    李伟铭MIng阅读 3,789评论 2 13
  • 更改ip和dnsVi /etc/sysconfig/network-scripts/ifcfg-eth0vi /...
    Xwei_阅读 1,804评论 0 3
  • 一、准备工作 1、安装编译工具gcc、gcc-c++、make注意解决依赖关系,推荐使用yum安装,若不能联网可使...
    提莫队长1234阅读 609评论 0 0
  • 啊 公司要开始新项目 移动的app 名字叫安好 运维太坑爹了 给了个破配置 Xeon(TM) CPU 3.40...
    xiasix阅读 1,462评论 0 2
  • (centos7+nginx1.9+mysql5.6+php7) 1.准备工作: 1)把所有的软件安装在/data...
    Tshare_XUN阅读 591评论 0 0