编译php7
I. 准备
PHP的安装最头疼的就是因为某些类库没有安装而报错,所以编译前请确保以下包已安装
yum groupinstall "development tools"
yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses curl curl-devel openssl-devel gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel
安装mcrypt
yum install -y php-mcrypt libmcrypt libmcrypt-devel
由于版本问题,centos不能集成mcrypt,自行安装解决错误
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar xvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure --prefix=/usr/local
make
make install
升级bison
cd /var/soft/
wget http://ftp.gnu.org/gnu/bison/bison-2.6.4.tar.gz
tar -xvzf bison-2.6.4.tar.gz
cd bison-2.6.4
./configure
make && make install
升级re2c,解决You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.错误
cd /var/soft/
wget http://sourceforge.net/projects/re2c/files/re2c/0.13.5/re2c-0.13.5.tar.gz/download
tar zxf re2c-0.13.5.tar.gz && cd re2c-0.13.5
./configure
make && make install
编译PHP7
# 创建目录
mkdir -p /var/soft/php7
cd /var/soft/php7
# 下载源代码
git clone http://git.php.net/repository/php-src.git
cd php-src
./buildconf
# 或
wget http://us1.php.net/distributions/php-7.0.0.tar.gz
tar xvf php-7.0.0.tar.gz
cd php-7.0.0
配置参数
./configure --prefix=/usr/local/php7 \
--with-config-file-path=/usr/local/php7/etc \
--with-mcrypt=/usr/include \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-gd \
--with-iconv \
--with-zlib \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--with-openssl \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--with-jpeg-dir \
--with-freetype-dir \
--enable-opcache
# 编译安装php时出现 /encodings.c:101: undefined reference to `libiconv_close’ 错误的解决方法
# 在装php时出现以下的错误:
# /root/Downloads/php-5.6.5/ext/xmlrpc/libxmlrpc/encodings.c:73: undefined reference to `libiconv_open'
# /root/Downloads/php-5.6.5/ext/xmlrpc/libxmlrpc/encodings.c:81: undefined reference to `libiconv'
# /root/Downloads/php-5.6.5/ext/xmlrpc/libxmlrpc/encodings.c:101: undefined reference to `libiconv_close'
# /root/Downloads/php-5.6.5/ext/xmlrpc/libxmlrpc/encodings.c:101: undefined reference to `libiconv_close'
# collect2: error: ld returned 1 exit status
# make: *** [sapi/cli/php] Error 1
# 根据php官网描述这是一个bug(https://bugs.php.net/bug.php?id=52611)。在configure以后要手动修改下Makefile文件,找到EXTRA_LIBS 在最后添加 -liconv 即可顺利通过
# (大约在Makefile文件的104)
# EXTRA_LIBS = -lcrypt -lz -lresolv -lcrypt -lrt -lmysqlclient -lmcrypt -lltdl -lpng -lz -ljpeg -lcurl -lz -lrt -lm -ldl -lnsl -lxml2 -lz -lm -ldl -lssl -lcrypto -lcurl -lxml2 -lz -lm -ldl -lfreetype -lmysqlclient -lz -lm -lssl -lcrypto -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lcrypt -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lssl -lcrypto -lcrypt -liconv
编译安装
make && sudo make install
配置
cp php.ini-production /usr/local/php7/etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php7-fpm
chmod +x /etc/init.d/php7-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/www.conf
配置opcache
vim /usr/local/php7/etc/php.ini
加入
zend_extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/opcache.so
启动
/etc/init.d/php7-fpm start
查看PHP版本
/usr/local/php7/bin/php -v
结果:
[root@localhost ~]# /usr/local/php7/bin/php -v
PHP 7.1.0-dev (cli) (built: Mar 8 2016 05:28:01) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/
Installing PHP CLI binary: /usr/local/php7/bin/
Installing PHP CLI man page: /usr/local/php7/php/man/man1/
Installing PHP FPM binary: /usr/local/php7/sbin/
Installing PHP FPM config: /usr/local/php7/etc/
Installing PHP FPM man page: /usr/local/php7/php/man/man8/
Installing PHP FPM status page: /usr/local/php7/php/php/fpm/
Installing phpdbg binary: /usr/local/php7/bin/
Installing phpdbg man page: /usr/local/php7/php/man/man1/
Installing PHP CGI binary: /usr/local/php7/bin/
Installing PHP CGI man page: /usr/local/php7/php/man/man1/
Installing build environment: /usr/local/php7/lib/php/build/
Installing header files: /usr/local/php7/include/php/
Installing helper programs: /usr/local/php7/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php7/php/man/man1/
page: phpize.1
page: php-config.1
/var/soft/php7/php-src/build/shtool install -c ext/phar/phar.phar /usr/local/php7/bin
ln -s -f phar.phar /usr/local/php7/bin/phar
Installing PDO headers: /usr/local/php7/include/php/ext/pdo/
[root@localhost php-src]#
https://xiaoai.me/?p=45
https://segmentfault.com/a/1190000004065931
https://typecodes.com/web/centos7compilephp7.html
https://typecodes.com/web/centos7compilenginx.html
http://blog.csdn.net/shaerdong/article/details/50212969
https://www.hdj.me/php7-install-note
http://blog.sina.com.cn/s/blog_6c971aa30102vnwy.html
安装mcrypt的时候提示libmcrypt was not found
如提示,修改LD_LIBRARY_PATH就可以了
>export LD_LIBRARY_PATH=/usr/local/lib:LD_LIBRARY_PATH
>./configure –with-libmcrypt-prefix=/usr/local
>make && make install
安装成功。
解决configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
今天给php编译安装Fileinfo的时候,报configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.看了下说是要re2c这个东西.
解决办法:
wget http://sourceforge.net/projects/re2c/files/re2c/0.13.5/re2c-0.13.5.tar.gz/download
tar zxf re2c-0.13.5.tar.gz && cd re2c-0.13.5
./configure
make && make install
然后再去编译安装Fileinfo,就不会报re2c的错误了.
configure: error: *** libmcrypt was not found
为了的到mcrypt.so库文件,先后安装编译了mhash和libmcrypt,但是到最后编译mcrypt时报错:
configure: error: *** libmcrypt was not found
最后发现是因为环境变量的问题,gcc编译的时候根据自身定义的变量寻找相关函数库等文件,libmcrypt也是刚安装的,在变量中没有定义出来,所以手动添加:
[root@localhost modules]# export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
再次编译即可。
http://blog.csdn.net/love__coder/article/details/7721951
编译mcrypt时,报错:You need at least libmhash 0.8.15
执行 ./configure 编译源码,报错如下:
checking whether mhash >= 0.8.15... no
configure: error: "You need at least libmhash 0.8.15 to compile this program. http://mhash.sf.net/"
奇怪,libmhash安装的是 mhash-0.9.9.9.tar.gz ,怎么会报这样的错误呢,难道是没找到?
[plain] view plain copy
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
一通上面的操作之后,还是不行。
打开/etc/ld.so.conf,在文件之后,添加一行:
[html] view plain copy
/usr/local/lib
然后,执行 ldconfig ,重新编译即可。
编译mcrypt 报错"You need at least libmhash 0.8.15 to compile this program"
这是由于在安装 mhash 使用了 --prefix= 此参数 导致系统无法超找到某些文件
可设置变量解决
export LD_LIBRARY_PATH="/usr/local/src/mhash/lib/"
export LDFLAGS="-L/usr/local/src/mhash/lib/ -I/usr/local/src/mhash/include/"
export CFLAGS="-I/usr/local/src/mhash/include/"
注意是 大写的I 不是小写的l
相关PHP7中php.ini、php-fpm和www.conf的配置
Nginx 1.5.2 + PHP 5.5.1 + MySQL 5.6.10 在 CentOS 下的编译安装