PHP7初体验
jopen
9年前
php7刚出来的时候,由于手头上事情比较多,一直没有时间去弄,只能静静的看着其他人在那吹笔。最近终于闲下来,抽空编译了下php7.
安装PHP
#缺失的部分组件 yum install libpng libpng-devel gd gd-devel zlib zlib-devel libmcrypt libmcrypt-devel #download wget http://am1.php.net/distributions/php-7.0.0.tar.gz tar -zxvf php-7.0.0.tar.gz cd php-7.0.0 #网上找的一段配置项 ./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli --with-pdo-mysql --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts --enable-opcache make make install ln -s /usr/local/php7/bin/php /usr/bin/php7 ln -s /usr/local/php7/bin/phpize /usr/bin/php7ize php -v php7 -v cp /src/php-7.0.0/php.ini-development /usr/local/php7/etc/php.ini vim php.ini (修改timezone为Aisa/Shanghai, 打开opcache及hugepage, opcache.huge_code_pages=1) #查看ini文件修改是否生效 php7 -r "phpinfo();"|grep timezone #查看opcache配置 cat /usr/local/php7/ #查看模块 php7 -m
安装Memcached扩展
#需要安装libmemcached最新版本(所需组件) wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz tar -zxvf libmemcached-1.0.18.tar.gz cd libmencached ./configure --prefix=/usr/local/libmemcached make && make install #安装memcached扩展 git clone https://github.com/php-memcached-dev/php-memcached -b php7 cd php-memcached php7ize #不加--with-php-config参数,会默认使用到原来的php-config,而不是php7-config,导致make的时候报fatal error: Zend/zend_smart_str.h: No such file or directory ./configure --with-libmemcached-dir=/usr/local/libmemcached --with-php-config=/usr/local/php7/bin/php-config make && make install vim php.ini (修改extension=memcached.so) php7 -m #安装memcached服务 yum install memcached -y #开启memcached服务 memcached -d -m 100 -u root -p 11211 -P /tmp/memcached.pid
测试程序:
安装Redis扩展
#git clone地址 git clone https://github.com/phpredis/phpredis -b php7 cd phpredis php7ize ./configure --with-php-config=/usr/local/php7/bin/php-config make && make install vim /usr/local/php7/ect/php.ini (添加extension=redis.so) #安装redis 服务 yum install redis -y service redis start
测试程序:
对了,鸟哥微博里说的,建议gcc升级到4.8:
wget ftp://gcc.gnu.org/pub/gcc/releases/gcc-4.8.2/gcc-4.8.2.tar.bz2 tar -xvf gcc-4.8.2.tar.bz2 cd gcc-4.8.2 ./contrib/download_prerequistities //会自动下载三个依赖库,gmp, mpfr, mpc cd gmp mkdir build cd build ../configure --prefix=/usr/local/gcc/gmp make && make install cd ../../mpfr mkdir build cd build ../configure --prefix=/usr/local/gcc/mpfr --with-gmp=/usr/local/gcc/gmp make && make install cd ../../mpc mkdir build cd build ../configure --prefix=/usr/local/gcc/mpc --with-mpfr=/usr/local/gcc/mpfr --with-gmp=/usr/local/gcc/gmp make && make install vim /etc/ld.so.conf #添加以下内容到文件中: /usr/local/gcc/gmp/lib /usr/local/gcc/mpfr/lib /usr/local/gcc/mpc/lib ldconf 编译gcc cd ../.. ./configure --prefix=/usr/local/gcc --enable-threads=posix --disable-checking --enable-languages=c,c++ --disable-multilib make && make install //漫长的编译。。。第一次编译差不多两三个小时。。 删除旧版本gcc yum remove gcc yum remove gcc-c++ updatedb 链接到新版本 cd /usr/bin ln -s /usr/local/gcc/bin/gcc gcc ln -s /usr/local/gcc/bin/g++ g++ gcc -v