首先推荐一篇文章PHP 7 Release Date Arrived: Will Developers Adopt PHP 7? - PHP Classes blog。
里面说到是否会去使用PHP7,就个人而言,我是毫不犹豫地使用的,但是生产环境就不是我说了算,所以只能自己在自己的开发环境里更新PHP的版本。那么,你呢?
笔者使用的是Linux的openSUSE42.1发行版,Yast里面还没有PHP7的安装包,于是乎只能自己手动编译安装了。作为一个PHP开发者,我是非常希望能够学会编译安装PHP7的,之前试过几次,但是每次安装都要上网找各种资料,于是乎,这次安装成功后就想把自己的安装过程以及遇到的问题记录下来,方便以后查阅和分享给需要的人。
进入正题,要编译安装PHP7,首先当然要下载PHP7的源码。你可以到github上clone,也可以到PHP官网下载。下载后解压到 /usr/local/src 目录,并将目录重命名为php7。进入目录。
./buildconf
./<span>configure \ </span>--prefix=/usr/local/<span>php7 \ </span>--exec-prefix=/usr/local/<span>php7 \ </span>--bindir=/usr/local/php7/<span>bin \ </span>--sbindir=/usr/local/php7/<span>sbin \ </span>--includedir=/usr/local/php7/<span>include \ </span>--libdir=/usr/local/php7/lib/<span>php \ </span>--mandir=/usr/local/php7/php/<span>man</span><span> \ </span>--with-config-<span>file</span>-path=/usr/local/php7/<span>etc \ </span>--with-mysql-sock=/var/run/mysql/<span>mysql.sock \ </span>--with-mcrypt=/usr/<span>include \ </span>--with-<span>mhash \ </span>--with-<span>openssl \ </span>--with-mysqli=<span>shared,mysqlnd \ </span>--with-pdo-mysql=<span>shared,mysqlnd \ </span>--with-<span>gd \ </span>--with-<span>iconv \ </span>--with-<span>zlib \ </span>--enable-<span>zip</span><span> \ </span>--enable-inline-<span>optimization \ </span>--disable-<span>debug \ </span>--disable-<span>rpath \ </span>--enable-<span>shared \ </span>--enable-<span>xml \ </span>--enable-<span>bcmath \ </span>--enable-<span>shmop \ </span>--enable-<span>sysvsem \ </span>--enable-<span>mbregex \ </span>--enable-<span>mbstring \ </span>--enable-<span>ftp</span><span> \ </span>--enable-gd-native-<span>ttf \ </span>--enable-<span>pcntl \ </span>--enable-<span>sockets \ </span>--with-<span>xmlrpc \ </span>--enable-<span>soap \ </span>--without-<span>pear \ </span>--with-<span>gettext \ </span>--enable-<span>session \ </span>--with-<span>curl \ </span>--with-jpeg-<span>dir</span><span> \ </span>--with-freetype-<span>dir</span><span> \ </span>--enable-<span>opcache \ </span>--enable-<span>fpm \ </span>--disable-<span>cgi \ </span>--with-fpm-user=<span>nginx \ </span>--with-fpm-group=<span>nginx \ </span>--without-<span>gdbm \ </span>--disable-fileinfo
参数说明
<p>prefix PHP7安装的根目录</p> <p><em id="__mceDel">with-config-file-path PHP7的配置文件目录</em></p>
执行完上面的配置命令后的结果如下图所示:
执行上面命令的过程中会遇到一些依赖缺少的提示,下面列出我遇到的依赖问题:
错误:
configure: error: xml2-config not found. Please check your libxml2 installation.
解决:
zypper <span>install</span> libxml2-devel
错误:
configure: WARNING: unrecognized options: --with-mysql
解决:
取消这个选项,这个选项是不存在的
错误:
configure: error: jpeglib.h not found.
解决:
zypper <span>install</span> libjpeg-devel
错误:
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决:
zypper <span>install</span> libmcrypt-devel
错误:
checking <span>for</span><span> recode support... yes configure: error: Can not </span><span>find</span> recode.h anywhere under /usr /usr/local /usr /opt.
解决:
zypper <span>install</span> librecode-devel
总的来说,在配置的时候遇到没有的就打开Yast搜一下,如果有的话就安装,然后重新编译看还需要那些,如果在Yast找不到,那就上网找一下Google。
<span>make</span> && <span>make</span> <span>install</span>
<p>其中,make之后可以选择make test。只是一个可选步骤,不执行不知道有什么问题,不过笔者暂时还没遇到。</p>
编译安装成功后,查看PHP7的安装目录`ls /usr/local/php7`:
<span>cp</span> /usr/local/src/php7/php.ini-production /usr/local/php7/etc/<span>php.ini </span><span>cp</span> /usr/local/src/sapi/fpm/init.d.php-fpm /etc/init.d/php-<span>fpm </span><span>cp</span> /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-<span>fpm.conf </span><span>cp</span> /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
在/etc/profile 文件的最后一行加上
export PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH
然后执行 source /etc/profile
<span>mkdir</span> -p /var/log/php-fpm/ && <span>mkdir</span> -p /var/run/php-fpm && cd /var/run/ && <span>chown</span> -R nginx:nginx php-fpm
<span>chmod</span> +x /etc/init.d/php-<span>fpm chkconfig php</span>-fpm on
<p>可以用chkconfig命令查看开机启动服务列表。</p>
service php-fpm start
通过ps aux | grep 'php'查看PHP是否启动成功
至此,PHP7就安装成功了,你也开始使用PHP7吧!