第一次写脚本儿---LAMP环境一键安装

回复 收藏
#!/bin/bash
#YUM安装所需插件
yum install -y zlib-devel
#下载所需要的安装包
cd /usr/local/src
wget http://mirrors.sohu.com/apache/httpd-2.2.31.tar.gz http://mirrors.sohu.com/php/php-5.3.27.tar.gz http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-x86_64-glibc23.tar.gz

#安装Mysql
tar -zxvf mysql-5.1.73-linux-x86_64-glibc23.tar.gz
mv mysql-5.1.73-linux-x86_64-glibc23 /usr/local/mysql
useradd -s /sbin/nologin mysql
cd /usr/local/mysql/
mkdir -p /data/mysql ; chown -R mysql:mysql /data/mysql
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
cp support-files/my-large.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
sed -i '1,50s/basedir\=/basedir\=\/usr\/local\/mysql/g' /etc/init.d/mysqld
sed -i '1,50s/datadir\=/datadir\=\/data\/mysql/g' /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start

#安装Apache
cd /usr/local/src
tar -zxvf httpd-2.2.31.tar.gz
cd httpd-2.2.31
./configure --prefix=/usr/local/apache2 --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --with-pcre
make && make install
/usr/local/apache2/bin/apachectl start

#安装PHP
cd /usr/local/src
tar -zxvf php-5.3.27.tar.gz
rpm -ivh "http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm"
echo $?
yum install -y libxml2-devel openssl openssl-devel bzip2 bzip2-devel libpng libpng-devel freetype freetype-devel libmcrypt-devel libjpeg-devel
echo $?
cd php-5.3.27
./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 --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6
echo $?
make
echo $?
make install
echo $?
cp php.ini-production /usr/local/php/etc/php.ini

#Apache结合PHP
sed -i '/AddType application\/x-gzip/a AddType application\/x-httpd-php .php' /usr/local/apache2/conf/httpd.conf
sed -i 's/DirectoryIndex index.html/DirectoryIndex index.html index.htm index.php/g' /usr/local/apache2/conf/httpd.conf
sed -i '/ServerName/a ServerName localhost\:80' /usr/local/apache2/conf/httpd.conf

#启动LAMP
/usr/local/apache2/bin/apachectl start
touch /usr/local/apache2/htdocs/info.php
echo "<?php" > /usr/local/apache2/htdocs/info.php
echo "phpinfo();" >> /usr/local/apache2/htdocs/info.php
echo "?>" >> /usr/local/apache2/htdocs/info.php
iptables -F
service iptables save
/usr/local/apache2/bin/apachectl restart

2016-07-26 17:46 举报
已邀请:

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: