centos下使用shell脚本自动安装程序

用shell安装程序非常方便,省得每一步都需要人为操作,在这里我自己尝试安装了PHP7到服务器,已经测试成功了我将我写的脚本分享出来,希望能帮助到一部分朋友!

#!/bin/bash
#PHP7.0安装脚本
#author Sindsun
#date 2019年4月9日13:39:45
#:set ff=unix



#先停止php-fpm
if [ -f "/etc/init.d/php-fpm" ]; then
	/etc/init.d/php-fpm stop
fi

service php-fpm stop

#添加新用户和组
groupadd nginx
useradd -g nginx nginx

#执行卸载
rm -rf /usr/local/php*
rm -rf /usr/bin/php*
rm -rf /usr/sbin/php*
rm -rf /var/lib/php*
rm -rf /usr/lib64/php*
rm -rf /usr/share/php*

#安装依赖
wget -P /usr/src http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
cd /usr/src
tar -zxvf /usr/src/libmcrypt-2.5.8.tar.gz
cd /usr/src/libmcrypt-2.5.8
./configure
make && make install

yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel

cd /usr/src/php
#编译php
/usr/src/php/configure --prefix=/usr/local/php7 \
--with-config-file-path=/usr/local/php7/etc \
--with-config-file-scan-dir=/usr/local/php7/etc/php.d \
--with-mcrypt=/usr/include \
--enable-mysqlnd \
--with-mysqli \
--with-pdo-mysql \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--with-gd \
--with-iconv \
--with-zlib \
--enable-xml \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--with-openssl \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--with-jpeg-dir \
--with-freetype-dir \
--enable-opcache



#安装
make && make install



#新建目录
mkdir /usr/local/php7/tmp
chmod -R 777 /usr/local/php7/tmp



#移动复制配置文件 
cp /usr/src/php/php.ini-dev /usr/local/php7/etc/php.ini

if [ -f "/etc/init.d/php-fpm" ]; then
	mv /etc/init.d/php-fpm /etc/init.d/php-fpm-20190409
fi
cp /usr/src/php/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf



#添加环境变量
echo 'export PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH' >> /etc/profile
source /etc/profile


#添加自启动
chkconfig --add php-fpm
chkconfig php-fpm on
chkconfig --list php-fpm


#启动服务
chmod 777 /etc/init.d/php-fpm
/etc/init.d/php-fpm start
/usr/local/nginx/sbin/nginx -s reload


版权声明: 此文为本站源创文章[或由本站编辑从网络整理改编],
转载请备注出处:
[狂码一生] https://www.sindsun.com/articles/23/107
[若此文确切存在侵权,请联系本站管理员进行删除!]


--THE END--