准备依赖包和函数库:
yum -yinstall gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetypefreetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-develcurl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-developenssl openssl-devel openldap openldap-devel nss_ldap openldap-clientsopenldap-servers patch perl-CPAN pcre-devel pcre libxslt libxslt-devel php-mcrypt libmcrypt libmcrypt-devel
下载:
http://php.net/downloads.php
解压:
tar -zxvf php-5.6.3.tar.gz
检查配置环境(通用于7.0):
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/php.d --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir=/usr/local --with-jpeg-dir --with-kerberos --with-ldap --with-ldap-sasl --with-libdir=lib64 --with-libxml-dir=/usr/lib64 --with-mcrypt --with-mhash --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --with-pcre-regex=/usr --with-pdo-mysql=mysqlnd --with-pdo-sqlite=shared --with-pear=/usr/local/lib/php --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip --disable-rpath --enable-opcache --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip --disable-rpath --enable-opcache --disable-debug --enable-shared --enable-ftp --enable-session --enable-fastcgi --disable-fileinfo --with-fpm-user=username --with-fpm-group=username
配置详解:
--with-mysql-sock=/var/run/mysql/mysql.sock //mysql的sock文件
--with-iconv-dir=/usr/local //iconv库文件,编译安装icon库时需要指定路径
--with-fpm-user=username--with-fpm-group=username //指定php-fpm的用户和组
configure: error:mcrypt.h not found.
报错内容:configure: error: mcrypt.h notfound. Please reinstall libmcrypt
yum install php-mcrypt libmcrypt libmcrypt-devel
编译安装:
ln-s /usr/local/lib/libiconv.so.2 /usr/lib64/
make ZEND_EXTRA_LIBS='-liconv'
报错:
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1
解释:
在安裝 PHP 到系统中时要是发生「undefined reference to libiconv_open'」之类的错误信息,那表示在「./configure 」沒抓好一些环境变数值。错误发生点在建立「-o sapi/cli/php」是出错,没給到要 link 的 iconv 函式库参数。
解决方法:
编辑Makefile 大约100 行左右的地方: EXTRA_LIBS = ..... -lcrypt 在最后加上 -liconv,例如: EXTRA_LIBS = ..... -lcrypt -liconv 然后重新再次 make 即可。
然后重新make 顺利通过了
编译安装php 的时候,执行make报错误
错误:make: *** [ext/mysqli/mysqli.lo] Error 1
[[email protected]]# mkdir /usr/local/webserver/mysql/include/mysql
[[email protected]]# ln -s /usr/local/webserver/mysql/include/*/usr/local/webserver/mysql/include/mysql
[root@localhost php-5.4.9]# make ZEND_EXTRA_LIBS='-liconv'
抛错:
Generating phar.phar
/usr/local/src/php-5.4.9/sapi/cli/php:error while loading shared libraries: libiconv.so.2: cannot open shared objectfile: No such file or directory
make: *** [ext/phar/phar.php] Error 127
解决的方法如下:
#vi /etc/ld.so.conf
在里面加上一行
/usr/local/lib
/usr/lib64
/usr/lib
2.然后运行/sbin/ldconfig
#/sbin/ldconfig
编译make
#makeZEND_EXTRA_LIBS='-liconv'
抛错:
Generating phar.phar
chmod: cannot access `ext/phar/phar.phar': No such file or directory
make: [ext/phar/phar.phar] Error 1 (ignored)
Build complete.
Don't forget to run 'make test'.
此处可以忽略不过解决办法如下
#cd ext/phar/
#cp ./phar.php ./phar.phar
然后到php5.4文件夹
#makeZEND_EXTRA_LIBS='-liconv'
#make test
#make install
make clean
make ZEND_EXTRA_LIBS='-liconv'
make install
准备配置文件:
cp php.ini-production/usr/local/webserver/php-d/php-5.5.0/etc/php.ini
剩下的根据个人配置 配置,php.ini中的模块设置和php-fpm中的进程池配置按照原先的配置配置。