centos编译安装php7.2 php-fpm.service - shell脚本

本文涉及的产品
云数据库 RDS SQL Server,独享型 2核4GB
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: php7.2 编译安装脚本
#!/bin/bash
yum install epel-release -y             # 安装扩展包并更新系统内核
yum list
yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel
                                                        # 安装php依赖组件(包含Nginx依赖)
cd /tmp
groupadd www                            # 创建一个 www 的组
useradd -g www www                      # 创建用户www   归属于 www组
yum install -y wget ; yum install -y star
                                                        # 安装wget 下载工具和star 解压缩工具
wget http://am1.php.net/distributions/php-7.2.1.tar.gz
tar xvf php-7.2.1.tar.gz                        # tar -xvf 是解压,-cvf 是创建压缩包
cd php-7.2.1
# 创建用户和组,并下载php安装包解压
cp -frp /usr/lib64/libldap* /usr/lib/
#### 编译安装 是一条命令的开始
./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mysqlnd-compression-support \
--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-intl \
--with-mcrypt \
--with-libmbfl \
--enable-ftp \
--with-gd \
--enable-gd-jis-conv \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--disable-fileinfo \
--enable-opcache \
--with-pear \
--enable-maintainer-zts \
--with-ldap=shared \
--without-gdbm
#### 编译安装 是一条命令结束
make -j 4 && 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
setphpini=`find / -name "php.ini"`                              # 定义一个变量名字为:setphpini他的值为一个 find 查找文件 php.ini 命令返回的结果
sed -i "s/expose_php.*/expose_php\=off/g" $setphpini
                                                                                # sed -i 修改文件,匹配前一个字符串及其后面所有字符串,修改为后一个; \ 转译特殊字符   $setphpini 是一个文件路径变量
sed -i "s/short_open_tag.*/short_open_tag\=ON/g" $setphpini
sed -i "s/max_execution_time.*/max_execution_time\=300/g" $setphpini
sed -i "s/max_input_time.*/max_input_time\=300/g" $setphpini
sed -i "s/memory_limit.*/memory_limit\=128M/g" $setphpini
sed -i "s/post_max_size.*/post_max_size\=30M/g" $setphpini
sed -i "s/date.timezone.*/date.timezone\=Asia\/Shanghai/g" $setphpini
sed -i "s/memory_limit.*/memory_limit\=128M/g" $setphpini
sed -i "s/mbstring.func_overload.*/mbstring.func_overload\=2/g" $setphpini
NR=`cat -n $setphpini | grep "mbstring.func_overload" | awk -F" " '{print $1}' | sed "s/ //g"`
                                                                                # 定义行号变量 NR  ; grep匹配字符串所在行, 打印第一列,删除空格
sed -i "$NR a\extension = "/usr/local/php/lib/php/extensions/no-debug-zts-20170718/ldap.so"" $setphpini
                                                                                # 写入一个字符串, 在行 $NR 的  a\ 下一行写入 、
NR=`cat -n $setphpini | grep "\[opcache" | awk -F" " '{print $1}' | sed "s/ //"`
sed -i "$NR a\zend_extension=/usr/local/php/lib/php/extensions/no-debug-zts-20170718/opcache.so" $setphpini 
sed -i "s/opcache.max_accelerated_files.*/opcache.max_accelerated_files\=4000/g" $setphpini
sed -i "s/opcache.revalidate_freq.*/opcache.revalidate_freq\=60/g" $setphpini
sed -i "s/opcache.fast_shutdown.*/opcache.fast_shutdown\=1/g" $setphpini
sed -i "s/opcache.enable_cli.*/opcache.enable_cli\=1/g" $setphpini
sed -i "s/disable_functions.*/disable_functions\=passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthrug" $setphpini
 NR=`cat -n $setphpini | grep disable_functions | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR a\listen = /var/run/www/php-cgi.sock " $setphpini
############################
wwwconf=`find / -name "www.conf" | grep "usr"` ; echo "修改配置文件:"$wwwconf
############################
NR=`cat -n $wwwconf | grep "listen \= " | awk -F" " '{print $1}' | sed "s/ //g"`
                                                                                # cat -n 查看文件显示行号,  awk 字段处理打印第一列为行号
sed -i "$NR s/listen.*/listen \= \/var\/run\/www\/php-cgi.sock/g" $wwwconf
                                                                                # 获取到行号,sed -i 指定行号的内容进行修改
NR=`cat -n $wwwconf | grep "listen.owner = www" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR a\listen.owner = www" $wwwconf      # sed -i 在指定行号$NR的 a\  的下一行插入字符串
 
NR=`cat -n $wwwconf | grep "listen.group = www" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR a\listen.group = www"  $wwwconf
NR=`cat -n $wwwconf | grep "listen.mode =" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR a\listen.mode = 0660" $wwwconf 
NR=`cat -n $wwwconf | grep "listen.allowed_clients" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR a\listen.allowed_clients = 127.0.0.1" $wwwconf 
NR=`cat -n $wwwconf | grep "listen.backlog" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR a\listen.backlog = -1" $wwwconf 
NR=`cat -n $wwwconf | grep "pm.max_children =" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR s/pm.max_children \=.*/pm.max_children \= 180/g" $wwwconf 
NR=`cat -n $wwwconf | grep "pm.start_servers =" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR s/pm.start_servers \=.*/pm.start_servers \= 50/g" $wwwconf 
NR=`cat -n $wwwconf | grep "pm.min_spare_servers =" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR s/pm.min_spare_servers \=.*/pm.min_spare_servers \= 50/g" $wwwconf 
NR=`cat -n $wwwconf | grep "pm.max_spare_servers =" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR s/pm.max_spare_servers \=.*/pm.max_spare_servers \= 180/g" $wwwconf 
NR=`cat -n $wwwconf | grep "request_terminate_timeout =" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR a\request_terminate_timeout = 120" $wwwconf 
                                                                                # $NR 在制定行,  a 是下一行插入字符串
NR=`cat -n $wwwconf | grep "request_slowlog_timeout =" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR a\request_slowlog_timeout = 50" $wwwconf 
NR=`cat -n $wwwconf | grep "slowlog =" | awk -F" " '{print $1}' | sed "s/ //g"` ; 
sed -i "$NR a\slowlog = var/log/slow.log" $wwwconf 
mkdir /var/run/www/
chown -R www:www /var/run/www                   # 创建php-cgi.sock存放目录
NR=`cat -n /usr/local/php/etc/php-fpm.conf | grep "pid =" | awk -F" " '{print $1}' | sed "s/ //g"`
sed -i "$NR a\pid = /usr/local/php/var/run/php-fpm.pid" /usr/local/php/etc/php-fpm.conf
echo -e "
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
" > /usr/lib/systemd/system/php-fpm.service
systemctl enable php-fpm.service
systemctl restart php-fpm.service
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
23小时前
|
Java Shell Perl
使用shell脚本给日志文件瘦身
使用shell脚本给日志文件瘦身
|
3天前
|
运维 Java 应用服务中间件
Tomcat安装shell脚本
Tomcat安装shell脚本
16 7
|
3天前
|
运维 应用服务中间件 Shell
Nginx安装与虚拟主机配置shell脚本
Nginx安装与虚拟主机配置shell脚本
8 0
|
16天前
|
Shell
shell脚本for循环复杂用法
shell脚本for循环复杂用法
26 5
|
16天前
|
Shell
Shell脚本中的`case`语句
Shell脚本中的`case`语句
19 5
|
16天前
|
Shell
在Shell脚本中,使用`if`语句进行复杂的条件判断
在Shell脚本中,使用`if`语句进行复杂的条件判断
16 2
|
17天前
|
数据采集 JavaScript 前端开发
Shell脚本自动抢购火车票
Shell脚本自动抢购火车票
16 3
|
18天前
|
Unix Shell Linux
【Shell】Shell脚本入门
【Shell】Shell脚本入门
36 0
|
19天前
|
监控 Shell Linux
Shell脚本基础
Shell脚本基础
20 9
|
19天前
|
监控 Shell
Shell脚本实战教学
Shell脚本实战教学
15 5

相关产品

  • 云迁移中心