您好,登錄后才能下訂單哦!
安裝順序:apache→mysql→PHP
實驗所需軟件包:鏈接:https://pan.baidu.com/s/1tKAjqn50NnR7F3JmzyHF1w 提取碼:1xpr
#!/bin/bash
#一鍵自動構建LAMP架構(請使用source執行或者使用.命令執行)
#數據庫默認密碼為123123
#遠程掛載
df -hT | grep -o "cifs"
if [ $? -ne 0 ];then
echo "Start mount"
yum install expect -y
read -p "請輸入提供硬盤主機IP:" gongip
/usr/bin/expect <<-EOF
spawn mount.cifs //$gongip/LAMP-C7 /mnt/
expect {
"Password*"
{send "\r"}
}
expect eof
EOF
fi
#安裝apache服務
cd /mnt/
tar zxf apr-1.6.2.tar.gz -C /opt
tar zxf apr-util-1.6.0.tar.gz -C /opt/
tar jxf httpd-2.4.29.tar.bz2 -C /opt/
cd /opt/
mv apr-1.6.2/ httpd-2.4.29/srclib/apr
mv apr-util-1.6.0/ httpd-2.4.29/srclib/apr-util
yum -y install gcc \
gcc-c++ \
make \
pcre-devel \
expat-devel \
perl
cd /opt/httpd-2.4.29/
./configure --prefix=/usr/local/httpd \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi
make && make install
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
sed -i -e '2a# chkconfig: 35 85 21\n# description: Apache is a World Wide Web server' /etc/init.d/httpd
chkconfig --add httpd
sed -i -e '197d' -e '196aServerName www.kgc.com:80' /usr/local/httpd/conf/httpd.conf
ip=`ifconfig ens33 | awk 'NR==2{print $2}'`
sed -i -e '52s/^/#/' -e '51d' -e "50aListen $ip:80" /usr/local/httpd/conf/httpd.conf
ln -s /usr/local/httpd/conf/httpd.conf /etc/
ln -s /usr/local/httpd/bin/* /usr/local/bin/
systemctl stop firewalld.service
setenforce 0
service httpd start
netstat -ntuap | grep httpd
if [ $? -eq 0 ];then
echo Apache服務啟動
else
echo 啟動失敗
exit 1
fi
#安裝mysql服務
echo "================================="
echo "安裝mysql數據庫,請稍后。。。"
sleep 3
yum install -y ncurses-devel autoconf cmake
cd /mnt/
tar zxf mysql-5.6.26.tar.gz -C /opt/
cd /opt/mysql-5.6.26
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
echo "進行編譯安裝,要很久,請稍后。。。"
make && make install
cp support-files/my-default.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add /etc/init.d/mysqld
chkconfig --level 235 mysqld on
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
echo $PATH | grep -o "mysql"
if [ $? -eq 0 ];then
echo "添加成功"
else
echo "失敗"
exit 1
fi
useradd -s /sbin/nologin mysql
chown -R mysql:mysql /usr/local/mysql/
/usr/local/mysql/scripts/mysql_install_db \
--user=mysql \
--ldata=/var/lib/mysql \
--basedir=/usr/local/mysql \
--datadir=/home/mysql
sed -i -e '47d' -e '46d' -e '45abasedir=/usr/local/mysql\ndatadir=/home/mysql' /etc/init.d/mysqld
service mysqld start
netstat -ntuap | grep mysqld
if [ $? -eq 0 ];then
echo Mysql數據庫啟動
else
echo 啟動失敗
exit 1
fi
#read -p "請輸入數據庫密碼(自定義):" mima
/usr/bin/expect <<EOF
spawn mysqladmin -u root -p password 123123
expect {
"Enter*"
{send "\r"}
}
expect eof
EOF
#安裝PHP工具
yum install -y gd \
libpng \
libpng-devel \
pcre \
pcre-devel \
libxml2-devel \
libjpeg-devel
cd ~
tar jxf /mnt/php-5.6.11.tar.bz2 -C /opt/
cd /opt/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 \
--enable-mbstring
make && make install
cp -p php.ini-development /usr/local/php5/php.ini
ln -s /usr/local/php5/bin/* /usr/local/bin/
sed -i '393a AddType application/x-httpd-php .php\n AddType application/x-httpd-php-source .phps' /usr/local/httpd/conf/httpd.conf
sed -i -e '256d' -e '255aDirectoryIndex index.html index.php' /usr/local/httpd/conf/httpd.conf
cat > /usr/local/httpd/htdocs/index.php <<-EOF
<?php
phpinfo();
?>
EOF
service httpd stop
service httpd start
rm -rf /opt/*
umount /mnt
#請使用source+腳本啟動
source /etc/profile
echo $PATH | grep -o "mysql"
while [ $? -ne 0 ];do
while [ "a" = "a" ]
do
echo "錯誤!!"
sleep 2
done
done
echo "LAMP架構完成。腳本執行結束~~~~"
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。