Shell centos7.4整合安装Nginx+Mysql+php脚本

浏览:178
jackios 2020-05-21 16:51

这个脚本在centos.7.4环境下面使用 ,先安装nginx再安装php,因为php进程拥有者是nginx用户,所以先安装nginx再安装php,最后安装mysql。

[root@localhost ~]# cat test.sh 

#!/bin/bash

#mysql define variables

mysql_ver="5.5.60"

mysql_soft="mysql-${mysql_ver}.tar.gz"

mysql_dir="mysql-5.5.60"

mysql_url="http://mirrors.163.com/mysql/Downloads/MySQL-5.5/$mysql_soft"

mysql_create_sql="create database wordpress charset utf8;"

mysql_grant_sql="grant all on wordpress.* to 'wordpress'@'192.168.179.99' identified by '123456';"

mysql_exec="/usr/local/mysql55/bin/mysql"

 

#php define variables

php_ver="5.6.8"

php_dir="/usr/local/php"

php_url="http://mirrors.sohu.com/php/php-${php_ver}.tar.bz2" 

 

#nginx wordpress define variables

nginx_src="/usr/src"

nginx_dir="/usr/local/nginx"

nginx_url="http://nginx.org/download"

nginx_ver="1.16.0"

nginx_soft="nginx-${nginx_ver}.tar.gz"

nginx_args="--prefix=${nginx_dir} --user=nginx --group=nginx --with-http_stub_status_module"

 

word_press_name="blog.wordpress.com"

word_press_conf="blog.wordpress.com.conf"

word_press_dir="wordpress"

 

 

if [ $(id -u) -ne 0 ];then       ###只?root?禄搂驴???懈媒疟戮拢隆

        echo -e "\033[32myou must run scripts as root Sorry exit!!"

        exit 1

fi

 

##########################

#禄貌茫?使???拢卢??麓贸篓??

#if [ `whoami` != "root" ];then

#echo " only root can run it"

#exit 1

#fi

 

 

function nginx_install(){

yum install gcc pcre pcre-devel zlib zlib-devel wget make openssl-devel net-tools -y

sed -i 's/enforcing/disabled/g' /etc/selinux/config

systemctl stop firewalld.service

 

cd $nginx_src

wget -c $nginx_url/$nginx_soft

tar xf $nginx_soft

cd nginx-${nginx_ver}

 

useradd -s /sbin/nologin nginx

./configure $nginx_args

 

make&&make install

$nginx_dir/sbin/nginx

ps -ef | grep nginx | grep -v grep

 

echo -e "\033[32m-----------------config Nginx vhost now------------------------------\033[0m"

sleep 3s

 

#config Nginx vhost 

cd $nginx_dir/conf

\cp nginx.conf nginx.conf.bak

\cp $nginx_src/nginx-${nginx_ver}/conf/nginx.conf $nginx_dir/conf

 

sed -i -e '/#/d' -e '/^$/d' -e '/server/,$d'  nginx.conf

echo -e "include /usr/local/nginx/conf/vhosts/*.conf; \n}" >>nginx.conf

 

tar -xf  $nginx_src/wordpress-4.9.4-zh_CN.tar.gz -C $nginx_dir/html

chown -R  nginx:nginx $nginx_dir/html/$word_press_dir

 

mkdir -p vhosts

cd vhosts

 

cat >$word_press_conf<<EOF

server {

        listen       80;

        server_name  $word_press_name;

        location / {

            root   html/$word_press_dir;

            index index.php index.html index.htm;

        }

        

error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

       

location ~ \.php$ {

root html/wordpress;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;

  }

}

EOF

 

 

$nginx_dir/sbin/nginx -t

$nginx_dir/sbin/nginx -s reload

echo -e "\033[32myou configure informations blow..............wordpress dir previelege............................\033[0m"

ls -ld $nginx_dir/html/$word_press_dir

echo "\033[32m................................nginx config ......................................\033[0m"

cat  $nginx_dir/conf/nginx.conf

echo -e "\033[32m................................virtue host config......................................\033[0m"

cat  $nginx_dir/conf/vhosts/$word_press_conf

 

}

 

 

 

function php_install(){

yum -y install gd curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel

cd /usr/src

wget -c $php_url 

tar -xf php-${php_ver}.tar.bz2

cd php-${php_ver}

 

 

./configure --prefix=${php_dir} \

--enable-fpm \

--enable-debug \

--with-gd \

--with-jpeg-dir \

--with-png-dir \

--with-freetype-dir \

--enable-mbstring \

--with-curl \

--with-mysql=mysqlnd \

--with-mysqli=mysqlnd \

--with-pdo-mysql=mysqlnd \

--with-config-file-path=${php_dir}/etc \

--with-zlib-dir

 

make && make install 

 

\cp php.ini-development  $php_dir/etc/php.ini

\cp  $php_dir/etc/php-fpm.conf.default  $php_dir/etc/php-fpm.conf

 

sed -i '/^group/s/nobody/nginx/g' $php_dir/etc/php-fpm.conf 

sed -i '/^user/s/nobody/nginx/g' $php_dir/etc/php-fpm.conf 

 

egrep "^(user|group)"  $php_dir/etc/php-fpm.conf 

 

\cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

 chmod +x /etc/init.d/php-fpm

/etc/init.d/php-fpm start

 

if [ $? -ne 0 ];then

echo -e "\033[32mconfigure failed please check!!!!\033[0m"

else

echo -e "\033[32mconfigure successful \033[0m"

fi

 

ps -ef | grep php | grep -v grep

 

}

 

 

 

function mysql_install(){

yum install wget gcc c ncurses-devel libaio bison gcc-c++ git cmake ncurses-devel ncurses -y

setenforce 0

systemctl stop firewalld

 

cd /usr/src

wget -c  $mysql_url

tar xf $mysql_soft

cd $mysql_dir

 

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql55/ \

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \

-DMYSQL_DATADIR=/data/mysql \

-DSYSCONFDIR=/usr/local/mysql55/ \

-DMYSQL_USER=mysql \

-DMYSQL_TCP_PORT=3306 \

-DWITH_XTRADB_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_EXTRA_CHARSETS=1 \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DEXTRA_CHARSETS=all \

-DWITH_BIG_TABLES=1 \

-DWITH_DEBUG=0

 

make && make install

 

\cp /usr/src/$mysql_dir/support-files/my-large.cnf /usr/local/mysql55/my.cnf

\cp /usr/src/$mysql_dir/support-files/mysql.server /etc/init.d/mysqld

chmod o+x /etc/init.d/mysqld

useradd -s /bin/nologin mysql

mkdir -p /data/mysql

chown -R mysql:mysql /data/mysql

/usr/local/mysql55/scripts/mysql_install_db --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql55

 

cat >/etc/my.cnf <<EOF

[mysqld]

datadir=/data/mysql

socket=/tmp/mysql.sock

symbolic-links=0

EOF

 

/etc/init.d/mysqld start

 

if [ $? -ne 0 ];then

        echo -e "\033[32mconfigure mysql failed please check!!!!\033[0m"

else

        echo -e "\033[32mconfigure mysql successful \033[0m"

        $mysql_exec -e "$mysql_create_sql"

  $mysql_exec -e "$mysql_grant_sql"

$mysql_exec -e "flush privileges;"

fi

 

ps -ef | grep mysql

}

 

 

PS3="Please select install Menu:"

select i in nginx_install php_install mysql_install quit

do

 

case $i in

nginx_install) 

echo -e "\033[32mstart to install nginx and config wordpress,please wait.................\033[0m"

        nginx_install

        break

        ;;

php_install)

        echo -e "\033[32mstart to install php,please wait.................\033[0m"

        sleep 3

        php_install

        break

        ;;      

mysql_install)

        echo -e "\033[32mstart to install mysql,create database and user ,please wait..................\033[0m"

        sleep 3

        mysql_install

        break

        ;;

*)

        echo -e "\033[32mPlease input right agrs exit!!\033[0m"

        break

        ;;

esac

 

done



如果觉得我的文章对你有用,请随意赞赏

待完善
不要去追一匹马,用追马的时间种草,待到春暖花开时,就会有一批骏马任你挑选;不要去刻意巴结一个人,用暂时没有朋友的时间,去提升自己的能力,待到时机成熟时,就会有一批的朋友与你行。用人情做出来的朋友只是暂时的,用人格吸引来的朋友才是长久的。所以种下梧桐树,引得凤凰来。你若盛开,蝴蝶自来,你若精彩,天自安排
微信扫码登录测试

Powered by Jackios V1.0 Copyright © 2019-2020 liuql 版权所有 备案号: 鲁ICP19026293号