大家好,我是雷丘,欢迎来到我的博客,这是我第一篇技术博文,如果有错误和不明白的地方,欢迎留言,收到第一时间回复。
最近在搞app服务端的程序,开始是thinkphp开发的,后来又使用了php自己开发架构,但是性能都不是很好,当然java,nodejs,python等高大上语言本人也会,但是我还是喜欢php,近期听说php7出来了,性能赶超HHVM,心里小激动,再加上开了 swoole,workerman,yaf等C语言开发php扩展,瞬间对php的性能有了新的认知,php也能达到几万几十万的QFS,所以准备学习下这几个 框架,然后测试下php7的性能。
我在 virtualbox 上 安装了 CentOS7.0的操作系统,主要目的还是测试php7 然后做开发
CentOS7.0 我用的是 mini安装,安装很快,安装好后,要对系统进行一些简单的配置
虚拟机网卡设置 使用桥接网卡,centos就可以上网了。
1.最小安装的centos7 不提供 ifconfig命令的支持
yum install net-tools
执行命令后 可以正常使用ifconfig产看网卡信息了。
2.CentOS 7.0默认使用的是firewall作为防火墙,需要关闭后用如下命令
systemctl start firewalld.service#启动firewall
systemctl stop firewalld.service#停止firewall
systemctl disable firewalld.service#禁止firewall开机启动
3.安装一些常用的工具
yum -y install bash-completion vim net-tools bind-utils wget screen
yum groupinstall "Development tools"
4.安装依赖库,一大堆,一起yum安装了就
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 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
5.安装cmake
wget http://www.cmake.org/files/v3.3/cmake-3.3.0-rc2.tar.gz
tar -zvxf cmake-3.3.0-rc2.tar.gz
cd cmake-3.3.0-rc2
./configure
make && make install
6安装libxml2
yum install libxml2
yum install libxml2-devel
7安装libmarypt
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz
tar -zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make && make install
准备工作做好了,然后就是编译安装php7了,安装php7的主要目的是用 swoole开发项目,最新版的swoole支持php7,所以我就尝试下,据说php7的性能和HHVM的性能差不多,所以来测试下,再加上swoole的性能官方介绍秒杀nodejs,这个说法让我不禁熬夜测试安装。
php7目前只发布了阿尔法1版本,所以bug肯定还是有的,不建议用于生产环境
8.安装php7
可以直接下载,也可以从git上面获取
wget https://downloads.php.net/~ab/php-7.0.0alpha1.tar.gz
tar -zxvf php-7.0.0alpha1.tar.gz
cd php-7.0.0alpha1
当然,php7比较新,很多程序还不支持,比如截至雷丘写日志的时候 swoole1.7.18还没出来,估计过几天,1.7.18才支持php7,所以这里给出一个php5.6.10的安装地址,国内镜像,嗖嗖的。
wget http://cn2.php.net/get/php-5.6.10.tar.gz/from/this/mirror
这里说些php7的编译参数
./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
php5.6.10的编译参数
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-mysql=mysqlnd \
--with-mysql-sock=/tmp/mysql.sock \
--with-libxml-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-ftp \
--enable-mbstring \
--enable-exif \
--disable-ipv6 \
--with-pear \
--with-curl \
--with-openssl
如果编译出错了,可以看文章末尾的错误整理,或者百度检查下,系统可能缺少软件。
出现
Generating files configure: creating ./config.status creating main/internal_functions.c creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating main/php_config.h
config.status: executing default commands
表示安装成功,如果一切顺利的话,执行
make && make install
根据你的机器配置,时间可能很快或者很慢哦,需要耐心等待。
php安装过程中常见错误信息整理,这也是我开始安装的时候经常出现的,因为linux是 mini安装的,所以很多程序系统都没有。
error 1
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation.
(看提示就明白 是一个lib库没装 先用 yum search 名字 看是否能搜到名字 ,找到名字后 把软件包 开发包装上)
解决办法
yum install libxml2-devel.x86_64
error 2
checking for pkg-config... /usr/bin/pkg-config
configure: error: Cannot find OpenSSL's <evp.h>
这是ssl没装
解决办法
yum install openssl.x86_64 openssl-devel.x86_64 -y
error 3
checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution
这是bzip2软件包没有安装
解决办法
yum install bzip2-devel.x86_64 -y
error 4
configure: error: Please reinstall the libcurl distribution -
easy.h should be in <curl-dir>/include/curl/
curl和curl库文件没有安装
解决办法
yum install libcurl.x86_64 libcurl-devel.x86_64 -y
error 5
checking whether to enable JIS-mapped Japanese font support in GD... no
checking for fabsf... yes
checking for floorf... yes
configure: error: jpeglib.h not found
GD库没有安装
解决办法
yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y
error 6
checking for stdarg.h... (cached) yes
checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
libmcrypt库没有安装 ,要是不能用yun安装的话 就要去下载个gz包 自己编译安装
(编译安装 ./configure --piefix=/usr/local/libmcrypt make && make install)
要是错误里面含有mysql的 那是mysql-devel 没有安装