环境
CentOS 6.7 64位
安装包
OpenResty1.9.7.4源码包
下载地址:https://openresty.org/download/openresty-1.9.7.4.tar.gz
PHP 7.0.5源码包
下载地址:http://cn2.php.net/get/php-7.0.5.tar.gz/from/this/mirror
MySQL源码包
下载地址:http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.11.tar.gz
工具
Command Line
方法/步骤
安装MySQL 5.7.11
准备工作
安装编译工具:
yum install gcc-c++ cmake
安装Boost(从MySQL5.7.5开始,需要Boost):
下载地址:
http://120.52.73.48/jaist.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
解压缩并复制软件包(无需安装)
tar zxvf boost_1_59_0.tar.gz
cp -r boost_1_59_0 /usr/local
添加MySQL用户和所属组
groupadd mysql
useradd -r -g mysql mysql
安装MySQL
解压并进入软件包
tar zxvf mysql-5.7.11.tar.gz
cd mysql-5.7.11
编译安装
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql5711 -DWITH_BOOST=/usr/local/boost_1_59_0
make && make install
初始化MySQL
cd /usr/local/mysql5711
chown -R mysql .
chgrp -R mysql .
bin/mysqld --initialize --user=mysql
注意,最后一条命令会生成root用户的默认密码
“ A temporary password is generated for root@localhost: CdMdXdI-6!&P”
添加MySQL服务并启动MySQL
cp support-files/mysql.server /etc/init.d/mysqld
service mysqld start
用系统生成的密码登录MySQL,并修改密码为空
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
bin/mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY '';
安装PHP 7.0.5
安装PHP
安装依赖:
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql-devel pcre-devel libxslt-devel curl-devel openssl-devel
解压并进入软件包:
tar xvzf php-7.0.5.tar.gz
cd php-7.0.5
依次执行下面两条命令编译安装:
./configure --prefix=/usr/local/php705 --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip
make && make install
复制出配置文件
cp /usr/local/php705/etc/php-fpm.conf.default /usr/local/php705/etc/php-fpm.conf
cp /usr/local/php705/etc/php-fpm.d/www.conf.default /usr/local/php705/etc/php-fpm.d/www.conf
cp /root/software/php-7.0.5/php.ini-production /usr/local/php705/lib/php.ini
启动php-fpm
/usr/local/php705/sbin/php-fpm
若无报错,则说明启动成功
安装memcache扩展
下载php7专用扩展包:
https://codeload.github.com/websupport-sk/pecl-memcache/zip/php7
解压并进入软件包:
unzip pecl-memcache-php7.zip
cd pecl-memcache-php7
开始安装:
/usr/local/php705/bin/phpize
./configure --with-php-config=/usr/local/php705/bin/php-config
make && make install
修改php.ini
vim /usr/local/php705/lib/php.ini
#加入下面这行
extension=memcache.so
检查是否成功
/usr/local/php705/bin/php -m
#若有memcache,则说明安装成功
安装OpenResty 1.9.7.4
安装依赖:
yum install readline-devel pcre-devel openssl-devel
解压并进入软件包:
tar xvzf openresty-1.9.7.4.tar.gz
cd openresty-1.9.7.4
依次执行下面两条命令编译安装:
./configure --prefix=/usr/local/openresty1974
gmake && gmake install
启动nginx
/usr/local/openresty1974/nginx/sbin/nginx
若无报错,则说明启动成功
配置Nginx
打开配置文件
vim /usr/local/openresty1974/nginx/conf/nginx.conf
修改web根目录
#找到这段配置代码:
location / {
root html;
index index.html index.htm;
}
#其中,html为web根目录,改为自己定义的路径
location / {
root /root/workspace;
index index.php index.html index.htm;
}
支持PHP。
#找到这段配置代码:
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
去掉注释,改为
location ~ \.php$ {
root /root/workspace;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /root/workspace$fastcgi_script_name;
include fastcgi_params;
}
配置虚拟主机。
#在配置文件最后一个大括号(})的上一行插入下面一条命令:
include vhost/vhost_*.conf;
#保存并退出nginx.conf。
mkdir vhost
vim vhost/vhost_pay.v1game.v1cn.conf
#加入以下内容:
server {
listen 80;
server_name pay.v1game.v1cn;
location / {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /root/workspace/gplatform/website$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
if (!-f $request_filename ) {
rewrite ^/(.*) /bootstrap.php?var=$1 break;
}
}
location ~ \.php$ {
rewrite /(.*)\.php$ /$1 redirect;
}
}
原文链接:http://straiway.sinaapp.com/2016/06/01/coding/linux/bulit-openresty-nginx-php-7-php-fpm-mysql5-7-environment-on-centos-6-7.html
来源:https://www.douban.com/note/561547702/