存档在 ‘【技术】’ 分类

怎样安装bzip

2018年2月13日

参考:https://www.linuxquestions.org/questions/linux-newbie-8/cannot-enable-pcregrep-libbz2-because-bzlib-h-was-not-found-4175442278/
参考:https://www.linuxquestions.org/questions/linux-newbie-8/install-libbz2-4175444507/
参考:http://www.aichengxu.com/other/5934079.htm

yum install bzip2-devel

报错:expat.h: No such file or directory

2018年2月13日

参考:http://blog.csdn.net/tuenbotuenbo/article/details/38387999

安装apr-util时找不到expat.h。

yum install expat-devel

怎样编译安装PHP5.6.*

2018年1月27日

参考:http://amon.org/php72

通过源码包编译安装:

下载:http://php.net/downloads.php
最新版本:php-5.6.38

wget http://php.net/distributions/php-5.6.38.tar.xz && tar -xvf php-5.6.38.tar.xz && cd php-5.6.38

开始configure配置:

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=apache --with-fpm-group=apache --disable-debug --with-curl --with-iconv --with-pcre-regex --with-zlib --enable-bcmath --enable-ftp --enable-sockets --enable-mbstring --enable-mbregex --enable-soap --with-xsl --with-openssl --enable-opcache=no --with-mysqli --with-mysql-sock --with-pdo-mysql --enable-mysqlnd --disable-fileinfo --with-gd=/usr/local/gd --enable-gd-jis-conv --with-jpeg-dir=/usr/local/jpeg/lib --with-png-dir=/usr/local/png --with-freetype-dir=/usr/local/freetype --with-libzip=/usr/local/lib64 --enable-zip --with-iconv-dir=/usr/local/lib --with-readline --with-apxs2=/usr/local/apache2/bin/apxs LDFLAGS="-L/usr/lib -lz"

备用:

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-opcache=no --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql --with-mysqli --with-mysql-sock --with-pdo-mysql --enable-mysqlnd --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-kerberos --enable-calendar --enable-exif --with-gmp --enable-intl --with-ldap --with-libmbfl --with-xmlrpc --enable-maintainer-zts --enable-zend-signals --with-openssl --with-xsl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl=/usr/lib64 --with-bz2 --with-gd --with-gd=/usr/local/gd --enable-gd-jis-conv --enable-gd-native-ttf --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-freetype-dir=/usr/local/freetype --with-zlib --with-pcre-dir --enable-zip --with-readline --with-apxs2=/usr/local/apache2/bin/apxs

如果configure时报错:Cannot find ldap libraries

configure: error: Cannot find ldap libraries in /usr/lib

参考:http://www.111cn.net/sys/linux/44746.htm

提示在/usr/lib 下找不到相关模块,这是因为64位的linux默认把以上文件都存在 /usr/lib64 文件夹下。

cp -frp /usr/lib64/libldap* /usr/lib/

如果configure时报错:off_t undefined

checking size of off_t… 0
configure: error: off_t undefined; check your library configuration

参考:https://stackoverflow.com/questions/44941513/php-compile-off-t-undefined
参考:https://stackoverflow.com/questions/44941513/php-compile-off-t-undefined
参考:http://ju.outofmemory.cn/entry/319609

echo '/usr/local/lib64 /usr/local/lib /usr/lib /usr/lib64'>>/etc/ld.so.conf && ldconfig
ln -s -f /usr/include/zipconf.h /usr/local/include/zipconf.h

然后开始 make:

make ZEND_EXTRA_LIBS='-liconv'

如果make时报错:undefined reference to symbol ‘ber_scanf’

/usr/bin/ld: ext/ldap/.libs/ldap.o: undefined reference to symbol 'ber_scanf'
/usr/bin/ld: note: 'ber_scanf' is defined in DSO /lib64/liblber-2.4.so.2 so try adding it to the linker command line
/lib64/liblber-2.4.so.2: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1

参考:http://www.oschina.net/question/56833_128548?sort=time

编辑MakeFile,找到 110行 开头是 ‘EXTRA_LIBS’ 这一行 在结尾加上 ‘-llber’ :

EXTRA_LIBS = -lcrypt -lcrypto -lssl -lcrypto -lzip -lz -lexslt -lcrypt -lreadline -lncurses -lrt -lmcrypt -lltdl -lldap -lstdc++ -lgmp -lgd -lpng -lz -ljpeg -lpng -lz -ljpeg -lcurl -lbz2 -lz -lcrypto -lssl -lcrypto -lrt -lm -ldl -lnsl -lxml2 -lz -lm -ldl -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lcurl -lxml2 -lz -lm -ldl -lfreetype -lfreetype -ldl -lm -licui18n -licuuc -licudata -ldl -lm -licuio -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 -lxslt -lxml2 -lz -ldl -lm -lcrypt -llber

重新make(注意不能make clean,因为这样的话MakeFile会还原):

make ZEND_EXTRA_LIBS='-liconv'

输出:

...
Build complete.
Don't forget to run 'make test'

执行命令:

make test

有时候进程会卡死,止步于:

...
PASS Bug #66830 (Empty header causes PHP built-in web server to hang) [sapi/cli/tests/bug66830.phpt]

那就绕开此步,关闭进程后,重启进程直接“make install”。

执行命令:

make install

输出:

...
libtool: install: install .libs/libphp7.so /usr/local/apache2/modules/libphp7.so
...
Installing PEAR environment:      /usr/local/php/lib/php/
...
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
/root/php/php-5.6.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/

运行:

libtool --finish /root/php/php-5.6.38/libs

添加/usr/local/php/lib/php to your php.ini include_path:

/root/php/php-5.6.38/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar

创建软连接:

ln -s /usr/local/php/bin/php /usr/local/bin/
ln -s /usr/local/php/bin/phpize /usr/local/bin/
ln -s /usr/local/php/bin/php-config /usr/local/bin/

查看版本:

php -v

输出:

PHP 5.6.38 (cli) (built: Oct 28 2016 03:13:49)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies

重启Apache:

service httpd stop && service httpd start

报错:

/etc/init.d/httpd: line 81:  3668 Segmentation fault      $HTTPD -k $ARGV

原因在于Apache配置文件中模块libphp5.so还在加载中,但是5已经被删除了,新安装了7,所以需要将libphp5.so这一行注释掉,只加载libphp7.so。

打开httpd.conf文件:

/usr/local/apache2/conf/httpd.conf

将libphp5.so这一行注释掉:

#LoadModule php5_module modules/libphp5.so
LoadModule php7_module modules/libphp7.so

重启Apache:

service httpd start

Apache正常启动。

常见报错备注

备注1:

通过源码编译安装zlib跟libzip后,必须在configure中指定以下两个参数的路径:

--with-zlib-dir=DIR
--with-libzip=DIR

否则会出现报错。

备注2:–with-mysql

中间只报告了一个mysql无法扩展无法安装。

因为PHP7已经移除mysql了,现在主要使用mysqli和pdo连接mysql。

在configure 命令中 删除 –with-mysql 这一项即可。

备注2:–enable-opcache=no

使用大于php5.4版本的时候–enable-opcache可能会在./configure阶段就报错:

configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no

这句话的意思是让你关闭opcache,但是既然要使用新版本为何不开启opcache?执行下面这2句:

echo "/usr/local/lib">> /etc/ld.so.conf
ldconfig -v

以上操作是更新动态库,只有这样设置之后才能安装opcache选项。

常见报错:#error unsupported size of off_t

在make的时候又出现了编译错误:

In file included from /home/data/php-5.6.38/ext/zip/lib/zip_add.c:36:0:
/home/data/php-5.6.38/ext/zip/lib/zipint.h:126:2: error: #error unsupported size of off_t
 #error unsupported size of off_t
  ^
make: *** [ext/zip/lib/zip_add.lo] Error 1

https://bugs.php.net/bug.php?id=68302找到了答案:

执行命令:

export CFLAGS="-L/opt/xml2/lib"

然后清除上一次编译的错误:

make clean

重新执行configure命令编译。

怎样编译安装libtiff

2017年12月21日

【介绍】

参考:http://www.linuxfromscratch.org/blfs/view/svn/general/libtiff.html

【编译】

最高版本:tiff-4.0.9

wget http://download.osgeo.org/libtiff/tiff-4.0.9.tar.gz && tar -zxvf tiff-4.0.9.tar.gz && cd tiff-4.0.9
./configure --prefix=/usr
make && make check && make install

输出:

----------------------------------------------------------------------
Libraries have been installed in:
   /usr/lib
...
----------------------------------------------------------------------
 /usr/bin/mkdir -p '/usr/include'
 /usr/bin/install -c -m 644 tiff.h tiffio.h tiffvers.h tiffio.hxx '/usr/include'
 /usr/bin/mkdir -p '/usr/include'
 /usr/bin/install -c -m 644 tiffconf.h '/usr/include'
...

怎样编译安装PHP7.2.*

2017年12月20日

参考:https://github.com/gitKearney/php7-from-scratch

【依赖】

安装次序:1. aspell/pspell > 2. Libmcrypt > 3. mhash > 4. mcrypt

编译安装aspell/pspell

PHP5可以跳过这个文件,直接把configure命令中的 –with-pspell 参数去掉即可。

这两个扩展会识别单词的拼法是否正确并给出意见。

如果需要在编译PHP时添加pspell支持,必须安装aspell库。

编译php时加上 ./configure –with-pspell=/usr 如果是phpize 编译 –with-pspell=/usr

编译安装Libmcrypt:

参考:http://amon.org/mcrypt

编译安装GD库及依赖包

安装次序:1. zlib > 2. libpng > 3. freetype > 4. jpeg > 5. libxpm > 6. libgd

编译安装zlib:

参考:http://amon.org/zlib

编译安装libpng:

参考:http://amon.org/libpng

编译安装freetype

参考:http://amon.org/freetype

编译安装jpeg

参考:http://amon.org/jpeg

编译安装libxpm:

yum install libXpm libXpm-devel

编译安装libgd:

参考:http://amon.org/libgd

4. 安装PHP

第一步. 安装一些依赖包

yum install gmp gmp-devel

2. 安装 libc-client

yum install libc-client libc-client-devel

创建软连接:

ln -s /usr/lib64/libc-client.so /usr/lib/libc-client.so
ln -s /usr/lib64/libldap* /usr/lib/

必须创建软连接,不然在编译PHP的时候,会报错找不到文件。

3. 安装 libicu

参考:http://amon.org/icu

如果没有安装libicu的话,在编译PHP的时候,会报错:

configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.

4. 安装libzip

参考:http://amon.org/libzip

5. 安装 liconv

参考:http://amon.org/libiconv

如果没安装,会在编译时报错:

/usr/bin/ld: cannot find -liconv
collect2: error: ld returned 1 exit status
make: *** [libphp7.la] Error 1

【编译php】

参考:http://amon.org/php5217

下载:http://php.net/downloads.php

wget http://php.net/distributions/php-7.2.10.tar.xz && tar -xvf php-7.2.10.tar.xz && cd php-7.2.10

开始configure配置:

参考:http://blog.csdn.net/m0_37886429/article/details/72520632

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=apache --with-fpm-group=apache --disable-debug --with-curl --with-iconv --with-pcre-regex --with-zlib --enable-bcmath --enable-ftp --enable-sockets --enable-mbstring --enable-mbregex --enable-soap --with-xsl --with-openssl --enable-opcache=no --with-mysqli --with-mysql-sock --with-pdo-mysql --enable-mysqlnd --disable-fileinfo --with-gd=/usr/local/gd --enable-gd-jis-conv --with-jpeg-dir=/usr/local/jpeg/lib --with-png-dir=/usr/local/png --with-freetype-dir=/usr/local/freetype --with-libzip=/usr/local/lib64 --enable-zip --with-iconv-dir=/usr/local/lib --with-readline --with-apxs2=/usr/local/apache2/bin/apxs LDFLAGS="-L/usr/lib -lz"

然后开始 make:

make ZEND_EXTRA_LIBS='-liconv'

如果make 时报错:undefined reference to symbol ‘ber_scanf’

参考:http://www.oschina.net/question/56833_128548?sort=time

/usr/bin/ld: ext/ldap/.libs/ldap.o: undefined reference to symbol 'ber_scanf'
/usr/bin/ld: note: 'ber_scanf' is defined in DSO /lib64/liblber-2.4.so.2 so try adding it to the linker command line
/lib64/liblber-2.4.so.2: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1

编辑MakeFile,找到 117行 开头是 ‘EXTRA_LIBS’ 这一行 在结尾加上 ‘-llber’ :

EXTRA_LIBS = ... -llber

重新make(注意不能make clean,因为这样的话MakeFile会还原),输出:

...
Build complete.
Don't forget to run 'make test'

如果执行命令 make test ,进程会卡死,止步于:

...
PASS Bug #66830 (Empty header causes PHP built-in web server to hang) [sapi/cli/tests/bug66830.phpt]

那就绕开此步,关闭进程后,重启进程直接 make install :

make install

输出:

Installing PHP SAPI module:       apache2handler
/usr/local/apache2/build/instdso.sh SH_LIBTOOL='/usr/lib64/apr-1/build/libtool' libphp7.la /usr/local/apache2/modules
/usr/lib64/apr-1/build/libtool --mode=install install libphp7.la /usr/local/apache2/modules/
libtool: install: install .libs/libphp7.so /usr/local/apache2/modules/libphp7.so
libtool: install: install .libs/libphp7.lai /usr/local/apache2/modules/libphp7.la
libtool: install: warning: remember to run `libtool --finish /root/php-7.2.0/libs'
chmod 755 /usr/local/apache2/modules/libphp7.so
[activating module `php7' in /usr/local/apache2/conf/httpd.conf]
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 defconfig:     /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 phpdbg binary:         /usr/local/php/bin/
Installing phpdbg man page:       /usr/local/php/php/man/man1/
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.3
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.4.2
[PEAR] PEAR           - installed: 1.10.5
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
/root/php-7.2.0/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/

运行:

libtool --finish /root/php-7.2.0/libs

添加/usr/local/php/lib/php to your php.ini include_path:

/root/php-7.2.0/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar

编译安装完成。

创建软连接:

ln -s /usr/local/php/bin/php /usr/local/bin/
ln -s /usr/local/php/bin/phpize /usr/local/bin/
ln -s /usr/local/php/bin/php-config /usr/local/bin/

php 配置文件:

cp /root/php-7.2.10/php.ini-production /usr/local/php/etc/php.ini

php-fpm 配置文件:

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

查看版本:

php -v

输出:

PHP 7.2.10 (cli) (built: Mar 12 2018 10:11:46) ( ZTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

重启Apache:

service httpd stop && service httpd start

Apache正常启动。

【问题】

下载:http://php.net/downloads.php

参考:http://amon.org/php55

【依赖】

参考:http://www.bkjia.com/PHPjc/1008013.html
参考:http://www.cnblogs.com/mityaya/p/4436525.html

yum install libmcrypt libmcrypt-devel

onfigure: error: png.h not found.

yum install libpng-devel

configure: error: freetype-config not found.

yum install freetype-devel

configure: error: Unable to find gd.h anywhere under /usr/local/gd

yum install gd-devel

configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.

yum install libicu-devel

参考:http://amon.org/icu

configure: error: Cannot find ldap libraries in /usr/lib.

cp -frp /usr/lib64/libldap* /usr/lib/

checking for libzip… not found
configure: error: Please reinstall the libzip distribution

yum install libzip libzip-devel

checking for libzip… configure: error: system libzip must be upgraded to version >= 0.11

参考:http://amon.org/libzip

make 时报错:cannot find -liconv

参考:http://amon.org/libiconv

checking size of off_t… 0
configure: error: off_t undefined; check your library configuration

参考:https://stackoverflow.com/questions/44941513/php-compile-off-t-undefined
参考:https://stackoverflow.com/questions/44941513/php-compile-off-t-undefined
参考:http://ju.outofmemory.cn/entry/319609

echo ‘/usr/local/lib64 /usr/local/lib /usr/lib /usr/lib64’>>/etc/ld.so.conf&&ldconfig -v

ln -s -f /usr/include/zipconf.h /usr/local/include/zipconf.h