php 7.0 编译安装mysql_PHP7.0.0正式版编译安装LAMP/LNMP【CentOS 7】

本文详细介绍了如何在CentOS 7系统中编译安装PHP 7.0.0,包括安装Apache、libmcrypt、mhash、mcrypt等依赖,以及配置和启用PHP-FPM服务。特别强调了PHP 7.0不再支持--with-mysql选项,推荐使用mysqli和pdo-mysql以及mysqlnd驱动。
摘要由CSDN通过智能技术生成

apache mysql我就不编译了 网上有几篇7.0rc版的文章 但编译参数有问题,并不适合7.0正式版,在这里做一下修正,反正你按我给你的一步步的做,不会有错的....

前期准备 基本上很全了 你可以按自己的需求删减一些

yum groupinstall "Development tools"

yum install -y gcc gcc-c++ make cmake automake autoconf gd file bison patch mlocate flex \

diffutils zlib zlib-devel pcre pcre-devel \

libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel \

glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel \

ncurses ncurses-devel curl curl-devel libcurl libcurl-devel e2fsprogs e2fsprogs-devel \

krb5 krb5-devel openssl openssl-devel \

openldap openldap-devel nss_ldap openldap-clients openldap-servers \

openldap-devellibxslt-devel kernel-devel libtool-libs \

readline-devel gettext-devel libcap-devel php-mcrypt libmcrypt libmcrypt-devel recode-devel

=====================================================================

安装 apache

yum install httpd httpd-devel -y

htttpd-devel中含有apsx命令,可以方便的将 php 作为模块编译加载到 apache中

=====================================================================

安装 libmcrypt mhash mcrypt

CentOS 7 默认不包含这三个模块,所以得手动安装,注意mcrypt依赖前两者

libmcrypt-2.5.8.tar.gz

mhash-0.9.9.tar.gz

mcrypt-2.6.8.tar.gz

问题:configure: error: *** libmcrypt was not found

解决办法:

#

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

或者

ldconfig

=====================================================================

php 编译安装

前几天试着装了一次,虽然最后也装好了但感觉乱乱的,在鸟哥的指导下才知道 mysql 扩展已经被 7.0 废除了,此后使用 mysqli pdo-mysql 并且推荐使用 php 自带的 mysqlnd 驱动 配置参数,并且 php-fpm 也已经被 php 纳入,直接在选项中开启即可,我在官网看 --enable-cgi 是默认配置且 --enable-fast-cgi 已经被废除,--enable-cgi 即可让 fpm 模式调用

ladp在64的系统里可能存在写库关联问题,执行下面的命令

cp -frp /usr/lib64/libldap* /usr/lib/

部分参数释意

./configure \

--prefix=/usr/local/php \

--with-config-file-path=/usr/local/php/etc \

--with-mcrypt \                               # mcrypt 加密算法

--with-mhash \                                # mhash 加密算法

--with-mysqli=mysqlnd \                       # 推荐使用 mysqlnd 驱动 mysql已被废弃

--with-pdo-mysql=mysqlnd \                    # 推荐使用 mysqlnd 驱动 mysql已被废弃

--with-gd \                                   # gd库

--with-iconv \

--with-zlib \

--with-curl \

--with-jpeg-dir \

--with-freetype-dir \

--with-apxs2=/usr/bin/apxs \                  # 让 php 直接编译到 apache 的模块中去

--with-apache=/etc/httpd \                    # 静态编译apache的模块 编译完后去httpd.conf中加载so

--with-openssl \

--with-xmlrpc \

--with-bz2 \

--with-gettext \                              # 多语言应用开发

--with-readline \                             # readline只能在linux下win使用stream_get_line

--with-recode \

--with-ldap \                                   # 目录协议

--with-fpm-user=nginx \

--with-fpm-group=nginx \

--enable-fpm \                                  # php-fpm 进程管理器

--enable-cgi \                                  # 默认开启php的cgi sapi

--enable-xml \

--enable-bcmath \

--enable-inline-optimization \

--enable-mbregex \

--enable-mbstring \

--enable-ftp \

--enable-gd-native-ttf \

--enable-pcntl \                                #pcntl 多进程扩展模块

--enable-sockets \

--enable-sysvmsg \                              #消息队列

--enable-sysvshm \                              #内存共享模块 linux

--enable-shmop \                                #内存共享模块 linux/windows

--enable-zip \

--enable-soap \

--enable-session \

--enable-opcache \                              # opcache 缓存优化

--enable-cli                                    # cli 其实默认就是开启的 若禁用同时要--without-pear

编译参数

./configure \

--prefix=/usr/local/php \

--with-config-file-path=/usr/local/php/etc \

--with-mcrypt \

--with-mhash \

--with-mysqli=mysqlnd \

--with-pdo-mysql=mysqlnd \

--with-gd \

--with-iconv \

--with-zlib \

--with-curl \

--with-jpeg-dir \

--with-freetype-dir \

--with-apxs2=/usr/bin/apxs \

--with-openssl \

--with-xmlrpc \

--with-bz2 \

--with-gettext \

--with-readline \

--with-recode \

--with-ldap \

--with-fpm-user=nginx \

--with-fpm-group=nginx \

--enable-fpm \

--enable-cgi \

--enable-xml \

--enable-bcmath \

--enable-inline-optimization \

--enable-mbregex \

--enable-mbstring \

--enable-ftp \

--enable-gd-native-ttf \

--enable-pcntl \

--enable-sockets \

--enable-sysvmsg \

--enable-sysvshm \

--enable-shmop \

--enable-zip \

--enable-soap \

--enable-session \

--enable-opcache \

--enable-cli

应该不会有什么问题

=========================================================================

注意的地方:

1:--enable-cgi --disable-cgi :

在5.3.0后 enable-cgi 等同于--enable-fastcgi 也就是说此后不需要在额外声明 --enable-fastcgi,且 --enable-force-cgi-redirect 也默认有效且被废弃在编译选项中,要禁用需修改php.ini的cgi.force_redirect为0

2:--with-apxs2  --with-apache:

--with-apxs2是直接把php编译到apache的模块中去  --with-apache是置顶apache的serverRoot路径,生成apache的php模块 修改apache配置文件手动加载:

AddType application/x-httpd-php .php .html .htm

3:php7.0废除了--with-mysql编译选项,且推荐使用mysqlnd驱动

=====================================================================

复制源码包中的 php.ini-development php.ini-production 至 php 安装目录下的 etc 中,或者放在系统的 /etc 下也可以

将 php 的 bin 和 sbin 加入环境变量

echo "export PATH=$PATH:/usr/local/php/bin:/usr/local/php/sbin" >> /etc/profile

source profile

=======================================================================

安装mariadb(mysql)

yum -y install mariadb mariadb-server

启动mariadb后进行初始化设置

mysql_secure_installation

测试

vi /var/www/html/index.php

$con = new mysqli('127.0.0.1', 'root', 'passwd', '', 3306);

$resultObj = $con->query('show databases;');

var_dump($resultObj->fetch_assoc());

?>

php -v

PHP 7.0.0 (cli) (built: Dec  8 2015 16:38:37) ( NTS )

Copyright (c) 1997-2015 The PHP Group

Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies

安装完成

=====================================================================

php-fpm 服务脚本

#! /bin/sh

# Comments to support chkconfig on CentOS

# chkconfig: 2345 65 37

#

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

DESC="php-fpm daemon"

NAME=php-fpm

#php-fpm命令的路径

DAEMON=/usr/local/php/sbin/$NAME

#php-fpm的配置文件

CONFIGFILE=/usr/local/php/etc/php-fpm.conf

#php-fpm的pid文件

PIDFILE=/usr/local/php/var/run/$NAME.pid

SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.

test -x $DAEMON || exit 0

d_start() {

$DAEMON -y $CONFIGFILE || echo -n " already running"

}

d_stop() {

kill -QUIT `cat $PIDFILE` || echo -n " not running"

}

d_reload() {

kill -HUP `cat $PIDFILE` || echo -n " can't reload"

}

case "$1" in

start)

echo -n "Starting $DESC is success"

d_start

echo "."

;;

stop)

echo -n "Stopping $DESC is success"

d_stop

echo "."

;;

reload)

echo -n "Reloading $DESC configuration..."

d_reload

echo "reloaded."

;;

restart)

echo -n "Restarting $DESC is success"

d_stop

sleep 1

d_start

echo "."

;;

*)

echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2

exit 3

;;

esac

这样我们可以使用

service php-fpm start|stop|restart

来管理 php-fpm 服务

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值