缘起
最近在win10子系统中源码安装PHP7,遇到了各种问题,谷歌之记录解决方法。
下载源码
PHP源码有三个获取方式:
- Github下载,
- git.php.net 下载
- 压缩包下载
这个里选择Github下载:
//更新依赖sudo apt-get update sudo apt-get install build-essential //安装依赖sudo apt-get install -y autoconf libtool re2c libxml2-dev openssl libcurl4-openssl-dev libbz2-dev libjpeg-dev libpng12-dev libfreetype6-dev libldap2-dev libmysqlclient-dev libxslt1-dev libxt-dev libpcre3-dev libxpm-dev libt1-dev libgmp-dev libpspell-dev librecode-dev libreadline6-dev bison libtidy-dev //下载源码wget https://github.com/php/php-src/archive/php-7.0.20.tar.gz//解压tar -xzvf php-7.0.20.tar.gzcd php-7.0.20//生成configure文件./autoconf//检查配置./configure --prefix=/usr/local/php7 --exec-prefix=/usr/local/php7 --bindir=/usr/local/php7/bin --sbindir=/usr/local/php7/sbin --includedir=/usr/local/php7/include --libdir=/usr/local/php7/lib/php --mandir=/usr/local/php7/php/man --with-config-file-path=/usr/local/php7/etc --with-mysql-sock=/var/run/mysql/mysql.sock --enable-opcache --enable-ctype --enable-fpm --enable-tokenizer --enable-fileinfo --enable-pdo --enable-sockets --enable-exif --enable-soap --enable-ftp --enable-wddx --enable-pcntl --enable-soap --enable-bcmath --enable-mbstring --enable-dba --enable-gd-jis-conv --enable-zip --enable-calendar --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-mysqli --with-pdo-mysql --with-pdo-sqlite --with-iconv --with-gmp --with-pspell --with-gettext --with-xmlrpc --with-openssl --with-mhash --with-xsl --with-curl --with-pcre-regex --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-zlib-dir=/usr --with-xpm-dir=/usr --with-freetype-dir=/usr --with-gettext=/usr --with-zlib=/usr --with-bz2=/usr --with-recode=/usr --with-ldap --with-pear --with-readline//编译并安装make && make install
-v参数表示输出版本号,如果命令执行完后看到输出php版本信息则说明编译成功。
常见错误
错误一
configure: error: xml2-config not found. Please check your libxml2 installation.
解决
apt-get install libxml2-dev
错误二
/usr/bin/mysql_config: No such file or directory
解决:
apt-get install mysql-server mysql-client libmysqlclient-dev
错误三
Warning: Declaration of PEAR_Installer::download() should be compatible with & PEAR_Downloader::download($params) in phar:///root/php7/php-src/pear/install-pear-nozlib.phar/PEAR/Installer.php on line 43Warning: Declaration of PEAR_PackageFile_Parser_v2::parse() should be compatible with PEAR_XMLParser::parse($data) in phar:///root/php7/php-src/pear/install-pear-nozlib.phar/PEAR/PackageFile/Parser/v2.php on line 113[PEAR] Archive_Tar - installed: 1.3.13[PEAR] Console_Getopt - installed: 1.3.1[PEAR] Structures_Graph- installed: 1.0.4Warning: Declaration of PEAR_Task_Replace::init() should be compatible with PEAR_Task_Common::init($xml, $fileAttributes, $lastVersion) in phar:///root/php7/php-src/pear/install-pear-nozlib.phar/PEAR/Task/Replace.php on line 31[PEAR] XML_Util - installed: 1.2.3Warning: Declaration of PEAR_Task_Windowseol::init() should be compatible with PEAR_Task_Common::init($xml, $fileAttributes, $lastVersion) in phar:///root/php7/php-src/pear/install-pear-nozlib.phar/PEAR/Task/Windowseol.php on line 76Warning: Declaration of PEAR_Task_Unixeol::init() should be compatible with PEAR_Task_Common::init($xml, $fileAttributes, $lastVersion) in phar:///root/php7/php-src/pear/install-pear-nozlib.phar/PEAR/Task/Unixeol.php on line 76[PEAR] PEAR - installed: 1.9.5Wrote PEAR system config file at: /root/php7/usr/etc/pear.conf
解决:
You may want to add: /root/php7/usr/lib/php to your php.ini include_path/root/php7/php-src/build/shtool install -c ext/phar/phar.phar /root/php7/usr/bin
错误四
configure: WARNING: unrecognized options: --with-mysql
解决:
改用 -with-pdo-mysql
错误五
checking for bison version... invalidconfigure: WARNING: This bison version is not supported for regeneration of the Zend/PHP parsers (found: none, min: 204, excluded: ).checking for re2c... noconfigure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.configure: error: bison is required to build PHP/Zend when building a GIT checkout!
解决
apt-get install bison
错误六
configure: error: Cannot find OpenSSL's
解决
apt-get install libssl-dev
错误七
configure: error: Cannot find OpenSSL's libraries
解决
apt-get install libssl-dev
错误
checking for BZip2 in default path… not foundconfigure: error: Please reinstall the BZip2 distribution
解决
apt-get install libbz2-dev
错误
configure: error: Please reinstall the libcurl distribution –easy.h should be in /include/curl/
解决
apt-get install libcurl4-openssl-dev
错误
If configure fails try --with-vpx-dir=configure: error: jpeglib.h not found.
解决
apt-get install libjpeg-dev
错误
configure: error: png.h not found.
解决
apt-get install libpng12-dev
错误
configure: error: freetype-config not found.
解决
apt-get install libfreetype6-dev
错误
//PHP7以上版本已经废弃了mcrpyt扩展,请使用openssl代替.configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决
apt-get install libmcrypt-dev
错误
configure: error: Cannot find pspell
解决
apt-get install libpspell-dev
错误
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
解决
pear install pear/PHP_Archive
错误
checking for recode support... yesconfigure: error: Can not find recode.h anywhere under /usr /usr/local /usr /opt.
解决
apt-get install librecode-dev