通过yum源安装php7
PHP 7.0.0 已经推出了几天,带来了新版本的Zend引擎,不仅如此,还有许多新特性和改进,比如:
性能提升:PHP 7速度是PHP 5.6的两倍
内存的使用显著降低
抽象语法树
支持64位
许多重大的错误将转为异常
安全的随机数生成器
删除旧的、不支持的SAPIs和扩展
null合并操作符(??)
返回和标量类型声明
匿名类
零成本断言
下面我通过结合docker,部署一下php7
定义dockerfile
REMI 仓库提供了CentOS和RHEL的核心包的更新版本,尤其是最新的PHP/MySQL系列。 因此我选择通过
remi源的方式在线安装php7。具体的dockerfile定义如下:FROM centos:centos6RUN rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpmRUN rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpmRUN rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remiRUN yum -y --enablerepo=remi install php70 php70-php-cli php70-php-common php70-php-fpm# 安装mysql扩展RUN yum -y --enablerepo=remi install php70-php-mysqlnd# 安装nginxRUN yum -y install nginx# 增加一个启动脚本RUN echo "#!/bin/bash" >> /start.shRUN echo "/opt/remi/php70/root/usr/sbin/php-fpm" >> /start.shRUN echo "/usr/sbin/nginx" >> /start.sh# 监听80端口EXPOSE 80# 给脚本一个执行权限RUN chmod +x /start.sh#启动容器,执行 start.sh命令CMD /start.sh
注意事项: 安装remi源之前,首先需要安装epel源
把nginx服务跟php部署在同一个容器里
编译镜像
docke build -t fasss/php7 .
进入容器拷贝配置文件
运行容器
docker run -it fasss/php7 bash
进入php的安装目录
cd /opt/remi/php70/root
查看php配置文件目录
[root@96238f70b8b4 root]# ./usr/bin/php -i | head -10phpinfo()PHP Version => 7.0.0System => Linux 96238f70b8b4 3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22 UTC 2014 x86_64Build Date => Dec 3 2015 17:56:57Server API => Command Line InterfaceVirtual Directory Support => disabledConfiguration File (php.ini) Path => /etc/opt/remi/php70
得到php和fpm的配置文件目录为 /etc/opt/remi/php70
退出容器。从容器里拷贝文件到宿主机
docker cp 96238f70b8b4:/etc/opt/remi/php70 ./
96238f70b8b4这个根据你自己生成的容器ID来
宿主机映射的配置文件夹位置
docker cp 96238f70b8b4:/etc/nginx /data/etc/php70/
修改宿主机上的nginx配置文件
nginx conf文件
daemon off;user nginx;worker_processes 1;error_log /var/log/nginx/error.log;pid /var/run/nginx.pid;events { worker_connections 1024;}http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on;server { listen 80; #charset koi8-r; access_log /var/log/nginx/access.log main; location / { root /webwww/bbs; index index.php index.html index.htm; } location ~ \.php$ { root /webwww/bbs; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }}
注意点: 「daemon off」表示程序在前台运行。 「/webwww/bbs」 document_root的位置。
里面是我创建的一个hello.php文件。 输出「hello from php7」
运行最终容器
docker run -it --name my_php7 \-v /data/etc/php70/nginx/:/etc/nginx/ \-v /data/app/test:/webwww/bbs -p 80:80 fasss/php7
/data/app/test 表示程序文件夹
/data/etc/php70/nginx/:/etc/nginx/ 配置文件映射
显示结果:
源码安装php7
下载源码包
wget http://cn2.php.net/get/php-7.0.0.tar.gz/from/this/mirror
安装编译工具
yum -y install gcc automake autoconf libtool makeyum -y install gcc gcc-c++ glibc
安装EPEL源
rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
防止有些包找不到
安装基础库
yum -y install libmcrypt-devel mhash-devel libxslt-devel \libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel \libxml2 libxml2-devel \zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 \bzip2-devel \ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel \krb5 krb5-devel libidn libidn-devel openssl openssl-devel
编译
./configure --prefix=/usr/local/php \--with-config-file-path=/usr/local/php/etc \--with-mysqli \--with-openssl \--enable-fpm \--enable-mbstring \--with-freetype-dir \--with-jpeg-dir \--with-png-dir \--with-zlib-dir \--with-libxml-dir=/usr \--enable-xml \--with-mhash \--with-mcrypt \--enable-pcntl \--enable-sockets \--with-bz2 \--with-curl \--enable-mbregex \--with-gd \--enable-gd-native-ttf \--enable-zip \--enable-soap \--with-iconv \--enable-sysvshm \--enable-sysvmsg \--with-pdo-mysql# 如果没有错误makemake install
检查是否已经安装完成
[root@b30acbed1ebd php]# /usr/local/php/bin/php -vPHP 7.0.0 (cli) (built: Dec 7 2015 13:03:05) ( NTS )Copyright (c) 1997-2015 The PHP GroupZend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
修改fpm的配置文件
cd /usr/local/php/etc/mv php-fpm.conf.default php-fpm.confcd /usr/local/php/etc/php-fpm.dmv www.conf.default www.conf
启动fpm
/usr/local/php/sbin/php-fpm
常见错误
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
出现错误
yum install libmcrypt libmcrypt-devel
No package libmcrypt available.No package libmcrypt-devel available.
需要安装EPEL源
安装第三方源:EPEL源
rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
在线安装 libmcrypt
yum install libmcrypt libmcrypt-devel