LNMP项目部署

LNMP项目部署

介绍

项目的生命周期

  • 策划:老板+产品+UI设计
  • 实施:前端开发(客户端页面)+后端开发(ava php python等)+测试
  • 上线:运维
  • 维护:运维
  • 结束

运维工作内容

  • 项目策划,实施之初,进行准备工作,学习对应架构和方案
  • 服务器上搭建代码版本控制器
  • 为测试人员搭建测试环境
  • 部署项目上线
  • 项目后期维护

分布式集群

  • 集群:多台服务器在一起作同样的事

  • 分布式 :多台服务器在一起作不同的事

  • 常用架构

    • 负债均衡LB
    • 高可用HA
    • 数据库主从复制M-S
    • 读写分离R-W
    • 缓存中间件:memcached、Redis
    • 非关系型数据库:mongodb

在这里插入图片描述

项目背景

  • 年份:2021
  • 发布产品类型:互联网动态站点 社区论坛 商城 社交类站点
  • 用户数量:100-500
  • PV:页面访问数量,点击量,1000-3000(24小时访问次数总和)
  • QPS:并发量,吞吐量,5-10(每秒访问查询次数)
    • 计算:pv/时间 = qps
    • 压测:使用ab等并发测试软件,在规定时间发送一定的请求数量
  • TPS:每秒事务次数,5-10
  • RPS:每秒请求次数,5-10
  • DAU:每日活跃用户数,日活数,10-50

软件架构

  • C/S client/server
  • B/S browser/server

不管是C还是B,都是属于前端客户端

运维人员主要负责和管理的是server端,也统称为服务器端

  • LAMP:Linux+Apache+MySQL+PHP
  • LNMP:Linux+Nginx+MySQL+PHP
  • LNMPA:Linux+Nginx+MySQL+PHP+Apache
  • LNMT:Linux+Nginx+MySQL+Tomcat

在这里插入图片描述

环境准备

最小化安装centOs6.9

安装vim
[root@server02 ~]# yum install -y vim
已加载插件:fastestmirror
设置安装进程
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
 Eg. Invalid release/repo/arch combination/
removing mirrorlist with no valid mirrors: /var/cache/yum/x86_64/6/base/mirrorlist.txt
错误:Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again

报错:Cannot retrieve repository metadata (repomd.xml) for repository: base.

原因:CentOS6已经在2020年11月30日停止维护了。centos官方停止了对centos6的所有更新,并且下架了包括官方所有的centos6源,目前阿里、163、清华等centos6源已无法使用

解决:如下

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
vi /etc/yum.repos.d/CentOS-Base.repo
#编写
[centos-office]
name=centos-office
failovermethod=priority
baseurl=https://vault.centos.org/6.10/os/x86_64/
gpgcheck=1
gpgkey=https://vault.centos.org/6.10/os/x86_64/RPM-GPG-KEY-CentOS-6

yum list
yum install -y vim

配置vim
echo "set nu" >> /root/.vimrc
echo "set ts=4" >> /root/.vimrc

sed -i "8calias grep='grep --color'" /root/.bashrc
source /root/.bashrc

关闭防火墙
service iptables stop
chkconfig iptables off

setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config

修改主机名
vim /etc/sysconfig/network
#修改为
HOSTNAME=server01
su

域名解析
vim /etc/hosts
#追加
192.168.139.128 server01.lnmp.com server01

时间同步
yum -y install ntp
service ntpd start
chkconfig ntpd on
ntpdate cn.ntp.org.cn

LNMP部署

MySQL安装

编译参数的说明

编译参数说明
-DCMAKE_INSTALL_PREFIX安装到的软件目录
-DMYSQL_DATADIR数据文件存储的路径
-DSYSCONFDIR配置文件路径 (my.cnf)
-DENABLED_LOCAL_INFILE=1使用localmysql客户端的配置
-DWITH_PARTITION_STORAGE_ENGINE使mysql支持分表
-DEXTRA_CHARSETS安装支持的字符集
-DDEFAULT_CHARSET默认字符集使用 这里配置为utf8mb4
-DDEFAULT_COLLATION连接字符集
-DWITH_SSL开启mysql的ssl使用

初始化参数说明

初始化参数说明
–basedir安装到的软件目录
–datadir数据文件存储路径
–usermysql使用的用户

脚本安装及其初始化

[root@server01 ~]# yum install -y lrzsz
[root@server01 ~]# mkdir /root/soft
[root@server01 ~]# cd /root/soft
[root@server01 soft]# rz
#传入mysql-5.6.33.tar.gz软件包

[root@server01 ~]# vim mysql_install.sh

#!/bin/bash
#源码编译安装MySQL
mysql_install() {
	#1、创建用户
`id mysql` &>/dev/null
[ $? -ne 0 ] && useradd -s /sbin/nologin -M mysql
#2、解决依赖
yum install -y cmake ncurses-devel
#3、编译安装
cd /root/soft
tar zxvf mysql-5.6.33.tar.gz
cd mysql-5.6.33
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_SSL=bundled
make && make install
#配置文件
rm -rf /etc/my.cnf
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
#授权并初始化数据库
chown -R mysql:mysql /usr/local/mysql
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
#配置服务、自启动和环境变量
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
service mysqld start
chkconfig --add mysqld
echo 'PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile
source /etc/profile
#删除匿名用户
#设置root域名的密码
rpm -qa|grep expect
if [ $? -ne 0 ];then
   yum -y install expect
fi
#导入环境变量PATH
export PATH=/usr/local/mysql/bin:$PATH
#初始化root密码 删除匿名用户
echo '#!/usr/bin/expect
set timeout 60
spawn mysql_secure_installation
expect {
"enter for none" { send "\r"; exp_continue}
"Y/n" { send "Y\r" ; exp_continue}
"password" { send "123456\r"; exp_continue}
"Cleaning up" { send "\r"}
}
interact ' > mysql_secure_installation.exp
chmod +x mysql_secure_installation.exp
./mysql_secure_installation.exp
}
#脚本开始时间
start_time=`date +%s`
#执行的脚本代码
mysql_install
#脚本结束时间
end_time=`date +%s`
#脚本执行花费时间
const_time=$((end_time-start_time))
echo 'Take time is: '$const_time's'

[root@server01 ~]# sh mysql_install.sh 

Nginx安装

介绍
官网

http://nginx.org/

在这里插入图片描述

功能
  • web服务器 httpd http协议

同类的web服务器软件:apache,nginx(俄罗斯),IIS(微软 fastcgi),lighttpd(德国)

  • 代理服务器 反向代理
  • 邮箱代理服务器 IMAP POP3 SMTP
  • 负载均衡功能 LB loadblance
特点(优点)
  • 高可靠:稳定性高,一个master多个worker,master进程用于管理调度请求分发到哪一个worker进程,worker进程用于响应请求。当其中一个worker进程出现问题,master会调度其他worker进程
  • 热部署 :(1)平滑升级 ;(2)可以快速重载配置
  • 高并发:可以同时响应更多的请求 ,达到几万的并发量,基于事件epoll模型
  • 响应快:尤其在处理静态文件上,响应速度很快 ,内核基于sendfile机制
  • 低消耗:cpu和内存占用低,建立开销1w个请求 ,内存只消耗2-3MB
  • 分布式支持 :反向代理,七层负载均衡
安装
  • 编译参数说明
参数作用
–prefix编译安装到的软件目录
–userworker进程运行用户
–groupworker进程运行用户组
–with-http_ssl_module支持https,需要pcel-devel依赖
–with-http_stub_status_module基本状态信息显示,查看请求数、连接数等
–with-http_realip_module定义客户端地址和端口为header头信息
用于反向代理后的真实IP获取
[root@server01 ~]# cd /root/soft/
[root@server01 soft]# rz
#传入下载好的 nginx-1.14.2软件包
[root@server01 soft]# tar -xzf nginx-1.14.2.tar.gz 
[root@server01 soft]# ls
mysql-5.6.33         mysql_secure_installation.exp  nginx-1.14.2.tar.gz
mysql-5.6.33.tar.gz  nginx-1.14.2
[root@server01 nginx-1.14.2]# useradd -s /sbin/nologin -M www
[root@server01 nginx-1.14.2]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module

报错:./configure: error: the HTTP rewrite module requires the PCRE library.

原因:缺少pcre-devel依赖库

解决:yum install -y pcre-devel

[root@server01 nginx-1.14.2]# yum install -y pcre-devel
[root@server01 nginx-1.14.2]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module

报错:./configure: error: SSL modules require the OpenSSL library.

原因:缺少openssl-devel依赖库

解决:yum install -y openssl-devel

[root@server01 nginx-1.14.2]# yum install -y openssl-devel
[root@server01 nginx-1.14.2]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

[root@server01 nginx-1.14.2]# make && make install
[root@server01 nginx-1.14.2]# cd /usr/local/nginx/
[root@server01 nginx]# pwd
/usr/local/nginx

脚本安装(提前将软件包下载到/root/soft):

#!/bin/bash
#编译安装Nginx
nginx_install(){
#创建软件运行用户
`id www` &>>/dev/null
if [ $? -ne 0 ];then
   useradd -s/sbin/nologin -M www
fi
#安装依赖
yum -y install pcre-devel zlib-devel openssl-devel
#编译安装
cd /root/soft
tar xvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module && make && make install
}
#脚本开始时间
start_time=`date +%s`
#执行的脚本代码
nginx_install
#脚本结束时间
end_time=`date +%s`
#脚本执行花费时间
const_time=$((end_time-start_time))
echo 'Take time is: '$const_time's'
初始化
[root@server01 nginx-1.14.2]# cd /usr/local/nginx/
[root@server01 nginx]# ls
conf  html  logs  sbin
[root@server01 nginx]# cd sbin/
[root@server01 sbin]# ls
nginx
目录作用
conf配置文件
html网站根目录
logs日志
sbin可执行文件 [软件的启动,停止,重启等]
启动nginx
[root@server01 sbin]# ./nginx 
[root@server01 sbin]# ss -tnalp|grep nginx
LISTEN     0      128                       *:80                       *:*      users:(("nginx",34295,6),("nginx",34296,6))
[root@server01 sbin]# ps -ef |grep nginx
root   34295     1 0 17:57 ?  00:00:00 nginx: master process ./nginx
www    34296 34295 0 17:57 ?  00:00:00 nginx: worker process
root   34304  3419 0 17:57 pts/0 00:00:00 grep --color nginx

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pvRlavDz-1633274276799)(…/%E5%9B%BE%E7%89%87%E6%94%BE%E7%BD%AE%E7%82%B9/image-20211002180101979.png)]

参数介绍(#后面的了解即可,不常用)
[root@server01 sbin]# ./nginx -h
nginx version: nginx/1.14.2
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
  -?,-h         : this help 帮助
  -v            : show version and exit #版本查看
  -V            : show version and configure options then exit查看版本和配置选项
  -t            : test configuration and exit 检测配置文件语法
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing #在配置测试期间禁止显示非错误信息
  -s signal     : send signal to a master process: stop, quit, reopen, reload  stop强制退出  quit优雅的退出  reopen重开日志   reload重载配置
  -p prefix     : set prefix path (default: /usr/local/nginx/) #设置nginx目录
  -c filename   : set configuration file (default: conf/nginx.conf) #指定启动使用的配置文件
  -g directives : set global directives out of configuration file
服务配置
[root@server01 ~]# cd /etc/init.d/
[root@server01 init.d]# rz
#传入已经下载的nginx脚本
[root@server01 init.d]# chmod +x nginx 

开启
[root@server01 init.d]# service nginx start
[root@server01 init.d]# chkconfig --add nginx
[root@server01 init.d]# chkconfig nginx on

PHP安装

介绍
  • PHP: Hypertext Preprocessor,超文本预处理器

    • HTML:超文本标记语言
    • HTTP:超文本传输协议
  • 页面分类:

    • 静态页面 一般普通访问到的页面

    • 动态页面 用户可以和服务器进行交互页面

    • 执行动态页面,需要和服务器进行交互,使用后端语言进行开发,php可实现该功能

在这里插入图片描述

  • PHP是一种通用开源脚本语言,混合了C、Java、Perl以及PHP自创的语法,主要适用于Web开发

  • PHP是将程序嵌入到HTML(标准通用标记语言下的一个应用)文档中去执行,执行效率比完全生成HTML标记的CGI要高许多

  • PHP还可以执行编译后代码,编译可以达到加密和优化代码运行,使代码运行更快

  • PHP-FPM(FastCGI Process Manager:FastCGI进程管理器)。PHP-FPM提供了更好的PHP进程管理方式,可以有效控制内存和进程、可以平滑重载PHP配置,在./configure的时候带 –enable-fpm参数即可开启PHP-FPM

安装
[root@server01 init.d]# cd /root/soft/
[root@server01 soft]# rz
[root@server01 soft]# ls
mysql-5.6.33  mysql-5.6.33.tar.gz  mysql_secure_installation.exp  nginx-1.14.2  nginx-1.14.2.tar.gz  php-7.2.12.tar.gz
[root@server01 soft]# tar -xzf php-7.2.12.tar.gz 
[root@server01 soft]# cd php-7.2.12

解决依赖(可忽略下文因依赖报错的部分)
[root@server01 php-7.2.12]# yum -y install libxml2-devel libjpeg-devel libpng-devel freetype-devel curl-devel openssl-devel

配置
[root@server01 php-7.2.12]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts

报错:configure: error: libxml2 not found. Please check your libxml2 installation.

原因:缺少依赖库libxml2

解决:yum install -y libxml2-devel

[root@server01 php-7.2.12]# yum install -y libxml2-devel
[root@server01 php-7.2.12]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts

报错:configure: error: cURL version 7.10.5 or later is required to compile php with cURL support

原因:缺少curl依赖库

解决:yum install -y curl-devel

[root@server01 php-7.2.12]# yum install -y curl-devel
[root@server01 php-7.2.12]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts

报错:configure: error: jpeglib.h not found.

原因:缺少libjpeg依赖库

解决:yum install -y libjpeg-devel

[root@server01 php-7.2.12]# yum install -y libjpeg-devel
[root@server01 php-7.2.12]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts

报错:configure: error: png.h not found.

原因:缺少libpng依赖库

解决:yum install -y libpng-devel

[root@server01 php-7.2.12]# yum install -y libpng-devel
[root@server01 php-7.2.12]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts

报错:configure: error: freetype-config not found.

原因:缺少freetype依赖库

解决:yum install -y freetype-devel

[root@server01 php-7.2.12]# yum install -y freetype-devel
[root@server01 php-7.2.12]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts

编译安装
[root@server01 php-7.2.12]# make && make install

[root@server01 php-7.2.12]# cd /usr/local/php/
[root@server01 php]# ls
bin  etc  include  lib  php  sbin  var
目录名称作用
binphp相关命令目录,php 、phpize、php-config在源码编译扩展时用
etc配置文件
includephp默认类库
libphp第三方扩展类库
phpman文档文件
sbinphp-fpm执行文件
varlog日志目录 ;run运行目录 ;保存pid文件
初始化
使配置文件生效
[root@server01 php]# cd etc
[root@server01 etc]# ls
php-fpm.conf.default  php-fpm.d
[root@server01 etc]# cp php-fpm.conf.default php-fpm.conf
[root@server01 etc]# cp php-fpm.d/www.conf.default php-fpm.d/www.conf
[root@server01 etc]# ls
php-fpm.conf  php-fpm.conf.default  php-fpm.d
[root@server01 etc]# cp /root/soft/php-7.2.12/php.ini-development /usr/local/php/etc/php.ini
#配置文件说明
php.ini			默认php配置文件
php-fpm.conf	php-fpm相关的配置 

启动php
[root@server01 etc]# cd ../sbin/
[root@server01 sbin]# ./php-fpm

选项说明
[root@server01 sbin]# ./php-fpm -h
Usage: php-fpm [-n] [-e] [-h] [-i] [-m] [-v] [-t] [-p <prefix>] [-g <pid>] [-c <file>] [-d foo[=bar]] [-y <file>] [-D] [-F [-O]]
  -c <path>|<file> Look for php.ini file in this directory
  -n               No php.ini file will be used
  -d foo[=bar]     Define INI entry foo with value 'bar'
  -e               Generate extended information for debugger/profiler
  -h               This help
  -i               PHP information
  -m               Show compiled in modules
  -v               Version number
  -p, --prefix <dir>
                   Specify alternative prefix path to FastCGI process manager (default: /usr/local/php).
  -g, --pid <file>
                   Specify the PID file location.
  -y, --fpm-config <file>
                   Specify alternative path to FastCGI process manager config file.
  -t, --test       Test FPM configuration and exit
  -D, --daemonize  force to run in background, and ignore daemonize option from config file
  -F, --nodaemonize
                   force to stay in foreground, and ignore daemonize option from config file
  -O, --force-stderr
                   force output to stderr in nodaemonize even if stderr is not a TTY
  -R, --allow-to-run-as-root
                   Allow pool to run as root (disabled by default)

添加到启动服务中
[root@server01 php-7.2.12]# cp /root/soft/php-7.2.12/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@server01 php-7.2.12]# chmod +x /etc/init.d/php-fpm
[root@server01 php-7.2.12]# chkconfig --add php-fpm
[root@server01 php-7.2.12]# chkconfig --list

添加环境变量
[root@server01 php-7.2.12]# echo 'PATH=/usr/local/php/bin:$PATH' >> /etc/profile
[root@server01 php-7.2.12]# source /etc/profile

上述步骤均可使用脚本代替

#!/bin/bash
php_install(){
#php编译安装
#和nginx使用相同的用户,如果没有就创建
`id www` &> /dev/null
[ $? -ne 0 ] && useradd -s /sbin/nologin -M www
#解决依赖
yum -y install libxml2-devel libjpeg-devel libpng-devel freetype-devel curl-devel openssl-devel
#解压
tar xvf php-7.2.12.tar.gz
cd php-7.2.12
#编译安装php
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts && make && make install
#配置文件初始化
cp php.ini-development /usr/local/php/etc/php.ini
#php-fpm服务配置文件
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
#php-fpm服务子配置文件
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
#配置服务及其环境变量
cp /root/soft/php-7.2.12/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
service php-fpm start
chkconfig --add php-fpm
echo 'PATH=/usr/local/php/bin:$PATH' >> /etc/profile
}
#脚本开始时间
start_time=`date +%s`
#执行的脚本代码
php_install
#脚本结束时间
end_time=`date +%s`
#脚本执行花费时间
const_time=$((end_time-start_time))
echo 'Take time is: '$const_time's'
Nginx+php-fpm配置
编写测试文件
[root@server01 php-7.2.12]#  vim /usr/local/nginx/html/index.php
<?php
	phpinfo();

修改配置文件
[root@server01 php-7.2.12]# vim /usr/local/nginx/conf/nginx.conf

 41         #access_log  logs/host.access.log  main;
 42 root html; 第一步:把root变量提升上层
 43         location / {
 44             #root   html; 这里的root需要被注释掉
 45             index  index.html index.htm;
 46         }
 47 
 48         #error_page  404              /404.html;
 49 
 50         # redirect server error pages to the static page /50x.html
 51         #
 52         error_page   500 502 503 504  /50x.html;
 53         location = /50x.html {
 54             root   html;
 55         }
 56 
 57         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
 58         #
 59         #location ~ \.php$ {
 60         #    proxy_pass   http://127.0.0.1;
 61         #}
 62 
 63         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 64         #
 65         location ~ \.php$ { 第二步:该段解注释
 66         #    root           html; 默认使用上层的root变量,这里也要注释掉
 67             fastcgi_pass   127.0.0.1:9000;
 68             fastcgi_index  index.php;
 69             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 第三步:把script修改为$document_root 
 70             include        fastcgi_params;
 71         } 注意,不要忘记最后这个括号
 72 
root@server01 php-7.2.12]# service nginx configtest
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@server01 php-7.2.12]# service nginx reload
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
重新载入 nginx:                                           [确定]

测试

在这里插入图片描述

  • 5
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值