lnmp安装脚本、一起学习、有更好的建议请留言、
#!/bin/bash
#
# describe: linux nginx mysql php install
FileS=/updatefile
mkdir -p $FileS
# 安装lrzsz 方便后续文件上传
wget http://vault.centos.org/6.5/os/x86_64/Packages/lrzsz-0.12.20-27.1.el6.x86_64.rpm -P $FileS &>/dev/null
rpm -vih $FileS/*.rpm &>/dev/null
RETVAL=$?
[ $RETVAL -eq 0 ] && echo "lrzsz install done" || echo "lrzsz exists."
# yum - rprl网络源
rm -rf /etc/yum.repo.d/*.repo
wget http://mirrors.aliyun.com/repo/Centos-6.repo -P /etc/yum.repo.d/ &>/dev/null
wget http://mirrors.aliyun.com/repo/epel-6.repo -P /etc/yum.repo.d/ &>/dev/null
#修改yum源名称将系统提示改为系统版本,epel不需要改
sed -i ‘[email protected][email protected]@gi‘ /etc/yum.repo.d/Centos-6.repo
yum clean all &>/dev/null
yum list all &>/dev/null
# 提示信息 install nginx
echo "nginx Dependent package you need up | pcie (eq 8.38) | nginx "
cd $FileS
# 安装nginx依赖包
yum -y install make gcc gcc-c++ flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel gd freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel gettext gettext-devel ncurses-devel gmp-devel unzip libcap lsof
# Zlib:Nginx提供gzip模块,需要zlib的支持 Openssl:Nginx提供SSL的功能
yum -y install gcc gcc-c++ autoconf automake
yum -y install zlib zlib-devel openssl openssl-devel
# 解压pcre,nginx
cd $FileS
echo "download file loading..."
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.zip &>/dev/null
unzip pcre*
wget http://nginx.org/download/nginx-1.8.1.tar.gz &>/dev/null
tar xf nginx*
# 进入目录进入安装
cd nginx*
./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre=$FileS/pcre-8.38 --user=nginx --group=nginx
make && make install
# 创建系统用户
useradd -M -s /sbin/nologin nginx
# 配置nginx支持php文件
sed -i ‘3 a user nginx nginx;‘ /usr/local/nginx/conf/nginx.conf
sed -i "[email protected]/[email protected]/usr/local/nginx/[email protected]" /usr/local/nginx/conf/nginx.conf
sed -i ‘65,72s/#/ /gi‘ /usr/local/nginx/conf/nginx.conf
# 启动项
echo “export PATH=$PATH:/usr/local/nginx/sbin" >> /etc/profile.d/nginx.sh
source /etc/profile.d/nginx.sh
# 不管有没有启动先将其停止,然后再开启服务
killall -9 nginx
/usr/local/nginx/sbin/nginx
# 提示信息 install mysql
echo "******************************************************************************************"
echo "mysql Dependent package you need up | boost(eq boost_1_59_0 ) | mysql | cmake(gt 2.8) "
echo "boost,mysql 文件太大,手动上传 "
echo " warning mysql install directory need gt 15G "
echo "******************************************************************************************"
sleep 5
cd $FileS
rz
mv boost* mysql* $FileS &>/dev/null
# 版本太低直接删除
yum -y remove boost &>/dev/null
yum -y remove mysql &>/dev/null
# 安装cmake 使用网络yum源、上面已定义直接安装即可
yum -y install cmake
# 增加系统组mysql 用户不允许登陆系统不创建家目录
groupadd mysql
useradd -M -s /sbin/nologin -r -g mysql mysql
tar xf boost*
tar xf mysql*
cd mysql*
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_BOOST=$FileS/boost_1_59_0 -DWITH_PARTITION_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/server/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DDOWNLOAD_BOOST=1 -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all
make && make install
# 将Mysql目录下的文件属主属组权限交给mysql
chown -R mysql:myql /usr/local/mysql
# 备份原my.cnf配置文件
mv /etc/my.cnf{.,bak}
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x !$
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start
# 初始化数据库
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
# 启动mysqld服务
killall -9 mysqld
service mysqld start
# 添加全局环境变量
echo -e "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile.d/mysql.sh
source !$
# 修改mysql密码
mysqladmin -u root password "123456"
# install php
echo "php Dependent package you need up |libiconv | libmcrypt | mhash | mcrypt | php "
echo "上面指定软件包一共五个"
cd $FileS
rz
mv libiconv* libmcrypt* mhash* mcrypt* php* $FileS
# 安装开发软件包
cd $FileS
tar xf libiconv*
tar xf mhash*
tar xf libmcrypt*
tar xf mcrypt*
tar xf php*
cd $FileS/libiconv*
./configure --prefix=/usr/local/libiconv
make && make install
cd ..
cd $FileS/libmcrypt-2.5.8
./configure
make && make install
# 密文软件不安会各种报错离散数字
cd $FileS/mhash*
./configure
make && make install
cd ..
echo -e "/usr/local/lib\n/usr/local/libiconv\n/server/mysql/lib/libmysqlclient.so.20\n" >> /etc/ld.so.conf
# 加载库文件
ldconfig
sleep 10
# 安装离散数字解密包
cd $FileS/mcrypt*
./configure
make && make install
# 安装php组件
yum -y install php-pear
cd $FileS/php*
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/ --enable-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
make && make install
# 复制配置文件
cp $FileS/php-7.0.5/php.ini-production /usr/local/php/php.ini
cp $FileS/php-7.0.5/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# 自定义一个网页文件
echo -e "<?php\n\tphpinfo();\n?>" >> /usr/local/nginx/html/a.php
chmod +x /etc/rc.d/init.d/php-fpm
service php-fpm restart
killall -9 nginx
/usr/local/nginx/sbin/nginx
想直接使用网页查看效果可在host文件中添加主机记录