#!/bin/bash

 #description:mysql-5.5..tar apache2.4.23 php5.6.27

 function check_ok(){
if [ $? -eq ]
then
echo "-------------ok-------"
else
echo "please check error"
exit
fi
} function set_yum(){
echo "set yum repo"
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
# yum clean all &>/dev/null
yum makecache &>/dev/null
check_ok
} function install_mysql(){
echo "mysql5.5.53 will be installed,please be patient"
wget -O /usr/local/src/mysql-5.5..tar http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.53.tar.gz
cd /usr/local/src
tar -zxf mysql-5.5..tar
check_ok
cd /usr/local/src/mysql-5.5.
useradd -u -s /sbin/nologin mysql
mkdir /data
yum install cmake -y
yum install ncurses-devel -y
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE= -DWITH_INNOBASE_STORAGE_ENGINE= -DWITH_MEMORY_STORAGE_ENGINE= -DWITH_READLINE= -DENABLED_LOCAL_INFILE= -DMYSQL_DATADIR=/data -DMYSQL_USER=mysql
check_ok
make -j && make install
check_ok
chown -R mysql:mysql /usr/local/mysql/
chown -R mysql:mysql /data cp support-files/my-large.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
sed -i 's/^basedir=$/basedir=\/usr\/local\/mysql/' /etc/init.d/mysqld
sed -i 's/^datadir=$/datadir=\/data/' /etc/init.d/mysqld
chkconfig mysqld on
chmod +x scripts/mysql_install_db
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data --user=mysql
service mysqld start iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport -j ACCEPT
/etc/init.d/iptables save
check_ok
echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
source /etc/profile
} function install_apache(){
echo "apache2.4.23 will be installed,please be patient"
cd /usr/local/src
wget http://mirrors.cnnic.cn/apache/apr/apr-1.5.2.tar.gz
wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.5.4.tar.gz
check_ok
tar zxf apr-1.5..tar.gz
cd apr-1.5.
./configure --prefix=/usr/local/apr
check_ok
make && make install
check_ok cd /usr/local/src
tar zxf apr-util-1.5..tar.gz
cd apr-util-1.5.
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
check_ok
make && make install
check_ok cd /usr/local/src
wget http://ftp.exim.llorien.org/pcre/pcre-8.39.tar.gz
tar xvf pcre-8.39.tar.gz
cd pcre-8.39
./configure --prefix=/usr/local/pcre
make && make install
check_ok cd /usr/local/src
wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.23.tar.gz
tar zxf httpd-2.4..tar.gz
/bin/cp -r apr-1.5. /usr/local/src/httpd-2.4./srclib/apr
/bin/cp -r apr-util-1.5. /usr/local/src/httpd-2.4./srclib/apr-util
cd /usr/local/src/httpd-2.4.
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre --enable-mods-shared=most --enable-so --with-included-apr
check_ok
make && make install
check_ok
cp -a /usr/local/apache2/bin/apachectl /etc/init.d/httpd
sed -i '1a #chkconfig: 2345 10 90' /etc/init.d/httpd
sed -i '2a #description: Activates/Deactivates Apache Web Server' /etc/init.d/httpd
echo "export PATH=$PATH:/usr/local/apache2/bin" >>/etc/profile
source /etc/profile
check_ok
chkconfig --add httpd
chkconfig httpd on
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport -j ACCEPT
/etc/init.d/iptables save
check_ok
/usr/local/apache2/bin/apachectl
check_ok
service httpd restart
} function install_php(){
echo "php5.6.27 will be installed,please be patient"
cd /usr/local/src
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
tar zxvf libmcrypt-2.5..tar.gz
cd libmcrypt-2.5.
./configure --prefix=/usr/local/libmcrypt
make && make install
cd /usr/local/src wget http://am1.php.net/get/php-5.6.27.tar.gz/from/this/mirror tar zxf php-5.6..tar.gz
cd php-5.6.
yum install openssl openssl-devel -y
yum install bzip2 bzip2-devel -y
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/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=/usr/local/libmcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6 check_ok
make -j && make install
check_ok cp /usr/local/src/php-5.6./php.ini-production /usr/local/php/etc/php.ini
sed -i 's#^;date.timezone =#date.timezone=Asia/Shanghai#' /usr/local/php/etc/php.ini
check_ok
#
}
function set_lamp(){
sed -i '/AddType application\/x-gzip .gz .tgz/a\ AddType application/x-httpd-php .php\n' /usr/local/apache2/conf/httpd.conf
sed -i 's#index.html#index.html index.php#' /usr/local/apache2/conf/httpd.conf
sed -i '/#ServerName www.example.com:80/a\ServerName localhost:80\n' /usr/local/apache2/conf/httpd.conf
check_ok
cat >>/usr/local/apache2/htdocs/test.php<<EOF
<?php
echo "PHP is OK\n";
phpinfo();
?>
EOF /usr/local/apache2/bin/apachectl graceful
check_ok
} function install_lamp(){
install_mysql
install_apache
install_php
set_lamp
shutdown -r now
}
install_lamp

lamp 源码安装-LMLPHP

05-11 22:53