编译安装PHP7

安装编译工具

yum install -y gcc gcc-c++ automake autoconf libtool

安装基础库

yum install -y gd gd-devel zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel \
libjpeg libjpeg-devel libjpeg-turo-devel libpng libpng-devel freetype freetype-devel libcurl-devel libxslt-devel pcre pcre-devel
#安装yum无法安装的libiconv库
#libiconv库为需要做转换的应用提供了一个iconv()的函数,以实现一个字符编码到另一个字符编码的转换
cd /data/tools
wget http://ftp.gnu.org/gnu/libiconv/libiconv-1.14.tar.gz
tar zxf libiconv-1.14.tar.gz 
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make
注意:错误如下
    In file included from progname.c:26:0:
    ./stdio.h:1010:1: error: ‘gets’ undeclared here (not in a function)
    _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
    ^
    ...
解决办法:
  vim libiconv-1.14/srclib/stdio.in.h
  将698行的代码:_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");替换为:
    #if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)
      _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
    #endif
重新编译安装
    ./configure --prefix=/usr/local/libiconv
    make
    make install
  
#安装默认yum源无法安装的libmcrypt库(libmcrypt对于在程序运行时添加移除算法是有用的)
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum install libmcrypt-devel
#安装mhash加密扩展库
yum install mhash
#安装 mcrypt加密扩展库
yum install mcrypt

安装MariaDB

yum install mariadb mariadb-server mariadb-devel

安装Nginx

cd /data/tools
wget http://nginx.org/download/nginx-1.12.1.tar.gz
groupadd nginx
useradd -r -g nginx -s /sbin/nologin nginx
tar zxf nginx-1.12.1.tar.gz 
cd nginx-1.12.1
./configure --prefix=/application/nginx-1.12.1 --user=nginx --group=nginx
make
make install
ln -s /application/nginx-1.12.1 /application/nginx

编译安装php

cd /data/tools
wget wget http://php.net/distributions/php-7.1.7.tar.gz
tar zxf php-7.1.7.tar.gz
cd php-7.1.7
./configure \
--prefix=/application/php-7.1.7 \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-openssl \
--with-mhash \
--with-mcrypt \
--with-gd \
--with-curl \
--with-xmlrpc \
--with-xsl \
--with-libxml-dir \
--enable-gd-native-ttf \
--disable-debug \
--disable-rpath \
--enable-shared \
--with-mysql=shared,mysqlnd \
--with-mysqli=shared,mysqlnd \
--with-pdo-mysql=shared,mysqlnd \
--enable-zip \
--enable-soap \
--enable-static \
--enable-mbregex \
--enable-sockets \
--enable-short-tags \
--enable-inline-optimization \
--enable-ftp \
--enable-pcntl \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx 
 
make
make install
 
#复制配置文件
ln -s /application/php-7.1.7 /application/php
cp /data/tools/php-7.1.7/php.ini-production /application/php/lib/php.ini
cp /application//php/etc/php-fpm.conf.default /application/php/etc/php-fpm.conf
cp /application/php/etc/php-fpm.d/www.conf.default /application/php/etc/php-fpm.d/www.conf

整合Nginx + php

location ~ \.php$ {
    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $DOCUMENT_ROOT$fastcgi_script_name;
    include        fastcgi_params;
}

启动php和Nginx

/application/php/sbin/php-fpm 
/application/nginx/sbin/nginx

写PHP测试页面,打开浏览器http://xxxxxx/a.php

<?php
# /application/nginx/html/a.php
phpinfo();

配置PHP与数据库的连接

#确认MySQL的模块存在
/application/php/lib/php/extensions
cd /application/php/lib/php/extensions;ls
  no-debug-non-zts-20160303
ls no-debug-non-zts-20160303/
  mysqli.a  mysqli.so  opcache.a  opcache.so  pdo_mysql.a  pdo_mysql.so
#这里我们使用mysqli.so来连接数据库,编辑php.ini,加入下面配置
vim /application/php/lib/php.ini 
  ...
  extension_dir = "/application/php/lib/php/extensions/no-debug-non-zts-20160303"  #配置在735行
  extension=mysqli.so   #配置877行
  ...
#重启php-fpm

启动Mariadb并且配置账号授权

写数据库测试页面

<?php
#/application/nginx/html/b.php 
$conn = mysqli_connect('<数据库地址>','<账号>','<密码>');
if($conn){
    echo "ok";
}else{
    echo "fail";
}

打开浏览器http://xxxxxx/b.php,如果浏览器显示OK则表示数据库连接正常!

 

posted @ 2017-11-05 17:29  sellsa  阅读(272)  评论(0编辑  收藏  举报