最好是初始的linux Centos7版本 然后把所有安装包和执行脚本都要拷贝到/mnt目录下面
#!/usr/bin/bash
yum -y install gcc gcc-c++ make pcre-devel expat-devel perl apr* #安装所有必须组件
####################安装Apache
#安装所需编译器和组件包
if [ ! -d httpd-2.4.29 ];then
tar jxvf httpd-2.4.29.tar.bz2 #解压Apache源码包
fi
cd httpd-2.4.29/ #移动到解压后目录
./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charest-lite --enable-cgi
#--prefix=/usr/local/httpd
#--enable-so
#--enable-rewrite
#--enable-charest-lite
#--enable-cgi
make -j16 && make install #编译和安装
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
chkconfig --add httpd #将httpd加入到SERVICE管理器
#备份httpd服务配置文件
[ ! -d /usr/local/httpd/conf/httpd.conf.bak ] && cp /usr/local/httpd/conf/httpd.conf /usr/local/httpd/conf/httpd.conf.bak
sed -i '199s/#//' /usr/local/httpd/conf/httpd.conf
rm -rf /etc/httpd.conf
ln -s /usr/local/httpd/conf/httpd.conf /etc/#创建配置文件的软连接
ln -s /usr/local/httpd/bin/* /usr/local/bin/#创建命令的软连接
wait
#######################安装MySQL##################################################
cd /mnt#回到mnt目录
yum -y install git#安装Git组件
yum install -y cmake#安装cmake工具
yum install -y ncurses-devel autoconf#安装ncurses组件
tar zxvf mysql-5.6.26.tar.gz
cd mysql-5.6.26#解压MySQL 并cd到目录
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
-DEXTRA_CHARSETS=all -DSYSCONFIDIR=/etc -DMYSQL_DATADIR=/home/mysql/ -DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock
#定义安装环境
#-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
#-DDEFAULT_COLLATION=utf8_general_ci \
#-DEXTRA_CHARSETS=all \
#-DSYSCONFIDIR=/etc \
#-DMYSQL_DATADIR=/home/mysql/ \
#-DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock
make -j16 && make install#进行编译和安装
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 755 /etc/init.d/mysqld #给执行脚本添加执行权限
chkconfig --add /etc/init.d/mysqld && chkconfig mysqld --level 235 on#给service工具添加MySQL服务
#echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
#source /etc/profile#定义MySQL命令到系统环境变量
ln -s /usr/local/mysql/bin/* /usr/local/bin
useradd -s /sbin/nologin mysql#创建MySQL执行用户
chown -R mysql:mysql /usr/local/mysql/#给该MySQL安装目录的属主跟属组
/usr/local/mysql/scripts/mysql_install_db \
--user=mysql \
--ldata=/var/lib/mysql \
--basedir=/usr/local/mysql \
--datadir=/home/mysql
sed -i '46s/.*/basedir=\/usr\/local\/mysql /' /etc/init.d/mysqld#添加MySQL执行脚本
sed -i '47s/.*/datadir=\/home\/mysql/' /etc/init.d/mysqld
#mysqladmin -u root -p password "abc123" #给root账号设置密码
############################安装PHP#####################################
cd /mnt
yum -y install gd libpng libpng-devel pcre pcre-devel libxml2-devel #安装必要组件
tar xjvf php-5.6.11.tar.bz2
cd php-5.6.11#解压并进入到 解压后目录
./configure --prefix=/usr/local/php5 --with-gd --with-zlib --with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php5
make -j16 && make install#定义安装环境
cp php.ini-development /usr/local/php5/php.ini#复制PHP配置模板文件为新配置文件
ln -s /usr/local/php5/bin/* /usr/local/bin/
ln -s /usr/local/php5/sbin/* /usr/local/sbin/#创建命令的软连接
echo "
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps" >> /etc/httpd.conf#申明http支持php
sed -i '258s/index.html/index.php index.html/' /etc/httpd.conf#修改http主页格式为PHP结尾
以下是 源码包的的地址:
链接:https://pan.baidu.com/s/1M0p7skMwgXSsfvVoJm0kjQ
提取码:10pj