Centos7.2编译安装PHP-7.0.13
1- 安装依赖
yum install wget autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap libXpm* gcc gcc-c++ bison git -y
2- 安装libiconv
#加强系统对支持字符编码转换的功能
cd /usr/local/src
wget http://ftp.gnu.org/gnu/libiconv/libiconv-1.14.tar.gz
tar zvxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure
cd srclib
sed -i -e '/gets is a security/d' ./stdio.in.h
cd ..
make && make install
ln -sf /usr/local/lib/libiconv.so.2 /usr/lib64/
ldconfig
3- 安装libmcrypt (包含libltdl)
#加密算法库,PHP扩展mcrypt功能对此库有依赖关系
cd /usr/local/src
wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar zvxf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure && make && make install
cd libltdl/
./configure --enable-ltdl-install
make && make install
ln -sf /usr/local/lib/libmcrypt.* /usr/lib64/
ln -sf /usr/local/bin/libmcrypt-config /usr/lib64/
ldconfig
4- 安装mhash (hash加密算法库)
#mcrypt的编译依赖mhash
cd /usr/local/src/
wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
tar zvxf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure && make && make install
ln -sf /usr/local/lib/libmhash.* /usr/lib64/
ldconfig
5- 安装mcrypt (依赖libmcrypt和mhash)
cd /usr/local/src/
wget http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
tar zvxf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure && make && make install
6- 安装re2c
cd /usr/local/src/
wget http://sourceforge.net/projects/re2c/files/0.16/re2c-0.16.tar.gz
tar zvxf re2c-0.16.tar.gz
cd re2c-0.16
./configure && make && make install
7- 安装PHP
7-1 创建ldap软连接
ln -s /usr/lib64/libldap* /usr/lib
ln -s /usr/lib64/liblber* /usr/lib
ldconfig
7-2 编译
cd /usr/local/src/ wget http://am1.PHP.net/distributions/PHP-7.0.13.tar.gz tar zvxf PHP-7.0.13.tar.gz cd PHP-7.0.13 ./configure \ --prefix=/usr/local/PHP7 \ --with-config-file-path=/usr/local/PHP7/etc \ --with-openssl \ --with-MysqLi=shared,MysqLnd \ --with-pdo-MysqL=shared,MysqLnd \ --with-iconv-dir=/usr/local \ --with-libxml-dir=/usr \ --with-freetype-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib \ --with-curl \ --with-mhash \ --with-ldap \ --with-ldap-sasl \ --with-mcrypt \ --with-gd \ --with-xmlrpc \ --with-libdir=/lib/ \ --with-kerberos \ --with-pcre-regex \ --with-zlib-dir \ --with-bz2 \ --with-gettext \ --disable-rpath \ --enable-pdo \ --enable-xml \ --enable-bcmath \ --enable-shmop \ --enable-sysvsem \ --enable-inline-optimization \ --enable-mbregex \ --enable-fpm \ --enable-mbstring \ --enable-gd-native-ttf \ --enable-pcntl \ --enable-sockets \ --enable-zip \ --enable-soap \ --enable-opcache \ --enable-calendar \ --enable-ctype \ --enable-exif \ --enable-session \ --enable-ftp make ZEND_EXTRA_LIBS='-liconv' make install
7-3 复制配置文件
cp PHP.ini-production /usr/local/PHP7/etc/PHP.ini
7-4 开启系统HugePages
sysctl vm.nr_hugepages=512 cat /proc/meminfo | grep Huge
7-5 修改PHP配置文件,支持ZendOpcache
ll /usr/local/PHP7/lib/PHP/extensions/no-debug-non-zts-20151012 vim /usr/local/PHP7/etc/PHP.ini
在文件中搜索; extension_dir = “./”,并在下面添加以下内容(如果extension_dir已存在,只添加后面的内容)
extension_dir = "/usr/local/PHP7/lib/PHP/extensions/no-debug-non-zts-20151012/" zend_extension="opcache.so" opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=4000 opcache.revalidate_freq=60 opcache.fast_shutdown=1 opcache.enable=1 opcache.enable_cli=1 opcache.huge_code_pages=1 opcache.file_cache=/tmp
:wq 保存退出
7-6 修改PHP配置文件,支持pdo_MysqL,MysqLi
vim /usr/local/PHP7/etc/PHP.ini
在文件中搜索; extension_dir = “./”,并在下面添加以下内容(如果extension_dir已存在,只添加后面的一行)
extension_dir = "/usr/local/PHP7/lib/PHP/extensions/no-debug-non-zts-20151012/" extension = "pdo_MysqL.so" extension = "MysqLi.so"
:wq 保存退出
7-7 安装xdebug扩展(调试PHP用,不需要时可忽略)
cd /usr/local/src/
wget http://xdebug.org/files/xdebug-2.4.0rc3.tgz
tar zvxf xdebug-2.4.0rc3.tgz
cd xdebug-2.4.0RC3
/usr/local/PHP7/bin/PHPize
./configure --enable-xdebug --with-PHP-config=/usr/local/PHP7/bin/PHP-config
make && make install
vim /usr/local/PHP7/etc/PHP.ini
在文件中搜索; extension_dir = “./”,并在下面添加以下内容(如果extension_dir已存在,只添加后面的一行)
extension_dir = "/usr/local/PHP7/lib/PHP/extensions/no-debug-non-zts-20151012/" [xdebug] zend_extension = "xdebug.so" xdebug.remote_enable=1 xdebug.remote_connect_back=on xdebug.remote_port=8080 xdebug.idekey=PHPSTORM xdebug.remote_autostart=1
:wq 保存退出
7-8 安装memcahced扩展 (需要 libmemcached 库)
cd /usr/local/src wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz tar zvxf libmemcached-1.0.18.tar.gz cd libmemcached-1.0.18 ./configure --with-memcached --prefix=/opt/libmemcached make && make install cd /usr/local/src yum install git git clone https://github.com/rlerdorf/PHP-memcached.git cd PHP-memcached git checkout PHP7 /usr/local/PHP7/bin/PHPize ./configure --with-PHP-config=/usr/local/PHP7/bin/PHP-config --with-libmemcached-dir=/opt/libmemcached make && make install ll /usr/local/PHP7/lib/PHP/extensions/no-debug-non-zts-20151012/
vim /usr/local/PHP7/etc/PHP.ini
在文件中搜索; extension_dir = “./”,并在下面添加以下内容(如果extension_dir已存在,只添加后面的一行)
extension_dir = "/usr/local/PHP7/lib/PHP/extensions/no-debug-non-zts-20151012/" extension = "memcached.so"
7-9 安装redis扩展
cd /usr/local/src yum install git git clone https://github.com/PHPredis/PHPredis/ cd PHPredis git checkout PHP7 /usr/local/PHP7/bin/PHPize ./configure --with-PHP-config=/usr/local/PHP7/bin/PHP-config make && make install ll /usr/local/PHP7/lib/PHP/extensions/no-debug-non-zts-20151012/
vim /usr/local/PHP7/etc/PHP.ini在文件中搜索; extension_dir = “./”,并在下面添加以下内容(如果extension_dir已存在,只添加后面的一行)
extension_dir = "/usr/local/PHP7/lib/PHP/extensions/no-debug-non-zts-20151012/" extension = "redis.so"
7-10 安装PHP-fpm
cp /usr/local/PHP7/etc/PHP-fpm.conf.default /usr/local/PHP7/etc/PHP-fpm.conf cp /usr/local/PHP7/etc/PHP-fpm.d/www.conf.default /usr/local/PHP7/etc/PHP-fpm.d/web.conf vim /usr/local/PHP7/etc/PHP-fpm.conf
[global] pid = run/PHP-fpm.pid error_log = log/PHP-fpm.log emergency_restart_threshold = 10 emergency_restart_interval = 1m process_control_timeout = 5s
:wq 保存退出
vim /usr/local/PHP7/etc/PHP-fpm.d/web.conf
修改内容,并且让其它生效.[user和group根据实际情况修改]
user = nobody group = nobody pm.max_children = 35 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35
:wq 保存退出
7-11 设置PHP-fpm自动启动
cd /usr/local/src/PHP-7.0.13 cp sapi/fpm/init.d.PHP-fpm /etc/init.d/PHP-fpm chmod +x /etc/init.d/PHP-fpm chkconfig --add PHP-fpm chkconfig PHP-fpm on
7-12 启动PHP-fpm
systemctl start PHP-fpm
参考资料: @H_404_399@ [1].http://www.cnblogs.com/vicowong/p/5024792.html @H_404_399@ [2].http://www.phpddt.com/php/php-fpm-reload.html