Shell PHP7 install 脚本
Bash由自由软件基金会,Inc.版权所有(C) 1989-2011。
描述
- Bash是一种与sh兼容的命令语言解释器,它执行从标准输入或文件中读取的命令。Bash还合并了Korn和C shell (ksh和csh)的有用特性。
- Bash旨在成为IEEE POSIX规范(IEEE标准)的Shell和实用程序部分的一致实现1003.1)。在默认情况下,Bash可以配置为符合posix的。
sh 脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
#!/bin/bash mkdir -p /AutoMount/{ISO,Image,Lemp/PHP/Logs,temp} temp=/AutoMount/temp LP=/AutoMount/Lemp/PHP Logs=/AutoMount/Lemp/PHP/Logs PHP=/usr/local/php7 mysqlsock=/var/lib/mysql/mysql.sock User=www Group=www libzip=$(ls $temp |grep '^libzip' | grep 'tar.gz') libmcrypt=$(ls $temp |grep '^libmcrypt' | grep 'tar.gz') mhash=$(ls $temp |grep '^mhash' | grep 'tar.gz') mcrypt=$(ls $temp |grep '^mcrypt' | grep 'tar.gz') php=$(ls $temp |grep '^php' | grep 'tar.gz') cat << EOF `echo -e '\e[32m#------------------------------------------------------------------------------------------------\e[m'` `echo -e '\e[32m# \e[m'` `echo -e '\e[32m# 1. PHP-7.3.* “Automatically compile the installation script” \e[m'` `echo -e '\e[32m# 2. ! Note that the script must be run as root \e[m'` `echo -e '\e[32m# 3. Scripts support the RHEL/ContOS 7.4/5/6 system,Install using CD as local yum source \e[m'` `echo -e '\e[32m# 4. By default, scripts automatically download the required software packages from the we \e[m'` `echo -e '\e[32m# 5. If you are unable to connect to the Internet; \e[m'` `echo -e '\e[32m# please download the following packages to the directory in advance:'$temp' \e[m'` `echo -e '\e[32m# 6. Before compiling PHP \e[m'` `echo -e '\e[32m# The following software needs to be installed in advance and can be used: \e[m'` `echo -e '\e[32m# a. 36mlibzip-1.2, libmcrypt-2.5.8.tar.gz, mhash-0.9.9.9, libmcrypt-2.5.8 \e[m'` `echo -e '\e[32m# \e[m'` `echo -e '\e[32m#------------------------------------------------------------------------------------------------\e[m'` EOF mkdir -p /AutoMount/{ISO,Image,temp} && mkdir -p /etc/yum.repos.d/Backup && mv -f /etc/yum.repos.d/*.repo /etc/yum.repos.d/Backup/ mount /dev/sr0 /AutoMount/Image/ >> $Logs/log.log 2>&1 echo -e "[Local]\nname=Local\nbaseurl=file:///AutoMount/Image\nenabled=1\ngpgcheck=0\n" > /etc/yum.repos.d/Local.repo && yum clean all >> $Logs/log.log 2>&1 echo -e '\e[36mPlease select whether to install RHEL, CentOS common toolkits and softwar [ Yy|Nn ]\e[m' && read -p ": " InstallTools case $InstallTools in Y|y) yum install vim bash-completion net-tools wget mlocate yum-utils chrony showmount bzip2.x86_6 elinks -y --disablerepo=* --enablerepo=Local >> $Logs/InstallTools.log 2>&1 if [ $? -eq 0 ]; then echo -e '\e[36m[ successful ]\e[m install RHEL, CentOS common toolkits and software' else echo -e '\e[31m[ Failure ]\e[m install RHEL, CentOS common toolkits and software check the log: \e[4;31m'$Logs/InstallTools.log'\e[m' fi ;; N|n) yum install wget -y --disablerepo=* --enablerepo=Local >> $Logs/InstallTools.log 2>&1 ;; *) yum install wget -y --disablerepo=* --enablerepo=Local >> $Logs/InstallTools.log 2>&1 ;; esac ping -c 2 baidu.com >> $Logs/download_php.log 2>&1 if [ $? -eq 0 ]; then if [ ! -e $temp/libzip-1.2*tar.gz ]; then wget -P $temp/ https://libzip.org/download/libzip-1.2.0.tar.gz --output-file=$Logs/download_libzip.log >> $Logs/download_libzip.log 2>&1 if [ -e $temp/libzip-1.2*tar.gz ]; then libzip=$(ls $temp |grep '^libzip' | grep 'tar.gz') && echo -e '\e[32m[ successful ] \e[4;36m'$libzip'\e[m download complete' else echo -e '\e[33m[ Warning ]\e[m Not find,Please download the \e[4;33mlibzip-1.2*tar.gz\e[m to directory: \e[4m'$temp'\e[m' && exit 1 fi fi if [ ! -e $temp/libmcrypt-2*tar.gz ]; then wget -P $temp/ https://newcontinuum.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz --output-file=$Logs/download_libmcrypt.log >> $Logs/download_libmcrypt.log 2>&1 if [ -e $temp/libmcrypt-2*tar.gz ]; then libmcrypt=$(ls $temp |grep '^libmcrypt' | grep 'tar.gz') && echo -e '\e[32m[ successful ] \e[4;36m'$libmcrypt'\e[m download complete' else echo -e '\e[33m[ Warning ]\e[m Not find,Please download the \e[4;33mlibmcrypt-2*tar.gz\e[m to directory: \e[4m'$temp'\e[m' && exit 1 fi fi if [ ! -e $temp/mhash*.tar.gz ]; then wget -P $temp/ https://cfhcable.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz --output-file=$Logs/download_mhash.log >> $Logs/download_mhash.log 2>&1 if [ -e $temp/mhash*.tar.gz ]; then mhash=$(ls $temp |grep '^mhash' | grep 'tar.gz') && echo -e '\e[32m[ successful ] \e[4;36m'$mhash'\e[m download complete' else echo -e '\e[33m[ Warning ]\e[m Not find,Please download the \e[4;33mmhash*.tar.gz\e[m to directory: \e[4m'$temp'\e[m' && exit 1 fi fi if [ ! -e $temp/mcrypt-2*tar.gz ]; then wget -P $temp/ https://astuteinternet.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz --output-file=$Logs/download_mcrypt.log >> $Logs/download_mcrypt.log 2>&1 if [ -e $temp/mcrypt-2*tar.gz ]; then mcrypt=$(ls $temp |grep '^mcrypt' | grep 'tar.gz') && echo -e '\e[32m[ successful ] \e[4;36m'$mcrypt'\e[m download complete' else echo -e '\e[33m[ Warning ]\e[m Not find,Please download the \e[4;33mmcrypt-2*tar.gz\e[m to directory: \e[4m'$temp'\e[m' && exit 1 fi fi if [ ! -e $temp/php*.tar.gz ]; then wget -P $temp/ http://php.net/distributions/php-7.3.1.tar.gz --output-file=$Logs/download_php.log >> $Logs/download_php.log 2>&1 if [ -e $temp/php*.tar.gz ]; then php=$(ls $temp |grep '^php' | grep 'tar.gz') && echo -e '\e[32m[ successful ] \e[4;36m'$php'\e[m download complete' else echo -e '\e[33m[ Warning ]\e[m Not find,Please download the \e[4;33mphp-7.3.*tar.gz\e[m to directory: \e[4m'$temp'\e[m' && exit 1 fi fi else if [ ! -e $temp/libzip-1.2*tar.gz ]; then echo -e '\e[33m[ Warning ]\e[m Not find,Please download the \e[4;33mibzip-1.2.*.tar.gz\e[m to directory: \e[4m'$temp'\e[m' && exit 1 fi if [ ! -e $temp/libmcrypt-2*tar.gz ]; then echo -e '\e[33m[ Warning ]\e[m Not find,Please download the \e[4;33mlibmcrypt-2.5.*.tar.gz\e[m to directory: \e[4m'$temp'\e[m' && exit 1 fi if [ ! -e $temp/mhash*.tar.gz ]; then echo -e '\e[33m[ Warning ]\e[m Not find,Please download the \e[4;33mmhash-*.tar.gz\e[m to directory: \e[4m'$temp'\e[m' && exit 1 fi if [ ! -e $temp/mcrypt-2*tar.gz ]; then echo -e '\e[33m[ Warning ]\e[m Not find,Please download the \e[4;33mmcrypt-2.6.*.tar.gz\e[m to directory: \e[4m'$temp'\e[m' && exit 1 fi if [ ! -e $temp/php-7.3*.tar.gz ]; then echo -e '\e[33m[ Warning ]\e[m Not find,Please download the \e[4;33mphp-7.3.*.tar.gz\e[m to directory: \e[4m'$temp'\e[m' && exit 1 fi fi yum install autoconf mlocate gcc libxml2 libxml2-devel openssl openssl-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gcc gcc-c++ gd php-gd bison libXpm libXpm-devel patch compat* gettext gettext-devel gtk2-devel gtk3-devel ncurses ncurses-devel policycoreutils policycoreutils-devel php-mysql psmisc -y >> $Logs/RequiresPackage.log 2>&1 if [ $? -eq 0 ]; then echo -e '\e[36m[ successful ]\e[m PHP Required Dependency Package installation complete' if [ "$User" != "`id -un $User 2> /dev/null`" ]; then useradd -r -c "$User Server" -M -d $PHP -s /sbin/nologin $User >> $Logs/user.log 2>&1 && mkdir -p $PHP && chown -R $User:$User $PHP if [ "$User" = "`id -un $User 2> /dev/null`" ]; then echo -e '\e[36m[ successful ]\e[m Add PHP \e[36m'$User'\e[m user for PHP-7 successfully' else echo -e '\e[31m[ Failure ]\e[m Failed to create '$User', please check the log:\e[4;31m'$Logs'/user.log\e[m' && exit 1 fi else echo -e '\e[33m[ Warning ]\e[m Warning that the specified \e[33m'$User'\e[m user already exists,Skip this step' fi if [ -e $temp/libzip*.tar.gz ]; then tar -zxf $temp/libzip*.tar.gz -C $LP >> $Logs/tar_libzip.log 2>&1 && cd $LP/libzip* if [ $LP/libzip* = `pwd` ]; then echo -e '\e[36m[ successful ]\e[m 1.1 \e[4;36m'$libzip'\e[m File unzip complete' && ./configure >> $Logs/libzip_configure.log 2>&1 if [ $? -eq 0 ]; then echo -e '\e[36m[ successful ]\e[m 1.2 \e[4;36m'$libzip'\e[m source code package compilation complete' make >> $Logs/libzip_make.log 2>&1 && make install >> $Logs/libzip_install.log 2>&1 if [ $? -eq 0 ]; then echo -e '\e[36m[ successful ]\e[m 1.3 \e[4;36m'$libzip'\e[m compilation and installation complete' else echo -e '\e[31m[ Failure ]\e[m 1.3 \e[4;31m'$libzip'\e[m compilation failure,check the log \e[4;31m'$Logs'/(libzip_make.log、libzip_install.log)\e[m' && exit 1 fi else echo -e '\e[31m[ Failure ]\e[m 1.2 \e[4;31m'$libzip'\e[m compilation failure,check the log \e[4;31m'$Logs'/libzip_configure.log\e[m' && exit 1 fi else echo -e '\e[31m[ Failure ]\e[m 1.1 Failed to extract the file check the log: \e[4;31m'$Logs/tar_libzip.log'\e[m' && exit 1 fi fi if [ -e $temp/libmcrypt*.tar.gz ]; then tar -zxf $temp/libmcrypt*.tar.gz -C $LP >> $Logs/tar_libmcrypt.log 2>&1 && cd $LP/libmcrypt* if [ $LP/libmcrypt* = `pwd` ]; then echo -e '\e[36m[ successful ]\e[m 2.1 \e[4;36m'$libmcrypt'\e[m File unzip complete' && ./configure >> $Logs/libmcrypt_configure.log 2>&1 if [ $? -eq 0 ]; then echo -e '\e[36m[ successful ]\e[m 2.2 \e[4;36m'$libmcrypt'\e[m source code package compilation complete' make >> $Logs/libmcrypt_make.log 2>&1 && make install >> $Logs/libmcrypt_install.log 2>&1 if [ $? -eq 0 ]; then # echo -e "/usr/local/lib64/\n/usr/local/lib\n/usr/lib\n/usr/lib64" >>/etc/ld.so.conf # ldconfig -v >> $Logs/ld.so.conf.log 2>&1 echo -e '\e[36m[ successful ]\e[m 2.3 \e[4;36m'$libmcrypt'\e[m compilation and installation complete' else echo -e '\e[31m[ Failure ]\e[m 2.3 \e[4;31m'$libmcrypt'\e[m compilation failure,check the log \e[4;31m'$Logs'/(libmcrypt_make.log、libmcrypt_install.log)\e[m' && exit 1 fi else echo -e '\e[31m[ Failure ]\e[m 2.2 \e[4;31m'$libmcrypt'\e[m compilation failure,check the log \e[4;31m'$Logs'/libmcrypt_configure.log\e[m' && exit 1 fi else echo -e '\e[33m[ Failure ]\e[m 2.1 Failed to extract the file check the log: \e[4;33m'$Logs/tar_libmcrypt.log'\e[m' && exit 1 fi fi if [ -e $temp/mhash*.tar.gz ]; then tar -zxf $temp/mhash*.tar.gz -C $LP >> $Logs/tar_mhash.log 2>&1 && cd $LP/mhash* if [ $LP/mhash* = `pwd` ]; then echo -e '\e[36m[ successful ]\e[m 3.1 \e[4;36m'$mhash'\e[m File unzip complete' && ./configure >> $Logs/mhash_configure.log 2>&1 if [ $? -eq 0 ]; then echo -e '\e[36m[ successful ]\e[m 3.2 \e[4;36m'$mhash'\e[m source code package compilation complete' make >> $Logs/mhash_make.log 2>&1 && make install >> $Logs/mhash_install.log 2>&1 if [ $? -eq 0 ]; then echo -e '\e[36m[ successful ]\e[m 3.3 \e[4;36m'$mhash'\e[m compilation and installation complete' else echo -e '\e[31m[ Failure ]\e[m 3.3 \e[4;31m'$mhash'\e[m compilation failure,check the log \e[4;31m'$Logs'/(mhash_make.log、mhash_install.log)\e[m' && exit 1 fi else echo -e '\e[31m[ Failure ]\e[m 3.2 \e[4;31m'$mhash'\e[m compilation failure,check the log \e[4;31m'$Logs'/mhash_configure.log\e[m' && exit 1 fi else echo -e '\e[31m[ Failure ]\e[m 3.1 Failed to extract the file check the log: \e[4;31m'$Logs/tar_mhash.log'\e[m' && exit 1 fi fi if [ -e $temp/mcrypt*.tar.gz ]; then tar -zxf $temp/mcrypt*.tar.gz -C $LP >> $Logs/tar_mcrypt.log 2>&1 && cd $LP/mcrypt* if [ $LP/mcrypt* = `pwd` ]; then echo -e '\e[36m[ successful ]\e[m 4.1 \e[4;36m'$mcrypt'\e[m File unzip complete' && echo -e "/usr/local/lib64/\n/usr/local/lib\n/usr/lib\n/usr/lib64" >>/etc/ld.so.conf && ldconfig -v >> $Logs/ld.so.conf.log 2>&1 && ./configure >> $Logs/mcrypt_configure.log 2>&1 if [ $? -eq 0 ]; then echo -e '\e[36m[ successful ]\e[m 4.2 \e[4;36m'$mcrypt'\e[m source code package compilation complete' make >> $Logs/mcrypt_make.log 2>&1 && make install >> $Logs/mcrypt_install.log 2>&1 if [ $? -eq 0 ]; then echo -e '\e[36m[ successful ]\e[m 4.3 \e[4;36m'$mcrypt'\e[m compilation and installation complete' else echo -e '\e[31m[ Failure ]\e[m 4.3 \e[4;31m'$mcrypt'\e[m compilation failure,check the log \e[4;31m'$Logs'/(mcrypt_make.log、mcrypt_install.log)\e[m' && exit 1 fi else echo -e '\e[31m[ Failure ]\e[m 4.2 \e[4;31m'$mcrypt'\e[m compilation failure,check the log \e[4;31m'$Logs'/mcrypt_configure.log\e[m' && exit 1 fi else echo -e '\e[31m[ Failure ]\e[m 4.1 Failed to extract the file check the log: \e[4;31m'$Logs'/tar_mcrypt.log\e[m' && exit 1 fi fi if [ -e $temp/php-7*.tar.gz ]; then tar -zxf $temp/php-7*.tar.gz -C $LP >> $Logs/tar_php.log 2>&1 && cd $LP/php-7* && \cp -Rf ./ext/zip/lib/zipconf.h /usr/local/include if [ $LP/php-7* = `pwd` ]; then echo -e '\e[36m[ successful ]\e[m 5.1 \e[4;36m'$php'\e[m File unzip complete' ./buildconf --force >> $Logs/php_buildconf.log 2>&1 && ./configure --with-fpm-user=$User --with-fpm-group=$Group --prefix=$PHP --exec-prefix=$PHP --bindir=$PHP/bin --sbindir=$PHP/sbin --includedir=$PHP/include --libdir=$PHP/lib/php --mandir=$PHP/php/man --with-config-file-path=$PHP/etc --with-config-file-scan-dir=$PHP/etc/php-fpm.d --with-mysql-sock=$mysqlsock --with-mhash --with-openssl --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --with-gd --with-iconv --with-zlib --with-libzip --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-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 --without-gdbm >> $Logs/configure.log 2>&1 if [ $? -eq 0 ]; then echo -e '\e[36m[ successful ]\e[m 5.2 \e[4;36m'$php'\e[m source code package compilation complete' make >> $Logs/php_make.log 2>&1 && make install >> $Logs/php_install.log 2>&1 if [ $? -eq 0 ]; then echo -e '\e[36m[ successful ]\e[m 5.3 \e[4;36m'$php'\e[m compilation and installation complete' rm -rf /etc/php.ini && \cp -Rf ./php.ini-production $PHP/etc/php.ini && ln -s /usr/local/php7/etc/php.ini /etc/php.ini && sed -i '/^;cgi.fix_pathinfo=1/a\cgi.fix_pathinfo=0' /etc/php.ini && sed -i '/^;cgi.force_redirect = 1/a\cgi.force_redirect = 0' /etc/php.ini && \cp -Rf $PHP/etc/php-fpm.conf.default $PHP/etc/php-fpm.conf && sed -i -e 's@^;pid = run/php-fpm.pid@pid = run/php-fpm.pid@' $PHP/etc/php-fpm.conf && \cp -Rf $PHP/etc/php-fpm.d/www.conf.default $PHP/etc/php-fpm.d/www.conf && ln -s /usr/local/php7/sbin/php-fpm /usr/sbin/php-fpm && if [ $? -eq 0 ]; then echo -e '\e[36m[ successful ]\e[m 5.4 \e[4;36mPHP(Hypertext Preprocessor)\e[m configuration and optimization complete' fi else echo -e '\e[31m[ Failure ]\e[m 5.3 \e[4;31m'$php'\e[m compilation failure,check the log \e[4;31m'$Logs'/(php_make.log、php_nstall.log)\e[m' && exit 1 fi else echo -e '\e[31m[ Failure ]\e[m 5.2 \e[4;31m'$php'\e[m compilation failure,check the log \e[4;31m'$Logs'/php_configure.log\e[m' && exit 1 fi else echo -e '\e[31m[ Failure ]\e[m 5.1 Failed to extract the file check the log: \e[4;31m'$Logs'/tar_php.log\e[m' && exit 1 fi fi else echo -e '\e[31m[ Failure ]\e[m Dependency packages required by PHP-7,Please check the log \e[4;31m'$Logs'/RequiresPackage.log\e[m' && exit 1 fi cat > /usr/lib/systemd/system/php-fpm.service <<EOF [Unit] Description=The PHP FastCGI Process Manager After=syslog.target network.target [Service] Type=simple PIDFile=$PHP/var/run/php.pid ExecStart=$PHP/sbin/php-fpm --nodaemonize --fpm-config $PHP/etc/php-fpm.conf ExecReload=/bin/kill -USR2 $MAINPID ExecStop=/bin/kill -INT $MAINPID [Install] WantedBy=multi-user.target EOF systemctl daemon-reload >> $Logs/service.log 2>&1 && systemctl enable php-fpm.service >> $Logs/service.log 2>&1 && systemctl restart php-fpm.service >> $Logs/service.log 2>&1 if [ active = "`systemctl is-active php-fpm.service 2> /dev/null`" ]; then firewall-cmd --add-service={http,https} >>$Logs/firewall.log 2>&1 firewall-cmd --permanent --add-service={http,https} >>$Logs/firewall.log 2>&1 setenforce 0 >>$Logs/firewall.log 2>&1 && sed -i -e 's@^SELINUX=enforcing@SELINUX=disabled@' /etc/selinux/config echo -e '\e[36m[ Welcome to PHP! ]\e[m Congratulations PHP-7 is ready to use' else echo -e '\e[33m[ Failure ]\e[m \e[33mPHP\e[m service start failed,check the log \e[31m'$Logs'/service.log\e[m' && exit 1 fi |