首页 > 代码库 > CentOS6.8编译安装Nginx1.10.2+MySQL5.7.16+PHP7.0.12

CentOS6.8编译安装Nginx1.10.2+MySQL5.7.16+PHP7.0.12

1.    下载

#MySQL下载地址

http://dev.mysql.com/downloads/mysql/

#Nginx下载地址

http://nginx.org/en/download.html

#PHP下载地址

http://php.net/downloads.php

使用WinSCP把下载好的压缩包上传到/usr/local/src目录

mysql-5.7.16.tar.gz nginx-1.10.2.tar.gz php-7.0.12.tar.gz

2.    安装

2.1   MySQL安装

#安装所需依赖

yum install gcc gcc-c++ cmakencurses ncurses-devel bison

#下载boost http://www.boost.org/users/download/

tar zxf boost_1_59_0.tar.gz

cp boost_1_59_0 /usr/local/boost

#创建运行用户

groupadd mysql

useradd -r -g mysql -s /bin/falsemysql

#编译安装

cmake .-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

       -DMYSQL_DATADIR=/usr/local/mysql/data \

       -DDOWNLOAD_BOOST=1 \

       -DWITH_BOOST=/usr/local/boost \

       -DDEFAULT_CHARSET=utf8mb4 \

       -DDEFAULT_COLLATION=utf8mb4_unicode_ci

make

make install

#更改权限

chown -R mysql /usr/local/mysql

chgrp -R mysql /usr/local/mysql

#初始化

cd /usr/local/mysql/bin

./mysqld --initialize--user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

#拷贝配置文件

mv /etc/my.cnf/etc/my.cnf.bak

cd /usr/local/mysql/support-files

cp my-default.cnf /etc/my.cnf

#启动和关闭

cd /usr/local/mysql/bin

./mysqld_safe --user=mysql

cd /usr/local/mysql/support-files

./mysql.server stop

#设置开机启动

cp support-files/mysql.server /etc/init.d/mysqld

chmod 755/etc/init.d/mysqld

chkconfig --add mysqld

chkconfig --level 345 mysqld on

 

service mysqld start

service mysqld stop

service mysqld restart

#修改环境变量

vi/etc/profile   

PATH=/usr/local/mysql/bin:$PATH

export PATH

source/etc/profile

#修改root密码

cd /usr/local/mysql/bin

./mysql -uroot-p

mysql>alter user ‘root‘@‘localhost‘ identified by ‘123456‘;

mysql>exit;

2.2   Nginx安装

安装pcre openssl zlib

#安装依赖

yum install perl(openssl需要)

#安装pcre

cd /usr/local/src

mkdir /usr/local/pcre

tar zxvf pcre-8.39.tar.gz

cd pcre-8.39

./configure --prefix=/usr/local/pcre

make

make install

#安装openssl

cd /usr/local/src

mkdir /usr/local/openssl

tar xvf openssl-1.1.0.tar.gz

cd openssl-1.1.0

./config --prefix=/usr/local/openssl

make

make install

#安装zlib

cd /usr/local/src

mkdir /usr/local/zlib

tar zxvf zlib-1.2.8.tar.gz

cd zlib-1.2.8

./configure --prefix=/usr/local/zlib

make

make install

#安装Nginx

#创建运行用户

groupadd www

useradd -g www www -s /bin/false

#编译安装

cd /usr/local/src

tar zxvf nginx-1.10.2.tar.gz

cd nginx-1.10.2

./configure --prefix=/usr/local/nginx --user=www--group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/src/openssl-1.1.0 --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.39

  make

make install

#测试配置文件是否正确

  /usr/local/nginx/sbin/nginx -t

#启动

/usr/local/nginx/sbin/nginx

2.3   PHP安装

#安装依赖

yum install libxml2 libxml2-devel curl-devel openjpeg openjpeg-devel openjpeg-libs libjpeg libpng freetype libjpeg-devel libpng-devel freetype-devel  mcrypt php-mcrypt libmcrypt libmcrypt-devel bzip2 bzip2-devel

#创建运行用户

groupadd -r php

useradd -r -gphp -s /bin/flase php

#编译安装

./configure--prefix=/usr/local/php --with-mcrypt=/usr/include --with-mhash --with-openssl--with-zlib --enable-zip --enable-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 --with-fpm-user=www --with-fpm-group=www --without-gdbm--disable-fileinfo --with-bz2 --enable-maintainer-zts --with-libdir=lib64

make

make install

#拷贝配置文件

cp php.ini-development /usr/local/php/etc/php.ini

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

cp /usr/local/php/etc/php-fpm.d/www.conf.default  /usr/local/php/etc/php-fpm.d/www.conf

cp -R /usr/local/src/php-7.0.12/sapi/fpm/php-fpm /etc/init.d/php-fpm

#启动
/etc/init.d/php-fpm

chkconfig --add php-fpm

chkconfig php-fpm on

#配置Nginx代理PHP实现访问

通过上面的操作,nginxphp-fpm服务都被我们跑起来了,但是php-fpm走的是127.0.0.1:9000,外网是无法访问的,而且我们也不可能直接通过php-fpm给外网提供服务,我们用nginx去代理9000端口执行php

实际上这个过程只需要对nginx进行配置即可,fpm已经在后台运行了,我们需要在nginx的配置文件中增加代理的规则,即可让用户在访问80端口,请求php的时候,交由后端的fpm去执行,并返回结果。

vi /usr/local/nginx/conf/nginx.conf

把前面的#注释符号去掉,把script改为$document_root最终如下:

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;

}

这样就OK了,重新载入nginx配置即可


CentOS6.8编译安装Nginx1.10.2+MySQL5.7.16+PHP7.0.12