centos7安装php7

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7安装php7相关的知识,希望对你有一定的参考价值。

准备工作:

Yum update & yum upgrade
Yum –y install gcc*  
yum -y install libevent-devel  
yum -y install gperftools

编译安装libmcrypt, mhash, mcrypt 二进制源码包 

这里之所以编译安装libmcrypt,原因是yum安装的貌似会报错

######编译安装libmcrypt-2.5.7

[[email protected] soft]# tar zxvf libmcrypt-2.5.8.tar.gz

[[email protected] soft]# cd libmcrypt-2.5.8

[[email protected] libmcrypt-2.5.8]# ./configure--prefix=/usr/local/related/libmcrypt

[[email protected] libmcrypt-2.5.8]# make &&make install

######编译安装mhash-0.9.9.9

[[email protected] soft]# tar zxf mhash-0.9.9.9.tar.gz

[[email protected] soft]# cd mhash-0.9.9.9

[[email protected] mhash-0.9.9.9]# ./configure--prefix=/usr/local/related/mhash

[[email protected] mhash-0.9.9.9]# make && makeinstall

######编译安装mcrypt-2.6.8

[[email protected] soft]# tar zxf mcrypt-2.6.8.tar.gz&& cd mcrypt-2.6.8

[[email protected] mcrypt-2.6.8]# exportLD_LIBRARY_PATH=/usr/local/related/libmcrypt/lib:/usr/local/related/mhash/lib

[[email protected] mcrypt-2.6.8]# exportLDFLAGS="-L/usr/local/related/mhash/lib-I/usr/local/related/mhash/include/"

[[email protected] mcrypt-2.6.8]# exportCFLAGS="-I/usr/local/related/mhash/include/"

[[email protected] mcrypt-2.6.8]# ./configure--prefix=/usr/local/related/mcrypt--with-libmcrypt-prefix=/usr/local/related/libmcrypt

[[email protected] mcrypt-2.6.8]# make && makeinstall

######其他依赖yum安装

[[email protected] ~]# yum -y install libxml2 libxml2-developenssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel -y


php 7编译参数的配置

注意,操作时一定要先把下面反斜杠“\”后面添加的注释文字去掉!!!

######生成配置文件

[[email protected] soft]#tar -zxf php-7.0.0.tar.gz&& cd php-7.0.0

[[email protected] php-7.0.13]# rm -rf configure

[[email protected] php-7.0.13]# ./buildconf --force

Forcing buildconf

Removing configure caches

buildconf: checking installation...

buildconf: autoconf version 2.69 (ok)

rebuilding configure

rebuilding main/php_config.h.in

######开始配置

[[email protected] php-7.0.13]# ./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-mcrypt=/usr/include --with-mhash --with-openssl--with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --with-gd--with-iconv --with-zlib --enable-zip --enable-inline-optimization --disable-debug--disable-rpath --enable-shared --enable-xml --enable-bcmath --enable-shmop--enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp--enable-gd-native-ttf --enable-pcntl --enable-sockets  --with-xmlrpc --enable-soap --without-pear --with-gettext--enable-session --with-curl --with-jpeg-dir --with-freetype-dir--enable-opcache --enable-fpm --enable-fastcgi --with-fpm-user=nginx--with-fpm-group=nginx --without-gdbm--with-mcrypt=/usr/local/related/libmcrypt --disable-fileinfo

执行上面的配置命令的运行结果如下:

技术分享


开始编译安装PHP 7

[[email protected]]# make clean && make && make install

PHP7编译安装成功 

技术分享

[[email protected]]# ls -lrt/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/

total 1368

-rwxr-xr-x 1 root root 256998Nov 30 11:04 mysqli.a

-rwxr-xr-x 1 root root 193651Nov 30 11:04 mysqli.so

-rwxr-xr-x 1 root root 501074Nov 30 11:04 opcache.a

-rwxr-xr-x 1 root root 342253Nov 30 11:04 opcache.so

-rwxr-xr-x 1 root root  51750 Nov 30 11:04 pdo_mysql.a

-rwxr-xr-x 1 root root  42613 Nov 30 11:04 pdo_mysql.so

[[email protected]]# cp php.ini-production /usr/local/php7/etc/php.ini

[[email protected]]# cd /usr/local/php7/etc/

[[email protected] etc]# cpphp-fpm.conf.default php-fpm.conf

[[email protected] etc]#vim php.ini

extension_dir= "/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/"


安装memcached

 

先安装libmemcached

[[email protected] soft]#tar -zxvf libmemcached-1.0.8.tar.gz

[[email protected] soft]#cd libmemcached-1.0.8

[[email protected]]#  ./configure--prefix=/usr/local/libmemcached

[[email protected]]#  make&& make install


下载php7的memcached

[[email protected] soft]# gitclone https://github.com/php-memcached-dev/php-memcached  

[[email protected] soft]# cdphp-memcached   

[[email protected] php-memcached]# git checkoutphp7    //非常重要

Branch php7 set up to track remote branch php7 fromorigin.

Switched to a new branch ‘php7‘

[[email protected]]#/usr/local/php7/bin/phpize

[[email protected]]# ./configure --enable-memcached--with-php-config=/usr/local/php7/bin/php-config --with-zlib-dir--prefix=/usr/local/phpmecached --disable-memcached-sasl--with-libmemcached-dir=/usr/local/libmemcached/

[[email protected]]#make && make install

[[email protected]]# vim /usr/local/php7/etc/php.ini

extension="memcached.so"

下载nginx1.10.2最新稳定版本

[[email protected] soft]#wget http://219.239.26.14/files/321500000944715A/nginx.org/download/nginx-1.10.2.tar.gz

[[email protected] soft]#tar -zxvf nginx-1.10.2.tar.gz

[[email protected] soft]#cd nginx-1.10.2

[[email protected]]# useradd nginx

[[email protected] nginx-1.10.2]#./configure --prefix=/usr/local/nginx --with-pcre--with-http_stub_status_module --user=nginx --group=nginx

 

 

配置nginx.conf

user  nginx nginx;

worker_processes 4;

worker_cpu_affinity 0000000100000010 00000100 0000100;

worker_processes 8;

worker_cpu_affinity 0000000100000010 00000100 00001000 00010000 00100000 01000000 10000000;

error_log  logs/nginx_error.log  notice;

#pid        /usr/local/nginx/logs/nginx.pid

 

#Specifies the value formaximum file descriptors that can be opened by this process.

worker_rlimit_nofile 65535;

 

events

{

  use epoll;

  worker_connections 65535;

}

 

http

{

  include      mime.types;

  default_type application/octet-stream;

  #charset gb2312;

  server_names_hash_bucket_size 128;

  client_header_buffer_size 2k;

  large_client_header_buffers 4 4k;

  client_max_body_size 8m;

     

  sendfile on;

  tcp_nopush    on;

 

  keepalive_timeout 60;

 

 

  fastcgi_connect_timeout 300;

  fastcgi_send_timeout 300;

  fastcgi_read_timeout 300;

  fastcgi_buffer_size 64k;

  fastcgi_buffers 8 64k;

  fastcgi_busy_buffers_size 128k;

  fastcgi_temp_file_write_size 128k;

#  fastcgi_temp_path/usr/local/nginx/fastcgi_temp;

#  # fastcgi_cache_path /usr/local/nginx/fastcgi_cache levels=2:2keys_zone=ngx_fcgi_cache:512m inactive=1d max_size=40g;

#  # fastcgi_cache_valid 200 301 302 1d;

#  # fastcgi_cache_use_stale error timeout invalid_header http_500;

#  # fastcgi_cache_key $request_method://$host$request_uri;

#  # fastcgi_cache ngx_fcgi_cache;

#  #

#  # open_file_cache max=204800 inactive=20s;

#  # open_file_cache_min_uses 1;

#  # open_file_cache_valid 30s;

  tcp_nodelay on;

  server_tokens off;

 

  gzip on;

  gzip_min_length  1k;

  gzip_buffers 4 16k;

  gzip_http_version 1.0;

  gzip_comp_level 2;

  gzip_types       text/plain application/x-javascripttext/css application/xml;

  gzip_vary on;

  #limit_zone myzone_wq $binary_remote_addr  10m;

  # #limit_req_zone $binary_remote_addr zone=wq:10m rate=1r/s;

  log_format access  ‘$remote_addr -$remote_user [$time_local] "$request" ‘ ‘$status $body_bytes_sent"$http_referer" ‘ ‘"$http_user_agent"$http_x_forwarded_for‘;

  include/usr/local/nginx/conf/vhost_conf/*.conf;

}

 

[[email protected] conf]#mkdir vhost_conf/

[[email protected]_conf]# vim service.conf

 

server {

    listen  80;

    server_name www.example.com;

    access_log /usr/local/nginx/logs/example.com.access.log; 

 

    location / {

        root /usr/local/nginx/html;

        index index.php index.html index.htm;

    }

 

    location /images {

        autoindex on;

    }

 

    location ~ \.php$ {

        fastcgi_pass   127.0.0.1:9000;

        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;

        include fastcgi_params;

    }

}

[[email protected]_conf]# vim nginx_status.conf

 

server

{

    listen 4444;

    server_name 127.0.0.1;

    location /nginx_status {

        stub_status on;

        access_log off;

    }

}


完成!


错误提示:

ERROR: ld.so: object‘/usr/local/lib/libtcmalloc_minimal.so‘ from LD_PRELOAD cannot be preloaded:ignored.

解决:安装 gperftools 即可!

本文出自 “windows与linux” 博客,转载请与作者联系!

以上是关于centos7安装php7的主要内容,如果未能解决你的问题,请参考以下文章

centos7 安装nginx和php7

Centos7 安装 PHP7最新版

centos7 源码安装php7

Centos7下安装php7

源码安装CentOs7下的PHP7

Centos7 安装PHP7版本