Linux編譯安裝LAMP+Xcache環境(Apache2.4.23+MySQL5.6.33+php5.6.9+Xcache3.2.0)

2016年11月17日20:07:50 發表評論 4,706 ℃

本次編譯安裝LAMP環境版本:

Linux:Centos6x-el6.x86_64

Apache:2.4.23

Mysql:5.6.33 (rpm,通用二進制,源碼)

PHP:5.6.9

Xcache:3.2.0

安裝順序:Aapche-->Mysql-->PHP-->Xcache

首先關閉selinux 

#vim /etc/sysconfig/selinux

把里邊的一行改為

SELINUX=disabled  //重啟生效

#setenforce 0 臨時生效

一、編譯安裝httpd2.4.23

1、安裝 Development tools和 Server Platform Development開發環境。

#yum groupinstall -y Development Tools Server Platform Development

2、安裝apr 然后安裝apr-util,默認已經安裝,可以不用安裝

#wget http://mirrors.cnnic.cn/apache/apr/apr-1.5.2.tar.bz2

#tar -jxf apr-1.5.2.tar.bz2

#cd apr-1.5.2

#./configure --prefix=/usr/local/apr

#make

#make install

#wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.5.4.tar.bz2

#tar -jxf apr-util-1.5.4.tar.bz2

#cd apr-util-1.5.4

#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

#make

#make install

3、編譯安裝httpd2.4.23

#yum install -y pcre-devel

#yum install openssl-devel

#wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.23.tar.bz2

#./configure --prefix=/usr/local/httpd -sysc --enable-so --enable-rewrite --enable-ssl --enable--cgi --enable-cgid --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-ssl=/etc/pki/tls

#make

#make install

補充:

(1)構建MPM為靜態模塊

在全部平臺中,MPM都可以構建為靜態模塊。在構建時選擇一種MPM,鏈接到服務器中。如果要改變MPM,必須重新構建。為了使用指定的MPM,請在執行configure腳本 時,使用參數 --with-mpm=NAME。NAME是指定的MPM名稱。編譯完成后,可以使用 ./httpd -l 來確定選擇的MPM。 此命令會列出編譯到服務器程序中的所有模塊,包括 MPM。

(2)構建 MPM 為動態模塊

在Unix或類似平臺中,MPM可以構建為動態模塊,與其它動態模塊一樣在運行時加載。 構建 MPM 為動態模塊允許通過修改LoadModule指令內容來改變MPM,而不用重新構建服務器程序。在執行configure腳本時,使用--enable-mpms-shared選項即可啟用此特性。當給出的參數為all時,所有此平臺支持的MPM模塊都會被安裝。還可以在參數中給出模塊列表。默認MPM,可以自動選擇或者在執行configure腳本時通過--with-mpm選項來指定,然后出現在生成的服務器配置文件中。編輯LoadModule指令內容可以選擇不同的MPM。

4、配置httpd2.4.23

#vim /etc/httpd/httpd.conf

在ServerRoot "/usr/local/httpd"后面添加一行PidFile "/var/run/httpd.pid"

#vim /etc/rc.d/init.d/httpd

添加下列腳本:

#!/bin/bash

#

# httpd        Startup script for the Apache HTTP Server

#

# chkconfig: - 85 15

# description: Apache is a World Wide Web server.  It is used to serve \

#        HTML files and CGI.

# processname: httpd

# config: /etc/httpd/conf/httpd.conf

# config: /etc/sysconfig/httpd

# pidfile: /var/run/httpd.pid

# Source function library.

. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/httpd ]; then

        . /etc/sysconfig/httpd

fi

# Start httpd in the C locale by default.

HTTPD_LANG=${HTTPD_LANG-"C"}

# This will prevent initlog from swallowing up a pass-phrase prompt if

# mod_ssl needs a pass-phrase from the user.

INITLOG_ARGS=""

# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server

# with the thread-based "worker" MPM; BE WARNED that some modules may not

# work correctly with a thread-based MPM; notably PHP will refuse to start.

# Path to the apachectl script, server binary, and short-form for messages.

#這里的路徑和你編譯安裝的路徑要一致

apachectl=/usr/local/httpd/bin/apachectl

httpd=${HTTPD-/usr/local/httpd/bin/httpd}

prog=httpd

pidfile=${PIDFILE-/var/run/httpd.pid}

lockfile=${LOCKFILE-/var/lock/subsys/httpd}

RETVAL=0

start() {

        echo -n $"Starting $prog: "

        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS

        RETVAL=$?

        echo

        [ $RETVAL = 0 ] && touch ${lockfile}

        return $RETVAL

}

stop() {

 echo -n $"Stopping $prog: "

 killproc -p ${pidfile} -d 10 $httpd

 RETVAL=$?

 echo

 [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}

}

reload() {

    echo -n $"Reloading $prog: "

    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then

        RETVAL=$?

        echo $"not reloading due to configuration syntax error"

        failure $"not reloading $httpd due to configuration syntax error"

    else

        killproc -p ${pidfile} $httpd -HUP

        RETVAL=$?

    fi

    echo

}

# See how we were called.

case "$1" in

  start)

 start

 ;;

  stop)

 stop

 ;;

  status)

        status -p ${pidfile} $httpd

 RETVAL=$?

 ;;

  restart)

 stop

 start

 ;;

  condrestart)

 if [ -f ${pidfile} ] ; then

 stop

 start

 fi

 ;;

  reload)

        reload

 ;;

  graceful|help|configtest|fullstatus)

 $apachectl $@

 RETVAL=$?

 ;;

  *)

 echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"

 exit 1

esac

exit $RETVAL


#chmod +x /etc/init.d/httpd 為此腳本賦予執行權限:

#chkconfig --add httpd   //添加服務到開機啟動

#chkconfig --level 35 httpd on //設定啟動級別

#vim /etc/profile.d/httpd.sh  //添加httpd環境變量

添加export PATH=$PATH:/usr/local/httpd/bin

#vim /etc/sysconfig/iptables

添加 -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

#/etc/init.d/iptables restart

5、啟用虛擬主機

#vim /etc/httpd/httpd.conf

找到DocumentRoot "/usr/local/httpd/htdocs"

改成#DocumentRoot "/usr/local/httpd/htdocs"

找到#Include /etc/httpd/extra/httpd-vhosts.conf

改成Include /etc/httpd/extra/httpd-vhosts.conf

#/etc/init.d/httpd restart    

添加站點,編輯 /etc/httpd/extra/httpd-vhosts.conf文件即可,新建站點格式如下:

<VirtualHost *:80>

    ServerAdmin admin@amd5.cn

    DocumentRoot "/www/wwwroot/test"

    ServerName amd5.cn

    ServerAlias m.maowutv.com

    ErrorLog "/var/log/httpd/amd5.cn-error_log"

    CustomLog "/var/log/httpd/amd5.cn-access_log" combined

</VirtualHost>

說明:重啟httpd如果提示如下錯誤:

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using xxxx. Set the 'ServerName' directive globally to suppress this message

可以vim /etc/httpd/httpd.conf 找到

#ServerName www.example.com:80

更改為:

ServerName localhost:80

6、啟用服務器狀態(可省略)

mod_status模塊可以讓管理員查看服務器的執行狀態,它通過一個HTML頁面展示了當前服務器的統計數據。這些數據通常包括但不限于:

(1) 處于工作狀態的worker進程數;

(2) 空閑狀態的worker進程數;

(3) 每個worker的狀態,包括此worker已經響應的請求數,及由此worker發送的內容的字節數;

(4) 當前服務器總共發送的字節數;

(5) 服務器自上次啟動或重啟以來至當前的時長;

(6) 平均每秒鐘響應的請求數、平均每秒鐘發送的字節數、平均每個請求所請求內容的字節數;

啟用狀態頁面的方法很簡單,只需要在主配置文件中添加如下內容即可:

<Location /server-status>

    SetHandler server-status

    Require all granted

</Location>

需要提醒的是,這里的狀態信息不應該被所有人隨意訪問,因此,應該限制僅允許某些特定地址的客戶端查看。比如使用Require ip 172.16.0.0/16來限制僅允許指定網段的主機查看此頁面。

7、啟用openssl

#vim /etc/init.d/httpd restart

找到#LoadModule ssl_module modules/mod_ssl.so

改成LoadModule ssl_module modules/mod_ssl.so

找到#Include /etc/httpd/extra/httpd-ssl.conf

改為Include /etc/httpd/extra/httpd-ssl.conf

#/etc/init.d/httpd restart    

編輯/etc/httpd/extra/httpd-ssl.conf可以對openssl進行配置。

  openssl詳細配置可以參考阿湯博客教程 Centos Apache基于openssl的https服務配置

8、profork、worker、event參數設置

#vim /etc/httpd/httpd.conf

找到#Include /etc/httpd/extra/httpd-mpm.conf

改為Include /etc/httpd/extra/httpd-mpm.conf

編輯/etc/httpd/extra/httpd-mpm.conf可對相應參數做調整

#/etc/init.d/httpd restart  

  profork、worker、event三種工作模式比較可以參考阿湯博客文章 Apache的mpm prefork、worker、event三種工作模式比較

二、mysql5.6.33通用二進制安裝配置:

1、下載解壓,并添加mysql系統用戶和mysql系統組

#wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz

#tar -zxf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz -C /usr/local/

#cd /usr/local/

#ln -sv mysql-5.6.33-linux-glibc2.5-x86_64 mysql

#groupadd -r -g 306 mysql

#useradd -g 306 -r -u 306 mysql

#chown -R mysql:mysql /usr/local/mysql/*

2、創建一個邏輯卷存放數據庫數據,方便以后擴展,也可以mkdir一個目錄,存放。(數據量不大,可以省略此步驟,直接在現有磁盤新建目錄存放)

#fdisk /dev/vdb      //創建一個20G的分區 分區id 為8e

#partprobe /dev/vdb  //讓內核識別分區 cat /proc/partitions 查看,如果命令無法識別,重啟服務器

#pvcreate /dev/vdb2  //在創建的分區上面創建pv

#vgcreate mysqlvg/dev/vdb2   //創建vg

#lvcreate -n mysqllv -L 20G mysqlvg  //創建lv

#mkfs.ext4 /dev/mysqlvg/mysqllv   

#mkdir   /mysql_data/

#mount /dev/mysqlvg/mysqllv /mysql_data/

#vim /etc/fstab 

添加/dev/mapper/mysqlvg-mysqllv  /mysql_data         ext4    defaults 0 0

3、配置初始化安裝mysql

#mkdir /mysql_data/data

#chmod o-rx /mysql_data/data/    //取消其他用戶組權限

#chown -R mysql.mysql /mysql_data/data/  //設置數據存放路徑 用戶和組

#/usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/mysql_data/data/ --keep-my-cnf

#chown -R root /usr/local/mysql/*

#cp support-files/mysql.server /etc/init.d/mysqld  //為mysql提供sysv服務腳本

#chmod +x /etc/rc.d/init.d/mysqld

#chkconfig --add mysqld   //設置開機啟動,默認2345級別啟動

#cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

#vim /etc/my.cnf

添加下列兩行指定安裝路徑和數據庫存放路徑

basedir = /usr/local/mysql

datadir = /mysql_data/data

4、環境變量、頭文件、庫文件、幫助手冊設置(可省略)

#vim /etc/profile.d/mysql.sh   //設置環境變量

添加export PATH=$PATH:/usr/local/mysql/bin

#vim /etc/man.config   //設置幫助手冊

添加MANPATH /usr/local/mysql/man

#vim /etc/ld.so.conf.d/mysql.conf  //導出庫文件

添加/usr/local/mysql/lib

#ldconfig -v   //重新建立庫文件緩存

#ln -sv /usr/local/mysql/include/ /usr/include/mysql  //導出頭文件

5、設置mysql密碼

#mysql

>set password for 'root'@'localhost' =password('12344321');  //默認密碼為空,這里更改為12344321

>quit

Linux編譯安裝LAMP+Xcache環境(Apache2.4.23+MySQL5.6.33+php5.6.9+Xcache3.2.0)

三、編譯安裝php-5.6.9

1、安裝依賴擴展文件

#yum install -y libxml2 libxml2-devel bzip2 bzip2-devel

如果想讓編譯的php支持mcrypt擴展,此處還需要下載如下兩個rpm包并安裝(如果不需要此擴展,省略 --with-mcrypt即可 ):

#wget ftp://rpmfind.net/linux/dag/redhat/el6/en/x86_64/dag/RPMS/libmcrypt-2.5.7-1.2.el6.rf.x86_64.rpm

#wget ftp://rpmfind.net/linux/dag/redhat/el6/en/x86_64/dag/RPMS/libmcrypt-devel-2.5.7-1.2.el6.rf.x86_64.rpm

#rpm -ivh libmcrypt-2.5.7-1.2.el6.rf.x86_64.rpm  libmcrypt-devel-2.5.7-1.2.el6.rf.x86_64.rpm 

2、編譯安裝php5.6.9

#wget http://mirrors.sohu.com/php/php-5.6.9.tar.bz2

#tar jxf php-5.6.9.tar.bz2

#cd php-5.6.9

#./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml  --enable-sockets --with-apxs2=/usr/local/httpd/bin/apxs --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts

說明:

1、這里為了支持apache的worker或event這兩個MPM,編譯時使用了--enable-maintainer-zts選項。

2、如果使用PHP5.3以上版本,為了鏈接MySQL數據庫,可以指定mysqlnd,這樣在本機就不需要先安裝MySQL或MySQL開發包了。mysqlnd從php 5.3開始可用,可以編譯時綁定到它(而不用和具體的MySQL客戶端庫綁定形成依賴),但從PHP 5.4開始它就是默認設置了。

# ./configure --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd


#make

#make test

#make install

#cp php.ini-production /etc/php.ini

3、配置apache支持php

#vim /etc/httpd/httpd.conf

找到AddType application/x-gzip .gz .tgz添加如下兩行

AddType application/x-httpd-php  .php

AddType application/x-httpd-php-source  .phps

找到DirectoryIndex index.html修改為:

DirectoryIndex  index.php  index.html

#/etc/init.d/httpd restart    

四、編譯安裝Xcache-3.2.0

#wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz

#tar -zxf xcache-3.2.0.tar.gz

#cd xcache-3.2.0

#./configure --enable-xcache --with-php-c>

#make

#make install

#mkdir /etc/php.d

#cp xcache.ini /etc/php.d/

#vim /etc/php.d/xcache.ini

找到xcache.count =  改為你當前服務器cpu個數(cat /proc/cpuinfo |grep -c processor查看個數)

#/etc/init.d/httpd restart

Linux編譯安裝LAMP+Xcache環境(Apache2.4.23+MySQL5.6.33+php5.6.9+Xcache3.2.0)

【騰訊云】云服務器、云數據庫、COS、CDN、短信等云產品特惠熱賣中

發表評論

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: