实验
环境准备:
PHP: 192.168.42.103
nginx: 192.168.42.102
mysql: 192.168.42.181
环境初始化:
同步时间:
yum -y install ntp ntpdate
ntpdate cn.pool.ntp.org
hwclock --systohc
关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0
安装php,php-fpm
(1)下载并解压软件包
[root@localhost ~]# wget http://php.net/distributions/php-7.2.0.tar.gz
[root@localhost ~]# tar xf php-7.2.0.tar.gz -C /usr/local/src/
(2)安装依赖
[root@localhost ~]# yum install -y gcc zlib zlib-devel openssl openssl-devel perl perl-devel make
[root@localhost ~]# wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
[root@localhost ~]# yum -y install gd-devel libjpeg libjpeg-devel libpng libpng-devel libiconv-devel freetype freetype-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel libxslt-devel mhash
[root@localhost ~]# tar zxf libmcrypt-2.5.7.tar.gz
[root@localhost ~]# cd libmcrypt-2.5.7
[root@localhost libmcrypt-2.5.7]# ./configure
[root@localhost libmcrypt-2.5.7]# make && make install
[root@localhost libmcrypt-2.5.7]# echo $?
0
[root@localhost libmcrypt-2.5.7]# yum -y install gd-devel libjpeg libjpeg-devel libpng libpng-devel libiconv-devel freetype freetype-d
[root@localhost php-7.2.0]# rpm -e libcurl-7.29.0-42.el7.x86_64 --nodeps
[root@localhost php-7.2.0]# wget https://curl.haxx.se/download/curl-7.56.0.tar.gz
[root@localhost php-7.2.0]# mv curl-7.56.0.tar.gz /root
[root@localhost ~]# tar -zxvf curl-7.56.0.tar.gz
[root@localhost ~]# cd curl-7.56.0
[root@localhost curl-7.56.0]#./configure --prefix=/usr/local/curl --with-ssl --with-zlib
[root@localhost curl-7.56.0]# make && make install
(3)编译安装php
[root@localhost libmcrypt-2.5.7]# cd /usr/local/src/php-7.2.0/
[root@localhost php-7.2.0]# ./configure --prefix=/usr/local/php7 \
--with-config-file-path=/usr/local/php7/etc \
--with-curl=/usr/local/curl \
--disable-ipv6 \
--with-pdo-mysql \
--with-openssl \
--with-openssl-dir \
--with-pcre-regex \
--with-kerberos \
--with-libdir=lib \
--with-libxml-dir \
--with-mysqli=shared,mysqlnd \
--with-pdo-mysql=shared,mysqlnd \
--with-pdo-sqlite \
--with-gd \
--with-iconv \
--with-zlib \
--with-xmlrpc \
--with-xsl \
--with-pear \
--with-gettext \
--with-png-dir \
--with-jpeg-dir \
--with-freetype-dir \
--with-mcrypt \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-pdo \
--enable-mysqlnd \
--enable-zip \
--enable-inline-optimization \
--enable-shared \
--enable-libxml \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-ftp \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--enable-soap \
--enable-session \
--enable-opcache \
--enable-fpm \
--enable-maintainer-zts \
--enable-fileinfo \
--enable-gd-jis-conv \
--with-zlib-dir
[root@localhost php-7.2.0]# echo $?
0
[root@localhost php-7.2.0]# make install
[root@localhost php-7.2.0]# echo $?
0
(4)配置PHP启动
[root@localhost fpm]# cp -p init.d.php-fpm /etc/init.d/php-fpm
[root@localhost fpm]# cd /etc/init.d/
functions netconsole network php-fpm README
[root@localhost init.d]# chmod +x php-fpm
[root@localhost init.d]# chkconfig php-fpm on
[root@localhost init.d]# vim /etc/profile
export PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH
[root@localhost init.d]# php -v
[root@localhost init.d]# service php-fpm start
(5)配置php
[root@localhost local]# cd src/php-7.2.0/
[root@localhost php-7.2.0]# ls
acinclude.m4 ext Makefile.frag README.EXT_SKEL run-tests.php
aclocal.m4 EXTENSIONS Makefile.fragments README.GIT-RULES sapi
appveyor footer Makefile.gcov README.input_filter scripts
build generated_lists Makefile.global README.MAILINGLIST_RULES server-tests-config.php
buildconf genfiles Makefile.objects README.md server-tests.php
buildconf.bat header meta_ccld README.NEW-OUTPUT-API snapshot
CODING_STANDARDS include missing README.PARAMETER_PARSING_API stamp-h.in
config.guess INSTALL mkinstalldirs README.REDIST.BINS tests
config.log install-sh modules README.RELEASE_PROCESS travis
config.nice libs NEWS README.SELF-CONTAINED-EXTENSIONS TSRM
config.status libtool pear README.STREAMS UPGRADING
config.sub LICENSE php7.spec README.SUBMITTING_PATCH UPGRADING.INTERNALS
configure ltmain.sh php7.spec.in README.TESTING vcsclean
configure.ac main php.gif README.TESTING2 win32
CONTRIBUTING.md makedist php.ini-development README.UNIX-BUILD-SYSTEM Zend
CREDITS Makefile php.ini-production README.WIN32-BUILD-SYSTEM
[root@localhost php-7.2.0]# cp php.ini-production /usr/local/php7/etc/php-fpm
[root@localhost etc]# cp -p php-fpm.conf.default php-fpm.conf
[root@localhost etc]# cd php-fpm.d/
[root@localhost php-fpm.d]# cp -p www.conf.default www.conf
[root@localhost php-fpm.d]# cat /usr/local/php/etc/php-fpm.d/www.conf |grep -iv "^\;"
[www]
user = nobody
group = nobody
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
[root@localhost php-fpm.d]#
[root@localhost php-fpm.d]# useradd nginx
[root@localhost php-fpm.d]# vim /usr/local/php7/et7
[www]
user = nginx
group = nginx
listen = 0.0.0.0:9000
listen.owner = nginx
listen.group = nginx
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 10
[root@localhost php-fpm.d]# cat /usr/local/php7/etc/php-fpm.d/www.conf |grep -ivu
[www]
user = nginx
group = nginx
listen = 0.0.0.0:9000
listen.owner = nginx
listen.group = nginx
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 10
(6)测试
[root@localhost www]# vim index.php
[root@localhost www]# vim mysql.php
(7)安装PHP-mysql链接模块
[root@localhost www]# cd /usr/local/src/php-7.2.0/
[root@localhost php-7.2.0]# cd ext/
[root@localhost ext]# cd mysqli/
[root@localhost mysqli]# /usr/local/php7/bin/phpize
[root@localhost mysqli]# ./configure \
> --with-php-config=/usr/local/php7/bin/php-config \
> --enable-embedded-mysqli=shared \
> --enable-shared
[root@localhost mysqli]# echo $?
0
[root@localhost mysqli]# make
[root@localhost mysqli]# make install
[root@localhost mysqli]# echo $?
[root@localhost mysqli]# cd /usr/local/php7/lib/php/extensions/no-debug-zts-20170718
[root@localhost no-debug-zts-20170718]# ls
mysqli.a mysqli.so opcache.a opcache.so pdo_mysql.a pdo_mysql.so
[root@localhost php]# cd /usr/local/src/php-7.2.0/ext/pdo
[root@localhost php]# cd /usr/local/src/php-7.2.0/ext/pdo_mysql/
[root@localhost pdo_mysql]# /usr/local/php7/bin/phpize
Configuring for:
PHP Api Version: 20170718
Zend Module Api No: 20170718
Zend Extension Api No: 320170718
[root@localhost pdo_mysql]# ./configure \
> --with-php-config=/usr/local/php7/bin/php-config \
> --with-pdo-mysql=mysqlnd
[root@localhost pdo_mysql]# echo $?
0
[root@localhost pdo_mysql]# make
[root@localhost pdo_mysql]# echo $?
0
[root@localhost pdo_mysql]# make install
(8)添加模块:
[root@localhost php-7.2.0]# cp php.ini-production /usr/local/php7/etc/php.ini
[root@localhost php-7.2.0]# cd /usr/local/php7/etc/
[root@localhost etc]# vim php.ini
extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-zts-20170718"
extension = mysqli.so
extension = pdo_mysql.so
[root@localhost etc]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@localhost etc]# ps -ef |grep php
root 94481 1 0 12:00 ? 00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nginx 94482 94481 0 12:00 ? 00:00:00 php-fpm: pool www
nginx 94483 94481 0 12:00 ? 00:00:00 php-fpm: pool www
nginx 94484 94481 0 12:00 ? 00:00:00 php-fpm: pool www
nginx 94485 94481 0 12:00 ? 00:00:00 php-fpm: pool www
nginx 94486 94481 0 12:00 ? 00:00:00 php-fpm: pool www
root 94495 1506 0 12:00 pts/0 00:00:00 grep --color=auto php