#!/bin/bash #部署一個LAMP的環境 #文檔整理人:dingxue #整理日期:2017-10-6 #提取部署好yum環境,也可使用網絡yum操做 #說明:本文檔部署環境的機器是:Linux redhat_6.5_x64 #請將所需的源碼包拷貝到服務器的"/usr/local/lamp/"目錄裏面 log_file="/usr/local/lamp_install.log" [ -f $log_file ] && > $log_file echo -e "\t`date +"%F %T"` 開始部署環境" | tee -a $log_file c_err(){ echo -e "\033[5;31m`date +"%F %T"`------ $@ ------ \033[0m" | tee -a $log_file } c_scc(){ echo -e "\033[32m`date +"%F %T"`------ $@ ------ \033[0m" | tee -a $log_file } #退出狀態檢查 #echo $? #--> 1 表示rpm包安裝失敗 #--> 2 表示iptables或selinux關閉失敗 #--> 5 表示/usr/local/src/lamp文件不存在 #--> 10 表示apache安裝失敗 #--> 15 表示cmake安裝失敗 #--> 20 表示mysql安裝失敗 #--> 26 表示php安裝失敗 #遇到yum不能用的時候,使用下面的方式操做 # wget -q http://mirrors.tencentyun.com/install/softinst.sh && chmod +x softinst.sh && ./softinst.sh yum -y install gcc* &> /dev/null [ $? -ne 0 ] && c_err "rpm package install fail!!" && exit 1 || c_scc "rpm package install Success!!" #off iptables service iptables stop &>/dev/null chkconfig iptables off &>/dev/null [ $? -ne 0 ] && c_err "iptables Close fail !!" && exit 2 || c_scc "iptables Success Close!!" #off selinux (修改配置文件關閉selinux,須要重啓機器才能生效) sed -i.bak 's/SELINUX=enforcing/#&/' /etc/selinux/config sed -i 's/SELINUXTYPE=targeted/#&/' /etc/selinux/config sed -i '$a SELINUX=disabled' /etc/selinux/config #使用getenforce能夠查詢當前selinux的狀態(Enforcing-開啓一、permissive-->關閉0) #臨時關閉(不用重啓機器) (0 --> permissive,1 --> Enforcing) setenforce 0 &> /dev/null [ $? -ne 0 ] && c_err "selinux Close fail !!" && exit 2 || c_scc "selinux Success Close!!" #The installation package path is stored in the same "/usr/local/src" [ ! -d /usr/local/lamp/ ] && mkdir -p /usr/local/lamp/ && c_scc "lamp文件是空的,請拷貝相關源碼包!!"&& exit 5 #轉換文件格式. win>>>linux yum -y install dos2unix &> /dev/null ################################################################## ###### http(apache) server install ###### ################################################################## rpm_http=`rpm -qa | grep httpd | wc -l` [ $rpm_http -ne 0 ] && rpm -e `rpm -qa | grep httpd` --nodeps #測試使用curl yum -y install curl-devel &> /dev/null cd /usr/local/lamp tar xf httpd-2.2.17.tar.gz -C ../ cd ../httpd-2.2.17/ ./configure --prefix=/usr/local/httpd --disable-authn-file --disable-authn-default --disable-authz-groupfile --disable-authz-user --disable-authz-default --disable-auth-basic --disable-include --enable-so --with-mpm=prefork &>/dev/null #選項解釋: #--prefix=/usr/local/apache2 --> 指定安裝目錄 #--enable-so --> 容許運行時加載DSO模塊 #--with-mpm=prefork --> 指定使用的MPM的類型 make &> /dev/null && make install &> /dev/null apache_num=`echo $?` [ $apache_num -ne 0 ] && c_err "apache install fail" && exit 10 || c_scc "apache install Success" /bin/cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd sed -i '2i #chkconfig: 35 85 21' /etc/init.d/httpd chkconfig --add httpd sed -i '97 s/#//' /usr/local/httpd/conf/httpd.conf sed -i '97 s/example/benet/' /usr/local/httpd/conf/httpd.conf #配置文件53行內容是加載php的內容,因爲尚未安裝php,故暫時禁用,待安裝完php後在開啓 sed -i '53 s/^/#/' /usr/local/httpd/conf/httpd.conf /usr/local/httpd/bin/apachectl start #啓動apache服務器 #service httpd start 須要本身配置該啓動方式 curl http://127.0.0.1 &> /dev/null [ $? -eq 0 ] && c_scc "web server Can normally access!!" || c_err "web server Access failed!!" #在客戶端的機器上輸入:http://192.168.2.6查看是否能夠打開默認網頁 ################################################################## ###### mysql server install ###### ################################################################## rpm_mysql=`rpm -qa | grep mysql | wc -l` [ $rpm_mysql -ne 0 ] && rpm -e `rpm -qa | grep mysql` --nodeps groupadd mysql &> /dev/null #建立mysql組 useradd -M -s /sbin/nologin mysql -g mysql #建立mysql用戶 chown -R mysql:mysql /usr/local/mysql &> /dev/null #將目錄屬主屬組給改成mysql #須要使用cmake編譯,所以須要提早安裝cmake #可使用yum 安裝 --> yum -y install cmake cd /usr/local/lamp tar xf cmake-2.8.6.tar.gz -C /usr/local cd /usr/local/cmake-2.8.6/ ./bootstrap --prefix=/usr/local/cmake &> /dev/null gmake &> /dev/null && gmake install &> /dev/null cmake_num=`echo $?` [ $cmake_num -ne 0 ] && c_err "cmake install fail" && exit 15 || c_scc "cmake install Success" #mysql 所需rpm package yum -y install ncurses-devel* &> /dev/null #源碼安裝mysql cd /usr/local/lamp tar xf mysql-5.5.22.tar.gz -C /usr/local cd /usr/local/mysql-5.5.22/ cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all #-DDEFAULT_COLLATION=utf8_general_ci #-DMYSQL_TCP_PORT=3306 --> MySQL的監聽端口 make &> /dev/null && make install &>/dev/null #mysql數據庫編譯安裝須要等待必定時間,大約20分鐘 mysql_num=`echo $?` [ $mysql_num -ne 0 ] && c_err "mysql install fail" && exit 20 || c_scc "mysql install Success" #源碼安裝完後要進行數據庫的初始化操做 cd /usr/local/mysql-5.5.22/ rm -rf /etc/my.cnf cp support-files/my-medium.cnf /etc/my.cnf cp support-files/mysql.server /etc/init.d/mysqld #複製到系統,製做啓動服務 /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ chmod 755 /etc/init.d/mysqld #修改屬性 chkconfig --add /etc/init.d/mysqld #添加爲服務 chkconfig mysqld --level 235 on #設置在235 /etc/init.d/mysqld start &> /dev/null #service mysqld start netstat -nltp | grep '3306' &> /dev/null [ $? -eq 0 ] && c_scc "3306 port open!!" || c_err "3306 port off!!" #檢查3306端口是否開通 #讓mysql能夠正常執行,須要導入一下命令 echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile source /etc/profile [ $? -eq 0 ] && c_scc "mysql server Can normally access!!" || c_err "mysql server Access failed!!" . /etc/profile . /etc/profile #[root@ ~]#mysql 或 /usr/local/mysql/bin/mysql --> 測試mysql是否正常,沒有密碼直接進入數據庫 ################################################################## ###### PHP server install ###### ################################################################## rpm -e php php-cli php-ldap php-common php-mysql --nodeps &>/dev/null yum -y install zlib-devel* libxml2-devel* #安裝擴展工具 #安裝libmcrypt cd /usr/local/lamp tar zxf libmcrypt-2.5.8.tar.gz -C /usr/src/ cd /usr/src/libmcrypt-2.5.8/ ./configure && make && make install [ $? -eq 0 ] && echo "success" || echo "fail" exit ln -s /usr/local/lib/libmcrypt.* /usr/lib/ #安裝mhash cd /usr/local/lamp tar zxf mhash-0.9.9.9.tar.gz -C /usr/src/ cd /usr/src/mhash-0.9.9.9/ ./configure && make && make install ln -s /usr/local/lib/libmhash* /usr/lib/ 安裝mcrypt cd /usr/local/lamp tar zxf mcrypt-2.6.8.tar.gz -C /usr/src cd /usr/src/mcrypt-2.6.8/ export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ./configure && make && make install ./configure && make && make install [ $? -eq 0 ] && echo "success" || echo "fail" exit #安裝php cd /usr/local/lamp tar zxf php-5.3.6.tar.gz -C /usr/src cd /usr/src/php-5.3.6/ ./configure --prefix=/usr/local/php5 --with-mcrypt --with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php5 --enable-mbstring make && make install [ $? -eq 0 ] && echo "success" || echo "fail" exit #配置php cp /usr/src/php-5.3.6/php.ini-development /usr/local/php5/php.ini #安裝擴展工具 cd /usr/local/lamp/ tar zxvf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz -C /usr/src cd /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php-5.3.x/ cp ZendGuardLoader.so /usr/local/php5/lib/php #修改php.ini配置文件 echo Zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so >> /usr/local/php5/php.ini echo Zend_loader.enable=1 >> /usr/local/php5/php.ini #httpd.conf 配置的調整 sed -i '310i AddType application/x-httpd-php .php' /usr/local/httpd/conf/httpd.conf sed -i '167 s/html/php/' /usr/local/httpd/conf/httpd.conf touch /usr/local/httpd/htdocs/ceshi.php echo -e "<?php\nphpinfo();\n?>" > /usr/local/httpd/htdocs/ceshi.php #測試apache與PHP是否能夠調試通 sed -i '53 s/^#//' /usr/local/httpd/conf/httpd.conf /usr/local/httpd/bin/apachectl start &> /dev/null /usr/local/httpd/bin/apachectl restart &> /dev/null curl http://127.0.0.1/ceshi.php &> /dev/null [ $? -eq 0 ] && c_scc "web server and php Access Success !!" || c_err "web server and php Access failed!!"
須要的包以下,這是我用的包。php
[root@localhost lamp]# lshtml
cmake-2.8.6.tar.gz mcrypt-2.6.8.tar.gz php-5.3.6.tar.gznode
httpd-2.2.17.tar.gz mhash-0.9.9.9.tar.gz phpMyAdmin-3.3.10-all-languages.tar.gzmysql
libmcrypt-2.5.8.tar.gz mysql-5.5.22.tar.gz ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gzlinux
只要lamp 環境搭好了,裝個wordpress 就很是簡單了,傻瓜式建站。web
安裝wordpress(我是在linux虛擬機裏面)sql
1.安裝phpMyadmin,在本地登陸建立一個數據庫用於wp 的數據庫。數據庫
2.官網下載wordpress,解壓文件。apache
3.找到安裝的http的目錄,在httpd的htdocs中建立一個文件夾,任意取名,最好叫wp.
bootstrap
4.把wp解壓好的文件移動到該目錄下
5.打開瀏覽器輸入http://localhost/wp/wordpress安裝嚮導安裝便可。
可是要實現不少的功能就不是很容易了,這是我最近發現的一個word press 搭建的我的博客,我以爲很是的好,連接以下。