1、从官网下载php源码包 (php-5.5.38)
2、安装依赖包
yum install libxml2 libxml2-devel bzip2-devel libcurl-devel -y
yum install openssl openssl-devel -y
yum install libjpeg-devel libpng-devel freetype-devel -y
yum install libmcrypt libmcrypt-devel -y
3、编译安装
$ tar -xzvf php-5.5.38.tar.gz
$ cd php-5.5.38
$ ./configure --prefix=/usr/local/php ...
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-opcache \
--enable-fpm \
--with-mysql \
--with-mysqli \
--with-pdo-mysql \
--with-gettext \
--enable-mbstring \
--with-iconv \
--with-mcrypt \
--with-mhash \
--with-openssl \
--enable-bcmath \
--enable-soap \
--with-libxml-dir \
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-sockets \
--with-curl \
--with-zlib \
--enable-zip \
--with-bz2 \
--with-gd \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir
make && make install
安装成功的打印信息:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/
Installing PHP CLI binary: /usr/local/php/bin/
Installing PHP CLI man page: /usr/local/php/php/man/man1/
Installing PHP FPM binary: /usr/local/php/sbin/
Installing PHP FPM config: /usr/local/php/etc/
Installing PHP FPM man page: /usr/local/php/php/man/man8/
Installing PHP FPM status page: /usr/local/php/php/php/fpm/
Installing PHP CGI binary: /usr/local/php/bin/
Installing PHP CGI man page: /usr/local/php/php/man/man1/
Installing build environment: /usr/local/php/lib/php/build/
Installing header files: /usr/local/php/include/php/
Installing helper programs: /usr/local/php/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/php/lib/php/
[PEAR] Archive_Tar - installed: 1.4.0
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util - installed: 1.3.0
[PEAR] PEAR - installed: 1.10.1
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/opt/software/php-5.5.38/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers: /usr/local/php/include/php/ext/pdo/
安装成功之后进入/usr/local/php/bin目录查看php版本
[root@docker bin]# ./php -v
PHP 5.5.38 (cli) (built: Feb 28 2017 20:24:05)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
4、移动配置文件
$ cp php.ini-production /usr/local/php/etc/php.ini //将源码文件中的php.ini-production移动到php配置文件夹下作为php的配置文件
$ cp /usr/local/php/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
5、将php-fpm配置为系统服务,并设置为开机启动
$ cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm //php源码目录下
$ chmod +x /etc/init.d/php-fpm
$ chkconfig --add php-fpm
$ chkconfig php-fpm on
$ service php-fpm start
[root@client fpm]# service php-fpm start
Starting php-fpm done
[root@client fpm]# ps -ef |grep php
root 4586 1 0 10:32 ? 00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nobody 4587 4586 0 10:32 ? 00:00:00 php-fpm: pool www
nobody 4588 4586 0 10:32 ? 00:00:00 php-fpm: pool www
root 4590 2526 0 10:32 pts/0 00:00:00 grep --color=auto php
[root@client fpm]# netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 192.168.56.202:22 192.168.56.1:55794 ESTABLISHED
tcp 0 52 192.168.56.202:22 192.168.56.1:55757 ESTABLISHED
tcp6 0 0 :::22 :::* LISTEN