第24章,LAMP 一键安装脚本

更多内容请点击:

Linux学习从入门到打死也不放弃,完全笔记整理(持续更新,求收藏,求点赞~~~~) 

http://blog.51cto.com/13683480/2095439


脚本1:yum安装 lamp+wordpress

# 自行配置好yum源

# 第一步,安装并启动服务
yum -y install httpd mariadb-server php php-mysql
echo -e "\e[1;31mstarting service....\e[0m"
systemctl start httpd mariadb

# 第二步,添加mysql授权账号,新建数据库wordpress
mysql -e "grant all on *.* to 'wpuser'@'localhost' identified by 'PASSWORD';"
mysql -e "create database wordpress;"

# 第三步,下载wordpress,并解压
echo -e "\e[1;31mget the wordpress package....\e[0m"
wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.zip
unzip wordpress-4.9.4-zh_CN.zip
cp -a wordpress/* /var/www/html/
chown -R apache:apache /var/www/html

# 第四步,准备配置文件
cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php
sed -i 's/database_name_here/wordpress/' /var/www/html/wp-config.php
sed -i 's/username_here/wpuser/' /var/www/html/wp-config.php
sed -i 's/password_here/PASSWORD/' /var/www/html/wp-config.php

# 第五步,重启服务
echo -e "\e[1;31mrestarting httpd....\e[0m"
systemctl restart httpd
echo -e "\e[1;31mjob done....\e[0m"


脚本2,yum安装lamp-fpm + wordpress

# 自行配置好yum源

# 第一步,安装并启动服务
yum -y install httpd mariadb-server php-fpm php-mysql
echo -e "\e[1;31mstarting service....\e[0m"

echo -e 'DirectoryIndex index.php' > /etc/httpd/conf.d/fcgi.conf
echo -e 'ProxyRequests Off' >> /etc/httpd/conf.d/fcgi.conf
echo -e 'ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1' >>/etc/httpd/conf.d/fcgi.conf

systemctl start httpd mariadb php-fpm

# 第二步,添加mysql授权账号,新建数据库wordpress
mysql -e "grant all on *.* to 'wpuser'@'localhost' identified by 'PASSWORD';"
mysql -e "create database wordpress;"

# 第三步,下载wordpress,并解压
echo -e "\e[1;31mget the wordpress package....\e[0m"
wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.zip
unzip wordpress-4.9.4-zh_CN.zip
cp -a wordpress/* /var/www/html/
chown -R apache:apache /var/www/html

# 第四步,准备配置文件
cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php
sed -i 's/database_name_here/wordpress/' /var/www/html/wp-config.php
sed -i 's/username_here/wpuser/' /var/www/html/wp-config.php
sed -i 's/password_here/PASSWORD/' /var/www/html/wp-config.php

# 第五步,重启服务
echo -e "\e[1;31mrestarting httpd....\e[0m"
systemctl restart httpd
echo -e "\e[1;31mjob done....\e[0m"


脚本3:编译安装LAMP(module/fpm)+ wordpress + phpmyadmin

# 编译安装LAMP
#
##############################################################################################
# 安装程序顺序
# mariadb:通用二进制格式:mariadb-10.2.15
#       下载地址:

#       需提前准备好二进制安装包
# httpd:       编译安装,http-2.4.33
#       下载地址:
#        http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.33.tar.bz2 
#        http://mirrors.sohu.com/apache/httpd-2.4.33.tar.bz2
#       需要更新apr,apr-util
#       下载地址:
#       APR: http://mirrors.hust.edu.cn/apache//apr/apr-1.6.3.tar.bz2
#       APR-UTIL: http://mirrors.hust.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2
#
# php7:编译安装,php-7.2.7
#       下载地址:http://mirrors.sohu.com/php/php-7.2.7.tar.bz2
#
# phpmyadmin:安装phpmyadmin4.8.2
#       下载地址:https://files.phpmyadmin.net/phpMyAdmin/4.8.2/phpMyAdmin-4.8.2-all-languages.zip
# worppress: 版本wordpress-4.9.4
#       下载地址:https://cn.wordpress.org/wordpress-4.9.4-zh_CN.zip
# 
# xcache:php7 以内置加速功能,不需要安装xcache
#
#############################################################################################
# 安装选项 
# 选择PHP编译方式,"module" or "fpm"

phpmod="fpm"

httpd_dir="/app/httpd24"
httpd_conf_dir="/etc/httpd24"
php_dir="/app/php"

# 安装程序版本,和源码压缩包名
# 注意如果要修改,必须修改下载地址或者自行提供源码包

mariadb_version="mariadb-10.2.15-linux-x86_64"
mariadb_package="${mariadb_version}.tar.gz"
httpd_version="httpd-2.4.33"
httpd_package="${httpd_version}.tar.bz2"
apr_version="apr-1.6.3"
apr_package="${apr_version}.tar.bz2"
apr_util_version="apr-util-1.6.1"
apr_util_package="${apr_util_version}.tar.bz2"
php_version="php-7.2.7"
php_package="${php_version}.tar.bz2"


# 选择应用程序 "yes" or "no"

wdpress="yes"
pma="yes"

# 是否清理源码包 "yes" or "no"

cleantemp="yes"

############################################################################################
# 准备开发环境
echo -e "\e[1;31mPrepare the development environment....\e[0m"

# 开发包组
yum groupinstall "development tools" "Server Platform Development" -y

# 编译 httpd-2.4需要
yum install pcre-devel openssl-devel expat-devel -y

# 编译 php 需要
yum install libxml2-devel bzip2-devel libmcrypt-devel -y

# 下载源程序包
echo -e "\e[1;31mdownload packages....\e[0m"

wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.33.tar.bz2
wget http://mirrors.hust.edu.cn/apache//apr/apr-1.6.3.tar.bz2
wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2
wget http://mirrors.sohu.com/php/php-7.2.7.tar.bz2

echo -e "\e[1;31munpack the packages....\e[0m"
tar -xf ${httpd_package}
tar -xf ${apr_package}
tar -xf ${apr_util_package}
tar -xf ${php_package}

############################################################################################
# 二进制安装mariadb-10.2.15,程序包需另行下载
echo -e "\e[1;31minstall mariadb....\e[0m"

# 创建账号
groupadd -r -g 306 mysql
useradd -r -u 306 -g 306 -d /data/mysqldb mysql

# 解压缩
tar -xf mariadb-10.2.15-linux-x86_64.tar.gz -C /usr/local/
cd /usr/local/
ln -sv mariadb-10.2.15-linux-x86_64 mysql
cd mysql
chown -R mysql:mysql ./*

# 数据目录和启动脚本
mkdir /data/mysqldb -p
chown -R mysql:mysql /data/mysqldb
./scripts/mysql_install_db --datadir=/data/mysqldb --user=mysql
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on

# 配置文件
mkdir /etc/mysql
cp support-files/my-huge.cnf /etc/mysql/my.cnf
sed -i '27a \datadir =\/data\/mysqldb' /etc/mysql/my.cnf
sed -i '27a \innodb_file_per_table = on' /etc/mysql/my.cnf
sed -i '27a \skip_name_resolve = on' /etc/mysql/my.cnf

mkdir /var/log/mariadb -p
touch /var/log/mariadb/mariadb.log
chown mysql:mysql /var/log/mariadb/mariadb.log

# 添加环境变量
echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh

# 启动服务
echo -e "\e[1;31mstarting mariadb....\e[0m"
service mysqld start

####################################################################
# 源码编译http-2.4.33
echo -e "\e[1;31mstart install httpd....\e[0m"

groupadd -r -g 80 apache
useradd -r -u 80 -g 80 apache

# 下载并解压
cd
cp -a ${apr_version} ${httpd_version}/srclib/apr
cp -a ${apr_util_version} ${httpd_version}/srclib/apr-util

# 编译
cd ${httpd_version}
./configure --prefix=${httpd_dir} \
--sysconfdir=${httpd_conf_dir} \
--enable-so \
--enable-ssl --enable-cgi \
--enable-rewrite \
--with-zlib --with-pcre \
--with-includedapr \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork

make -j 4 && make install

# 添加环境变量
echo -e "PATH=${httpd_dir}/bin/:\$PATH" > /etc/profile.d/apache.sh
. /etc/profile.d/apache.sh

# 修改配置文件中的user和group,默认是daemon
sed -i '/^User/s/.*/User apache/' ${httpd_conf_dir}/httpd.conf
sed -i '/^Group/s/.*/Group apache/' ${httpd_conf_dir}/httpd.conf

# 启动服务
echo -e "\e[1;31mstarting httpd....\e[0m"
apachectl start

#####################################################################
# 源码编译php
echo -e "\e[1;31mstart install php....\e[0m"
cd
cd ${php_version}/

if [ "$phpmod" = "module" ];then

######################
# 编译php module

./configure --prefix=${php_dir} \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-openssl \
--with-pdo-mysql=mysqlnd \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml  \
--enable-sockets \
--with-apxs2=${httpd_dir}/bin/apxs \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--disable-fileinfo

make -j 4 && make install

# 开始编辑配置文件
echo -e "\e[1;31mModify configuration....\e[0m"

cp php.ini-production /etc/php.ini
sed -i '/IfModule mime_module/a \AddType application\/x-httpd-php .php' ${httpd_conf_dir}/httpd.conf
sed -i '/IfModule mime_module/a \AddType application\/x-httpd-php-sourcei .phps' ${httpd_conf_dir}/httpd.conf
sed -i 's/index.html/index.php index.html/' ${httpd_conf_dir}/httpd.conf


######################
elif [ "$phpmod" = "fpm" ];then

# 编译php-fpm
./configure --prefix=${php_dir} \
--enable-mysqlnd  \
--with-mysqli=mysqlnd  \
--with-openssl \
--with-pdo-mysql=mysqlnd  \
--enable-mbstring  \
--with-freetype-dir  \
--with-jpeg-dir  \
--with-png-dir  \
--with-zlib  \
--with-libxml-dir=/usr  \
--enable-xml \
--enable-sockets  \
--enable-fpm  \
--with-config-file-path=/etc  \
--with-config-file-scan-dir=/etc/php.d  \
--disable-fileinfo 

make -j 4 && make install

# 安装后配置
echo -e "\e[1;31mModify configuration....\e[0m"

cp php.ini-production /etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
 
cd ${php_dir}/etc
cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default php-fpm.d/www.conf

# 修改php-fpm程序的用户和组,可选项,不修改也可以
sed -i '/^user =/s/.*/user = apache/' php-fpm.d/www.conf
sed -i '/^group =/s/.*/group = apache/' php-fpm.d/www.conf

# 修改/etc/php.d/*.ini --> /etc/php.d/*.so
# php7.2.7 如果不修改此项,启动会有一堆报错
rename ini so /etc/php.d/*


service php-fpm start

# 配置httpd支持php
sed -i '/IfModule mime_module/a \AddType application\/x-httpd-php .php' ${httpd_conf_dir}/httpd.conf
sed -i '/IfModule mime_module/a \AddType application\/x-httpd-php-sourcei .phps' ${httpd_conf_dir}/httpd.conf
sed -i 's/index.html/index.php index.html/' ${httpd_conf_dir}/httpd.conf
sed -i 's/#\(LoadModule proxy_module modules\/mod_proxy.so\)/\1/' ${httpd_conf_dir}/httpd.conf
sed -i 's/#\(LoadModule proxy_fcgi_module modules\/mod_proxy_fcgi.so\)/\1/' ${httpd_conf_dir}/httpd.conf
echo 'ProxyRequests Off' >> ${httpd_conf_dir}/httpd.conf
echo -e "ProxyPassMatch  ^/(.*\.php)$ fcgi://127.0.0.1:9000${httpd_dir}/htdocs/\$1" >> ${httpd_conf_dir}/httpd.conf


fi


############################################################################################
# 安装wordpress
cd
if [ "$wdpress" = "yes" ];then

# 获取安装包并解压
echo -e "\e[1;31mstart install wordpress....\e[0m"
wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.zip
unzip wordpress-4.9.4-zh_CN.zip
cp -a wordpress/* ${httpd_dir}/htdocs/
chown -R apache:apache ${httpd_dir}/htdocs/*

# 添加数据库授权账号,创建数据库
mysql -e "grant all on *.* to 'wpuser'@'localhost' identified by 'centos';"
mysql -e "create database wordpress;"

# 准备配置文件
cp ${httpd_dir}/htdocs/wp-config-sample.php ${httpd_dir}/htdocs/wp-config.php
sed -i 's/database_name_here/wordpress/' ${httpd_dir}/htdocs/wp-config.php
sed -i 's/username_here/wpuser/' ${httpd_dir}/htdocs/wp-config.php
sed -i 's/password_here/centos/' ${httpd_dir}/htdocs/wp-config.php

fi

############################################################################################
# 安装pma
if [ "$pma" = "yes" ];then
echo -e "\e[1;31mstart install phpmyadmin....\e[0m"
yum install php-mbstring -y

# 设置root账号密码
#mysql -e "SET PASSWORD FOR root@'localhost'=PASSWORD('centos');"


# 获取安装包并解压
wget https://files.phpmyadmin.net/phpMyAdmin/4.8.2/phpMyAdmin-4.8.2-all-languages.zip
unzip phpMyAdmin-4.8.2-all-languages.zip
cp -a phpMyAdmin-4.8.2-all-languages ${httpd_dir}/htdocs/pma
cp ${httpd_dir}/htdocs/pma/config.sample.inc.php ${httpd_dir}/htdocs/pma/config.inc.php

fi

############################################################################################
# php7.0 以上自带加速,所以无需安装xcache
# 清理缓存安装文件
cd
if [ "$cleantemp" = "yes" ];then
        rm -rf ${mariadb_package} 
        rm -rf ${httpd_package}  ${httpd_version}
        rm -rf ${apr_util_package}  ${apr_util_version}
        rm -rf ${apr_package}  ${apr_version}
        rm -rf ${php_package}  ${php_version}
        rm -rf wordpress-4.9.4-zh_CN.zip  wordpress
        rm -rf phpMyAdmin-4.8.2-all-languages.zip  phpMyAdmin-4.8.2-all-languages

fi


############################################################################################
# 重启服务
echo -e "\e[1;31mrestarting httpd....\e[0m"
apachectl restart
echo -e "\e[1;31mjob done....\e[0m"




猜你喜欢

转载自blog.51cto.com/13683480/2138859