CentOS下安装PHP7+Nginx+MySQL的方法详解

广告:宝塔Linux面板高效运维的服务器管理软件 点击【 https://www.bt.cn/p/uNLv1L 】立即购买

CentOS下安装PHP7+Nginx+MySQL的方法详解

本文以centos6为例。命令部分均省略sudo命令。

安装PHP

下载

http://cn2.php.net/distributions/php-5.6.22.tar.bz2http://cn2.php.net/distributions/php-7.0.7.tar.bz2
登录后复制

更新yum源

这里将Centos的yum源更换为国内的阿里云源。yum安装正常的可以跳过本步骤。

阿里云Linux安装镜像源地址:

http://mirrors.aliyun.com/
登录后复制

1、备份你的原镜像文件,以免出错后可以恢复:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
登录后复制

2、下载新的CentOS-Base.repo 到/etc/yum.repos.d/

## CentOS 5wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo## CentOS 6wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo## CentOS 7wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
登录后复制

3、生成缓存

yum clean allyum makecache
登录后复制

安装依赖

yum install -y gcc gcc-c++ make cmake bison autoconf wget lrzszyum install -y libtool libtool-ltdl-devel yum install -y freetype-devel libjpeg.x86_64 libjpeg-devel libpng-devel gd-develyum install -y python-devel  patch  sudo yum install -y openssl* openssl openssl-devel ncurses-develyum install -y bzip* bzip2 unzip zlib-develyum install -y libevent*yum install -y libxml* libxml2-develyum install -y libcurl* curl-devel yum install -y readline-devel
登录后复制

需要编译libmcrypt、mhash、mcrypt库

tar zxvf /libmcrypt-2.5.8.tar.gz \&& cd /libmcrypt-2.5.8 && ./configure && make && make install && cd - / && rm -rf /libmcrypt* \&& tar zxvf /mhash-0.9.9.9.tar.gz && cd mhash-0.9.9.9 && ./configure && make && make install && cd - / && rm -rf /mhash* \&& tar zxvf /mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8 && LD_LIBRARY_PATH=/usr/local/lib ./configure && make && make install && cd - / && rm -rf /mcrypt*
登录后复制

开始安装

使用./configure --help查看编译支持的选项。如果写了不支持的选项,如php7里不支持--with-mysql=mysqlnd会提示:

configure: WARNING: unrecognized options: --with-mysql
登录后复制
wget http://cn2.php.net/distributions/php-7.0.7.tar.bz2tar jxvf php-7.0.7.tar.bz2 cd php-7.0.7$ ./configure --prefix=/usr/local/php --with-config-file-scan-dir=/usr/local/php/etc/ --enable-inline-optimization --enable-opcache --enable-session --enable-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-sqlite3 --with-gettext --enable-mbregex --enable-mbstring --enable-xml --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-xmlrpc --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-curlwrappers --with-zlib --enable-zip --with-bz2 --with-gd --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-readline $ make$ make install
登录后复制

可选项:

--with-fpm-user=www --with-fpm-group=www
登录后复制

这里面开启了很多扩展。如果这时候忘了开启,以后还能加上吗?答案是可以的。以后只需要进入源码的ext目录,例如忘了pdo_mysql,进入ext/pdo_mysql,使用phpize工具,像安装普通扩展一样即可生成pdo_mysql.so。

关于:--enable-safe-mode

开启的话php可以执行一下系统函数,建议关闭(可搜索受此函数影响的php函数)

http://mirrors.aliyun.com/0
登录后复制

php7编译不用加这个配置。

编译比较耗内存和CPU。等待半小时左右,编译完成:

http://mirrors.aliyun.com/1
登录后复制

配置文件

需要从安装包里复制php.ini、php-fpm.conf到安装目录:

http://mirrors.aliyun.com/2
登录后复制

配置php.ini

http://mirrors.aliyun.com/3
登录后复制

配置php-fpm.conf

http://mirrors.aliyun.com/4
登录后复制

配置www.conf(在php-fpm.d目录下)

www.conf这是php-fpm进程服务的扩展配置文件:

http://mirrors.aliyun.com/5
登录后复制

保存配置文件后,检验配置是否正确的方法为:

http://mirrors.aliyun.com/6
登录后复制

如果出现诸如 test is successful 字样,说明配置没有问题。另外该命令也可以让我们知道php-fpm的配置文件在哪。

建立软连接:

http://mirrors.aliyun.com/7
登录后复制

或者将php编译生成的bin目录添加到当前Linux系统的环境变量中:

http://mirrors.aliyun.com/8
登录后复制

启动php-fpm

http://mirrors.aliyun.com/9
登录后复制

如果提示没有www用户(www.conf里填写了www而不是nobody),则新增:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup0
登录后复制

检测是否启动:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup1
登录后复制

查看php-fpm进程数:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup2
登录后复制

php-fpm操作汇总:

http://mirrors.aliyun.com/9         # php-fpm启动kill -INT `cat /usr/local/php/var/run/php-fpm.pid`      # php-fpm关闭kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`         #php-fpm平滑重启
登录后复制

重启方法二:

killall php-fpmhttp://mirrors.aliyun.com/9 &
登录后复制

如果无法平滑启动,那就终止进程id:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup5
登录后复制

安装Nginx

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup6
登录后复制

依赖:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup7
登录后复制

配置编译参数

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup8
登录后复制

配置ok:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup9
登录后复制

编译安装nginx

## CentOS 5wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo## CentOS 6wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo## CentOS 7wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo0
登录后复制

设置软连接:

## CentOS 5wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo## CentOS 6wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo## CentOS 7wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo1
登录后复制

检测nginx:

## CentOS 5wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo## CentOS 6wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo## CentOS 7wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo2
登录后复制

显示:

## CentOS 5wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo## CentOS 6wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo## CentOS 7wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo3
登录后复制

成功了。我们重新配置下nginx.conf:

## CentOS 5wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo## CentOS 6wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo## CentOS 7wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo4
登录后复制

配置localhost:

## CentOS 5wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo## CentOS 6wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo## CentOS 7wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo5
登录后复制
## CentOS 5wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo## CentOS 6wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo## CentOS 7wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo6
登录后复制

启动nginx:

## CentOS 5wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo## CentOS 6wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo## CentOS 7wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo7
登录后复制

重启:

## CentOS 5wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo## CentOS 6wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo## CentOS 7wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo8
登录后复制

停止:

## CentOS 5wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo## CentOS 6wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo## CentOS 7wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo9
登录后复制

如果提示80端口被占用了,可以使用ps aunx | grep 80查看。一般是apache占用了。可以使用:

yum clean allyum makecache0
登录后复制

禁止apache启动并关闭apache服务。

安装扩展

安装swoole

Swoole: PHP的异步、并行、高性能网络通信引擎

http://www.swoole.com/

yum clean allyum makecache1
登录后复制

安装redis

服务器端:

http://download.redis.io/releases/redis-3.2.0.tar.gz

yum clean allyum makecache2
登录后复制

默认编译完后在当前目录的src目录下。可以复制可执行文件到其他地方:

yum clean allyum makecache3
登录后复制

复制配置文件

yum clean allyum makecache4
登录后复制

或者安装的时候指定位置:

yum clean allyum makecache5
登录后复制

将Redis的命令所在目录添加到系统参数PATH中:

修改profile文件:

yum clean allyum makecache6
登录后复制

在最后行追加:

yum clean allyum makecache7
登录后复制

然后马上应用这个文件:

yum clean allyum makecache8
登录后复制

这样就可以直接调用redis-cli的命令了

客户端:

2.0安装

yum clean allyum makecache9
登录后复制

3.0安装

yum install -y gcc gcc-c++ make cmake bison autoconf wget lrzszyum install -y libtool libtool-ltdl-devel yum install -y freetype-devel libjpeg.x86_64 libjpeg-devel libpng-devel gd-develyum install -y python-devel  patch  sudo yum install -y openssl* openssl openssl-devel ncurses-develyum install -y bzip* bzip2 unzip zlib-develyum install -y libevent*yum install -y libxml* libxml2-develyum install -y libcurl* curl-devel yum install -y readline-devel0
登录后复制

需要先安装igbinary:

PECL :: Package :: igbinary

http://pecl.php.net/package/igbinary

yum install -y gcc gcc-c++ make cmake bison autoconf wget lrzszyum install -y libtool libtool-ltdl-devel yum install -y freetype-devel libjpeg.x86_64 libjpeg-devel libpng-devel gd-develyum install -y python-devel  patch  sudo yum install -y openssl* openssl openssl-devel ncurses-develyum install -y bzip* bzip2 unzip zlib-develyum install -y libevent*yum install -y libxml* libxml2-develyum install -y libcurl* curl-devel yum install -y readline-devel1
登录后复制
yum install -y gcc gcc-c++ make cmake bison autoconf wget lrzszyum install -y libtool libtool-ltdl-devel yum install -y freetype-devel libjpeg.x86_64 libjpeg-devel libpng-devel gd-develyum install -y python-devel  patch  sudo yum install -y openssl* openssl openssl-devel ncurses-develyum install -y bzip* bzip2 unzip zlib-develyum install -y libevent*yum install -y libxml* libxml2-develyum install -y libcurl* curl-devel yum install -y readline-devel2
登录后复制

安装memcache

yum install -y gcc gcc-c++ make cmake bison autoconf wget lrzszyum install -y libtool libtool-ltdl-devel yum install -y freetype-devel libjpeg.x86_64 libjpeg-devel libpng-devel gd-develyum install -y python-devel  patch  sudo yum install -y openssl* openssl openssl-devel ncurses-develyum install -y bzip* bzip2 unzip zlib-develyum install -y libevent*yum install -y libxml* libxml2-develyum install -y libcurl* curl-devel yum install -y readline-devel3
登录后复制

php7安装有兼容问题,从github上搜到了一个可用的:

git clone https://github.com/websupport-sk/pecl-memcache memcachecd memcachephpize./confihure## CentOS 5wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo## CentOS 6wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo## CentOS 7wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo0
登录后复制

安装memcached:

yum install -y gcc gcc-c++ make cmake bison autoconf wget lrzszyum install -y libtool libtool-ltdl-devel yum install -y freetype-devel libjpeg.x86_64 libjpeg-devel libpng-devel gd-develyum install -y python-devel  patch  sudo yum install -y openssl* openssl openssl-devel ncurses-develyum install -y bzip* bzip2 unzip zlib-develyum install -y libevent*yum install -y libxml* libxml2-develyum install -y libcurl* curl-devel yum install -y readline-devel3d
登录后复制

需要先安装:

yum install -y gcc gcc-c++ make cmake bison autoconf wget lrzszyum install -y libtool libtool-ltdl-devel yum install -y freetype-devel libjpeg.x86_64 libjpeg-devel libpng-devel gd-develyum install -y python-devel  patch  sudo yum install -y openssl* openssl openssl-devel ncurses-develyum install -y bzip* bzip2 unzip zlib-develyum install -y libevent*yum install -y libxml* libxml2-develyum install -y libcurl* curl-devel yum install -y readline-devel6
登录后复制

使用yum/apt-get安装php

如果只是想快速搭建开发环境,可以使用yum进行安装:

yum install -y gcc gcc-c++ make cmake bison autoconf wget lrzszyum install -y libtool libtool-ltdl-devel yum install -y freetype-devel libjpeg.x86_64 libjpeg-devel libpng-devel gd-develyum install -y python-devel  patch  sudo yum install -y openssl* openssl openssl-devel ncurses-develyum install -y bzip* bzip2 unzip zlib-develyum install -y libevent*yum install -y libxml* libxml2-develyum install -y libcurl* curl-devel yum install -y readline-devel7
登录后复制

使用yum search php可以查询到可以安装哪些php相关的扩展。

如果是ubuntu:

yum install -y gcc gcc-c++ make cmake bison autoconf wget lrzszyum install -y libtool libtool-ltdl-devel yum install -y freetype-devel libjpeg.x86_64 libjpeg-devel libpng-devel gd-develyum install -y python-devel  patch  sudo yum install -y openssl* openssl openssl-devel ncurses-develyum install -y bzip* bzip2 unzip zlib-develyum install -y libevent*yum install -y libxml* libxml2-develyum install -y libcurl* curl-devel yum install -y readline-devel8
登录后复制

需要下载 15.9 MB 的归档。

解压缩后会消耗 57.7 MB 的额外空间。

您希望继续执行吗? [Y/n]

php-pear包含pecl,php-dev包含phpize,pecl依赖phpize。

需要注意的是,使用yum安装的php,其配置文件位于:

yum install -y gcc gcc-c++ make cmake bison autoconf wget lrzszyum install -y libtool libtool-ltdl-devel yum install -y freetype-devel libjpeg.x86_64 libjpeg-devel libpng-devel gd-develyum install -y python-devel  patch  sudo yum install -y openssl* openssl openssl-devel ncurses-develyum install -y bzip* bzip2 unzip zlib-develyum install -y libevent*yum install -y libxml* libxml2-develyum install -y libcurl* curl-devel yum install -y readline-devel9
登录后复制

ubuntu与centos不一样,会分开存放php.ini到/etc/php7/cli/php.ini和/etc/php7/fpm/php.ini里。这个需要注意。

yum无法安装的扩展,可以使用pecl安装。由于pecl是需要编译的,所以需要先安装编译器:

tar zxvf /libmcrypt-2.5.8.tar.gz \&& cd /libmcrypt-2.5.8 && ./configure && make && make install && cd - / && rm -rf /libmcrypt* \&& tar zxvf /mhash-0.9.9.9.tar.gz && cd mhash-0.9.9.9 && ./configure && make && make install && cd - / && rm -rf /mhash* \&& tar zxvf /mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8 && LD_LIBRARY_PATH=/usr/local/lib ./configure && make && make install && cd - / && rm -rf /mcrypt*0
登录后复制

然后:

tar zxvf /libmcrypt-2.5.8.tar.gz \&& cd /libmcrypt-2.5.8 && ./configure && make && make install && cd - / && rm -rf /libmcrypt* \&& tar zxvf /mhash-0.9.9.9.tar.gz && cd mhash-0.9.9.9 && ./configure && make && make install && cd - / && rm -rf /mhash* \&& tar zxvf /mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8 && LD_LIBRARY_PATH=/usr/local/lib ./configure && make && make install && cd - / && rm -rf /mcrypt*1
登录后复制

pecl安装扩展完成后会提示添加so文件到php.ini。示例:

tar zxvf /libmcrypt-2.5.8.tar.gz \&& cd /libmcrypt-2.5.8 && ./configure && make && make install && cd - / && rm -rf /libmcrypt* \&& tar zxvf /mhash-0.9.9.9.tar.gz && cd mhash-0.9.9.9 && ./configure && make && make install && cd - / && rm -rf /mhash* \&& tar zxvf /mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8 && LD_LIBRARY_PATH=/usr/local/lib ./configure && make && make install && cd - / && rm -rf /mcrypt*2
登录后复制

添加示例:

tar zxvf /libmcrypt-2.5.8.tar.gz \&& cd /libmcrypt-2.5.8 && ./configure && make && make install && cd - / && rm -rf /libmcrypt* \&& tar zxvf /mhash-0.9.9.9.tar.gz && cd mhash-0.9.9.9 && ./configure && make && make install && cd - / && rm -rf /mhash* \&& tar zxvf /mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8 && LD_LIBRARY_PATH=/usr/local/lib ./configure && make && make install && cd - / && rm -rf /mcrypt*3
登录后复制

使用php -m可以查看安装的扩展。

信号管理

不重载配置启动新/旧工作进程

tar zxvf /libmcrypt-2.5.8.tar.gz \&& cd /libmcrypt-2.5.8 && ./configure && make && make install && cd - / && rm -rf /libmcrypt* \&& tar zxvf /mhash-0.9.9.9.tar.gz && cd mhash-0.9.9.9 && ./configure && make && make install && cd - / && rm -rf /mhash* \&& tar zxvf /mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8 && LD_LIBRARY_PATH=/usr/local/lib ./configure && make && make install && cd - / && rm -rf /mcrypt*4
登录后复制

从容关闭旧/新进程

tar zxvf /libmcrypt-2.5.8.tar.gz \&& cd /libmcrypt-2.5.8 && ./configure && make && make install && cd - / && rm -rf /libmcrypt* \&& tar zxvf /mhash-0.9.9.9.tar.gz && cd mhash-0.9.9.9 && ./configure && make && make install && cd - / && rm -rf /mhash* \&& tar zxvf /mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8 && LD_LIBRARY_PATH=/usr/local/lib ./configure && make && make install && cd - / && rm -rf /mcrypt*5
登录后复制

如果此时报错,提示还有进程没有结束就用下面命令先关闭旧/新工作进程,再关闭主进程号:

tar zxvf /libmcrypt-2.5.8.tar.gz \&& cd /libmcrypt-2.5.8 && ./configure && make && make install && cd - / && rm -rf /libmcrypt* \&& tar zxvf /mhash-0.9.9.9.tar.gz && cd mhash-0.9.9.9 && ./configure && make && make install && cd - / && rm -rf /mhash* \&& tar zxvf /mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8 && LD_LIBRARY_PATH=/usr/local/lib ./configure && make && make install && cd - / && rm -rf /mcrypt*6
登录后复制

升级、添加或删除模块时,我们需要停掉服务器

tar zxvf /libmcrypt-2.5.8.tar.gz \&& cd /libmcrypt-2.5.8 && ./configure && make && make install && cd - / && rm -rf /libmcrypt* \&& tar zxvf /mhash-0.9.9.9.tar.gz && cd mhash-0.9.9.9 && ./configure && make && make install && cd - / && rm -rf /mhash* \&& tar zxvf /mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8 && LD_LIBRARY_PATH=/usr/local/lib ./configure && make && make install && cd - / && rm -rf /mcrypt*7
登录后复制

MySQL

如果存在旧版本,需要先卸载旧版本。

使用下面的命令检查是否安装有MySQL Server

tar zxvf /libmcrypt-2.5.8.tar.gz \&& cd /libmcrypt-2.5.8 && ./configure && make && make install && cd - / && rm -rf /libmcrypt* \&& tar zxvf /mhash-0.9.9.9.tar.gz && cd mhash-0.9.9.9 && ./configure && make && make install && cd - / && rm -rf /mhash* \&& tar zxvf /mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8 && LD_LIBRARY_PATH=/usr/local/lib ./configure && make && make install && cd - / && rm -rf /mcrypt*8
登录后复制

有的话通过下面的命令来卸载掉

tar zxvf /libmcrypt-2.5.8.tar.gz \&& cd /libmcrypt-2.5.8 && ./configure && make && make install && cd - / && rm -rf /libmcrypt* \&& tar zxvf /mhash-0.9.9.9.tar.gz && cd mhash-0.9.9.9 && ./configure && make && make install && cd - / && rm -rf /mhash* \&& tar zxvf /mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8 && LD_LIBRARY_PATH=/usr/local/lib ./configure && make && make install && cd - / && rm -rf /mcrypt*9
登录后复制

安装

安装编译代码需要的包

configure: WARNING: unrecognized options: --with-mysql0
登录后复制

下载MySQL 5.6.14:

configure: WARNING: unrecognized options: --with-mysql1
登录后复制

编译安装

configure: WARNING: unrecognized options: --with-mysql2
登录后复制

编译的参数可以参考

http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html

整个过程需要30分钟左右……漫长的等待

配置MySQL

设置权限

使用下面的命令查看是否有mysql用户及用户组

configure: WARNING: unrecognized options: --with-mysql3
登录后复制

如果没有就创建

configure: WARNING: unrecognized options: --with-mysql4
登录后复制

修改/usr/local/mysql权限

configure: WARNING: unrecognized options: --with-mysql5
登录后复制

修改/usr/local/mysql权限

初始化配置

进入安装路径

configure: WARNING: unrecognized options: --with-mysql6
登录后复制

进入安装路径,执行初始化配置脚本,创建系统自带的数据库和表

configure: WARNING: unrecognized options: --with-mysql7
登录后复制

注:在启动MySQL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到则会搜索"$basedir/my.cnf",在本例中就是 /usr/local/mysql/my.cnf,这是新版MySQL的配置文件的默认位置!

注意:在CentOS 6.4版操作系统的最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。

在使用"yum update"更新系统后,需要检查下/etc目录下是否会多出一个my.cnf,如果多出,将它重命名成别的。否则,MySQL将使用这个配置文件启动,可能造成无法正常启动等问题。

启动MySQL

添加服务,拷贝服务脚本到init.d目录,并设置开机启动

configure: WARNING: unrecognized options: --with-mysql8
登录后复制

配置用户

MySQL启动成功后,root默认没有密码,我们需要设置root密码。

设置之前,我们需要先设置PATH,要不不能直接调用mysql

修改/etc/profile文件,在文件末尾添加

configure: WARNING: unrecognized options: --with-mysql9
登录后复制

关闭文件,运行下面的命令,让配置立即生效

wget http://cn2.php.net/distributions/php-7.0.7.tar.bz2tar jxvf php-7.0.7.tar.bz2 cd php-7.0.7$ ./configure --prefix=/usr/local/php --with-config-file-scan-dir=/usr/local/php/etc/ --enable-inline-optimization --enable-opcache --enable-session --enable-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-sqlite3 --with-gettext --enable-mbregex --enable-mbstring --enable-xml --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-xmlrpc --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-curlwrappers --with-zlib --enable-zip --with-bz2 --with-gd --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-readline $ make$ make install0
登录后复制

现在,我们可以在终端内直接输入mysql进入,mysql的环境了

执行下面的命令修改root密码

wget http://cn2.php.net/distributions/php-7.0.7.tar.bz2tar jxvf php-7.0.7.tar.bz2 cd php-7.0.7$ ./configure --prefix=/usr/local/php --with-config-file-scan-dir=/usr/local/php/etc/ --enable-inline-optimization --enable-opcache --enable-session --enable-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-sqlite3 --with-gettext --enable-mbregex --enable-mbstring --enable-xml --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-xmlrpc --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-curlwrappers --with-zlib --enable-zip --with-bz2 --with-gd --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-readline $ make$ make install1
登录后复制

若要设置root用户可以远程访问,执行

wget http://cn2.php.net/distributions/php-7.0.7.tar.bz2tar jxvf php-7.0.7.tar.bz2 cd php-7.0.7$ ./configure --prefix=/usr/local/php --with-config-file-scan-dir=/usr/local/php/etc/ --enable-inline-optimization --enable-opcache --enable-session --enable-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-sqlite3 --with-gettext --enable-mbregex --enable-mbstring --enable-xml --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-xmlrpc --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-curlwrappers --with-zlib --enable-zip --with-bz2 --with-gd --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-readline $ make$ make install2
登录后复制

红色的password为远程访问时,root用户的密码,可以和本地不同。

配置防火墙

防火墙的3306端口默认没有开启,若要远程访问,需要开启这个端口

打开/etc/sysconfig/iptables

在“-A INPUT –m state --state NEW –m tcp –p –dport 22 –j ACCEPT”,下添加:

wget http://cn2.php.net/distributions/php-7.0.7.tar.bz2tar jxvf php-7.0.7.tar.bz2 cd php-7.0.7$ ./configure --prefix=/usr/local/php --with-config-file-scan-dir=/usr/local/php/etc/ --enable-inline-optimization --enable-opcache --enable-session --enable-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-sqlite3 --with-gettext --enable-mbregex --enable-mbstring --enable-xml --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-xmlrpc --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-curlwrappers --with-zlib --enable-zip --with-bz2 --with-gd --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-readline $ make$ make install3
登录后复制

然后保存,并关闭该文件,在终端内运行下面的命令,刷新防火墙配置:

wget http://cn2.php.net/distributions/php-7.0.7.tar.bz2tar jxvf php-7.0.7.tar.bz2 cd php-7.0.7$ ./configure --prefix=/usr/local/php --with-config-file-scan-dir=/usr/local/php/etc/ --enable-inline-optimization --enable-opcache --enable-session --enable-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-sqlite3 --with-gettext --enable-mbregex --enable-mbstring --enable-xml --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-xmlrpc --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-curlwrappers --with-zlib --enable-zip --with-bz2 --with-gd --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-readline $ make$ make install4
登录后复制

OK,一切配置完毕,你可以访问你的MySQL了~

注意:

CentOS 7中默认使用Firewalld做防火墙,所以修改iptables后,在重启系统后,根本不管用。

Firewalld中添加端口方法如下:

wget http://cn2.php.net/distributions/php-7.0.7.tar.bz2tar jxvf php-7.0.7.tar.bz2 cd php-7.0.7$ ./configure --prefix=/usr/local/php --with-config-file-scan-dir=/usr/local/php/etc/ --enable-inline-optimization --enable-opcache --enable-session --enable-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-sqlite3 --with-gettext --enable-mbregex --enable-mbstring --enable-xml --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-xmlrpc --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-curlwrappers --with-zlib --enable-zip --with-bz2 --with-gd --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-readline $ make$ make install5
登录后复制

常见问题

1、编译PHP提示easy.h should be in <curl-dir>/include/curl/

如果是centos:

wget http://cn2.php.net/distributions/php-7.0.7.tar.bz2tar jxvf php-7.0.7.tar.bz2 cd php-7.0.7$ ./configure --prefix=/usr/local/php --with-config-file-scan-dir=/usr/local/php/etc/ --enable-inline-optimization --enable-opcache --enable-session --enable-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-sqlite3 --with-gettext --enable-mbregex --enable-mbstring --enable-xml --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-xmlrpc --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-curlwrappers --with-zlib --enable-zip --with-bz2 --with-gd --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-readline $ make$ make install6
登录后复制

如果是ubuntu:

wget http://cn2.php.net/distributions/php-7.0.7.tar.bz2tar jxvf php-7.0.7.tar.bz2 cd php-7.0.7$ ./configure --prefix=/usr/local/php --with-config-file-scan-dir=/usr/local/php/etc/ --enable-inline-optimization --enable-opcache --enable-session --enable-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-sqlite3 --with-gettext --enable-mbregex --enable-mbstring --enable-xml --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-xmlrpc --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-curlwrappers --with-zlib --enable-zip --with-bz2 --with-gd --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-readline $ make$ make install7
登录后复制

如果还是没有解决,直接编译curl:

wget http://curl.haxx.se/download/curl-7.37.0.tar.gztar zxvf curl-7.37.0.tar.gzcd curl-7.37.0../configure --prefix=/usr/local --enable-shared ## CentOS 5wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo## CentOS 6wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo## CentOS 7wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo0
登录后复制

以上就是CentOS下安装PHP7+Nginx+MySQL的方法详解的详细内容,更多请关注9543建站博客其它相关文章!

广告:SSL证书一年128.66元起,点击购买~~~

9543建站博客
一个专注于网站开发、微信开发的技术类纯净博客。

作者头像
admin创始人

肥猫,知名SEO博客站长,14年SEO经验。

上一篇:javascript怎么读中文
下一篇:如何搭建和使用Laravel

发表评论

关闭广告
关闭广告