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 | #!/bin/bash php_data_dir="/data/web" php_user="php" DownloadFileDir="$(pwd)" InstallLogFile="$(pwd)/install.log" tmp="n" fun_failed() { printf "%-59s" "$1" echo -e "[\033[31mFAILED\033[0m]" echo -e "\033[31msee ./install.log for detail\033[0m" exit 1 } fun_ok() { printf "%-59s" "$1" echo -e "[\033[32m OK \033[0m]" } while [[ $# != 0 ]];do case $1 in -y) tmp="y" shift 1 ;; -u) php_user=$2 shift 2 ;; -d) php_data_dir=$2 shift 2 ;; -h) echo "usage: script that auto install php-fpm srv" echo " -y :answer to any question which would be asked is yes" echo " -u <user> :set user the process running by [default: $php_user]" echo " -d <data dir> :set data dir that web page data [default: $php_data_dir]" exit ;; *) echo "wrong option" exit esac done echo "=========================" echo "user: $php_user" echo "datadir: $php_data_dir" if [[ $tmp = "n" ]];then read -p "Confirm set is right [y/n]: " tmp [[ $tmp != "y" ]] && exit 2 fi echo ss -tnpl | grep -q php-fpm [[ $? -eq 0 ]] && fun_failed "php-fpm process is running:" useradd -r $php_user -s /sbin/nologin &>> $InstallLogFile [[ $? -ne 0 && $? -ne 9 ]] && fun_failed "useradd $php_user:" # $? -eq 0 || $? -eq 9 ͨȡfun_ok "useradd $php_user:" yum install -y gcc bison bison-devel zlib-devel \ mhash-devel openssl openssl-devel libcurl-devel \ bzip2-devel readline-devel libedit-devel sqlite-devel \ libxml2 libxml2-devel curl-devel libjpeg-devel \ libpng-devel freetype-devel mcrypt libmcrypt-devel &>> $InstallLogFile || fun_failed "install rpm:" fun_ok "install rpm:" #[[ -e php-5.6.30.tar.gz ]] && mv php-5.6.30.tar.gz php-5.6.30.tar.gz.bak-$(date +%M) #wget http://hk1.php.net/get/php-5.6.30.tar.gz/from/this/mirror -O php-5.6.30.tar.gz || fun_failed "wget php:" #wget https://andyblog.org/files/20170625-9671764068.gz -O php-5.6.30.tar.gz &>> $InstallLogFile || fun_failed "wget php:" #fun_ok "wget php:" [[ -e php-5.6.30 ]] && mv php-5.6.30 php-5.6.30.bak-$(date +%M) tar xf php-5.6.30.tar.gz &>> $InstallLogFile || fun_failed "tar xf php:" fun_ok "tar xf php:" [[ -e /usr/local/php ]] && fun_failed "bin dir has exist:" mkdir -p /usr/local/php/run/lock mkdir -p /var/log/php-fpm chown -R $php_user /var/log/php-fpm cd php-5.6.30 ./configure \ --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/conf \ --with-config-file-scan-dir=/usr/local/php/conf/php.d \ --sysconfdir=/usr/local/php/conf \ --datadir=/usr/local/php/data \ --enable-inline-optimization \ --disable-rpath \ --enable-shared \ --enable-opcache \ --enable-fpm \ --enable-mbstring \ --enable-bcmath \ --enable-soap \ --enable-pcntl \ --enable-shmop \ --enable-sysvmsg \ --enable-sysvsem \ --enable-sysvshm \ --enable-sockets \ --enable-xml \ --enable-mbregex \ --enable-ftp \ --enable-session \ --enable-gd-native-ttf \ --enable-zip \ --with-fpm-user=$php_user \ --with-fpm-group=$php_user \ --with-mysql=mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-gettext \ --with-iconv \ --with-mcrypt \ --with-mhash \ --with-openssl \ --with-libxml-dir \ --with-curl \ --with-zlib \ --with-bz2 \ --with-gd \ --with-readline \ --with-xmlrpc \ --with-jpeg-dir \ --with-freetype-dir &>> $InstallLogFile || fun_failed "configure php-fpm:" fun_ok "configure php-fpm:" CpuCount=$(cat /proc/cpuinfo| grep "processor"| wc -l) make -j $CpuCount &>> $InstallLogFile || fun_failed "make php-fpm:" fun_ok "make php-fpm:" make install &>> $InstallLogFile || fun_failed "make install:" fun_ok "make install:" cd /usr/local/php/conf rm -rf php-fpm* php* \cp $DownloadFileDir/file/php-fpm.ini php.ini \cp $DownloadFileDir/file/php-fpm.conf php-fpm.conf sed -i "s#^user.*#user = $php_user#g" php-fpm.conf &>> $InstallLogFile sed -i "s#^group.*#group = $php_user#g" php-fpm.conf &>> $InstallLogFile cat > /etc/profile.d/php.sh<< EOF PATH=/usr/local/php/bin:/usr/local/php/sbin:\$PATH export PATH EOF source /etc/profile.d/php.sh \cp $DownloadFileDir/file/php-fpm.init /etc/init.d/php-fpm chmod +x /etc/init.d/php-fpm chkconfig --add php-fpm chkconfig php-fpm on mkdir -p $php_data_dir cat > $php_data_dir/phpinfo.php << EOF <?php phpinfo(); EOF \cp $DownloadFileDir/file/php-fpm.tz.php $php_data_dir/tz.php chown -R $php_user $php_data_dir \cp $DownloadFileDir/file/php-fpm.logrotate /etc/logrotate.d/php-fpm fun_ok "config php-fpm:" service php-fpm start &>> $InstallLogFile || fun_failed "start php-fpm:" fun_ok "start php-fpm:" sleep 1 ss -tnlp | grep php &>> $InstallLogFile || fun_failed "listen port:" fun_ok "listen port:" cd $DownloadFileDir rm -rf php-5.6.30* &>> $InstallLogFile || fun_failed "rm download file:" fun_ok "rm download file:" echo -e "\033[32mservice php-fpm started \033[0m" echo echo "bindir: /usr/local/php" echo "service: /etc/init.d/php-fpm" echo "datadir: $php_data_dir" echo "logdir: /var/log/php-fpm" echo "change nginx conf and visit http://localhost/tz.php" echo |
---|