最好是初始的linux Centos7版本 而後把全部安裝包和執行腳本都要拷貝到/mnt目錄下面php
#!/usr/bin/bash
html
yum -y install gcc gcc-c++ make pcre-devel expat-devel perl apr* #安裝全部必須組件mysql
####################安裝Apachelinux
#安裝所需編譯器和組件包c++
if [ ! -d httpd-2.4.29 ];thengit
tar jxvf httpd-2.4.29.tar.bz2 #解壓Apache源碼包sql
fiapache
cd httpd-2.4.29/ #移動到解壓後目錄bash
./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charest-lite --enable-cgiapp
#--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