#filename lamp.sh
#version centos6.7;apache2.4.23;mariadb-5.5.40;php5.5.38
#data 2016/09/28
#mail [email protected]
Init ()
{#install Pre
Yum-y install cmake l readline-devel zlib-devel openssl-devel cmake gcc-c++ gcc boost boost-devel bison bison-devel ncurs Es-devel
#edit SELinux
Sed-ir ' s/selinux=enforcing/selinux=permissive/g '/etc/sysconfig/selinux
Setenforce 0
#edit iptables
echo "-A input-m State--state new-m tcp-p TCP--dport 80-j ACCEPT" >>/etc/sysconfig/iptables
echo "-A input-m State--state new-m tcp-p TCP--dport 443-j ACCEPT" >>/etc/sysconfig/iptables
echo "-A input-m State--state new-m tcp-p TCP--dport 3306-j ACCEPT" >>/etc/sysconfig/iptables
echo "-A input-m State--state new-m tcp-p TCP--dport 9000-j ACCEPT" >>/etc/sysconfig/iptables
Service Iptables Stop
#mkdir file
[-D/USR/LOCAL/SRC] | | Mkdir-p/USR/LOCAL/SRC
}
Mysql_install ()
{useradd-s/sbin/nologin MySQL
[-d/data/mysql] | | Mkdir-p/data/mysql && chown-r mysql.mysql/data/mysql
Cd/usr/local/src
#wget http://archive.mariadb.org//mariadb-5.5.40/source/mariadb-5.5.40.tar.gz
Tar XF mariadb-5.5.40.tar.gz
CD mariadb-5.5.40
CMake. -dcmake_install_prefix=/usr/local/mysql-dmysql_datadir=/data/mysql-dsysconfdir=/etc-dwith_innobase_storage_ Engine=1-dwith_archive_stprage_engine=1-dwith_blackhole_storage_engine=1-dwiyh_readline=1-dwiyh_ssl=system- dvith_zlib=system-dwith_lobwrap=0-dmysql_unix_addr=/tmp/mysql.sock-ddefault_charset=utf8-ddefault_collation= Utf8_general_ci
If [$?-ne 0];then
echo "MySQL CMake fail, stop ..."
Exit 1
Fi
Make && make install
If [$?-ne 0];then
echo "MySQL install fail, stop ..."
Exit 1
Fi
Cd/usr/local/mysql
Chown-r Mysql:mysql *
./scripts/mysql_install_db--user=mysql--datadir=/data/mysql--basedir=/usr/local/mysql
Rm-rf/etc/my.cnf
Cp/usr/local/mysql/support-files/my-large.cnf/etc/my.cnf
Cp/usr/local/mysql/support-files/mysql.server/etc/init.d/mysqld
chmod u+x/etc/init.d/mysqld
Sed-i ' s#socket =/tmp/mysql.sock#&\n datadir=/data/mysql#g '/etc/my.cnf
#sed-ir ' s#basedir= #basedir =/usr/local/mysql#g '/etc/init.d/mysqld
#sed-ir ' s#datadir= #datadir =/data/mysql#g '/etc/init.d/mysqld
Chkconfig--add mysqld;chkconfig mysqld on;/etc/init.d/mysqld start
If [$?-ne 0];then
echo "MySQL install fail, stop ..."
Exit 1
Fi
}
Apache_install ()
{
Yum install-y pcre pcre-devel zlib-devel OpenSSL openssl-devel
Cd/usr/local/src
wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.5.2.tar.gz
wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.5.4.tar.gz
wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-iconv-1.2.1.tar.gz
wget http://mirrors.aliyun.com/apache/httpd/httpd-2.4.23.tar.gz
#compile Install Apr apr-util apr-iconv
Tar XF apr-1.5.2.tar.gz
CD apr-1.5.2
./configure--prefix=/usr/local/apr && make && make install
Cd/usr/local/src
Tar XF apr-util-1.5.4.tar.gz
CD apr-util-1.5.4
./configure--prefix=/usr/local/apr-util--with-apr=/usr/local/apr && make && make install
Cd/usr/local/src
Tar XF apr-iconv-1.2.1.tar.gz
./configure--prefix=/usr/local/apr-iconv--with-apr=/usr/local/apr && make && make install
Cd/usr/local/src
Tar XF httpd-2.4.23.tar.gz
CD httpd-2.4.23
./configure--prefix=/usr/local/apache--sysconfdir=/etc/httpd24--enable-so--enable-ssl--enable-cgi-- Enable-rewrite--with-zlib--with-pcre--with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util-- Enable-mpms-shared=all--with-mpm=event--enable-modules=all--enable-cache--enable-ratelimit
If [$?-ne 0];then
echo "Apache Configure fail, stop ... "
Exit 1
Fi
Make && make install
If [$?-ne 0];then
echo "Apache make fail, stop ... "
Exit 1
Fi
/usr/local/apache/bin/apachectl start
Curl localhost
If [$?-eq 0];then
echo "Apache started ok,continue ... "
Else
echo "Apachec started Fail,top ..."
Exit 1
Fi
}
Php_install ()
{
Yum install-y epel-release libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel
Yum install-y bzip2 bzip2-devel OpenSSL openssl-devel libmcrypt-devel libxml2-devel gd gd-devel
Cd/usr/local/src
wget http://mirrors.sohu.com/php/php-5.5.38.tar.gz
Tar XF php-5.5.38.tar.gz
CD php-5.5.38
./configure--prefix=/usr/local/php--with-apxs2=/usr/local/apache/bin/apxs--with-config-file-path=/usr/local/ Php/etc--with-mysql=/usr/local/mysql--with-libxml-dir--with-gd--with-jpeg-dir--with-png-dir--with-freetype-dir --with-iconv-dir--with-zlib-dir--with-bz2--with-openssl--with-mcrypt--enable-soap--enable-gd-native-ttf-- Enable-mbstring--enable-sockets--enable-exif
If [$?-ne 0];then
echo "PHP configure fail, stop ... "
Exit 1
Fi
Make && make install
If [$?-ne 0];then
echo "PHP make fail, stop ... "
Exit 1
Fi
test-d/usr/local/php/etc/| | mkdir/usr/local/php/etc/
CP Php.ini-production/usr/local/php/etc/php.ini
}
Apache_resolve_php ()
{
#support resilve PHP
Cd/usr/local/src
Sed-i-E ' S#addtype application/x-gzip. gz. tgz#&\n addtype application/x-httpd-php. Php#g '/etc/httpd24/httpd.conf
Sed-i ' S#directoryindex index.html#& index.htm index.php#g '/etc/httpd24/httpd.conf
#set Apachectl as global variable
Echo-e ' path= $PATH:/usr/local/mysql/bin:/usr/local/apache/bin\nexport PATH ' >/etc/profile.d/path.sh;
source/etc/profile.d/path.sh
Apachectl-t
Apachectl restart
Cat >/usr/local/apache/htdocs/index.php<<eof
<?php
Phpinfo ();
?>
Eof
Curl localhost && echo "php resolve OK" | | echo "php resolve fail"
}
Lamp_install ()
{
Init
Mysql_install
Apache_install
Php_install
apache_resolve_php
}
Lamp_install 2>&1 | Tee ~/lmap_install.log
Shell script compiles the installation lamp environment