LAMP平臺 ,MySQL、httpd、php安裝


LAMP平臺


編譯安裝apache解決依賴關係


安裝apr

wKiom1PrZ9azyD6HAAez2YRGquo172.jpg




編譯安裝apr-util

wKiom1PraMrCDxfzAALx1cJ5h7k838.jpg


安裝pcre-devel軟件包。

使用命令  yum install pcre-devel -y



編譯安裝httpd-2.4.9


# tar xf httpd-2.4.9.tar.bz2

# cd httpd-2.4.9

# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd2.4 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event

# 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。


3、修改httpd的主配置文件,設置其Pid文件的路徑

編輯/etc/httpd/httpd.conf,添加如下行即可:

PidFile  "/var/run/httpd.pid"


4、提供SysV服務腳本/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/apache/bin/apachectl

httpd=${HTTPD-/usr/local/apache/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/rc.d/init.d/httpd


加入服務列表:

# chkconfig --add httpd




安裝MySQL-5.5.33

1、準備數據存放的文件系統


新建一個邏輯卷,並將其掛載至特定目錄即可。這裏不再給出過程。


這裏假設其邏輯卷的掛載目錄爲/mydata,而後需要創建/mydata/data目錄做爲mysql數據的存放目錄。


2、新建用戶以安全方式運行進程:


# groupadd -r mysql

# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql

# chown -R mysql:mysql /mydata/data


3、安裝並初始化mysql-5.5.33

# tar xf mysql-5.5.33-linux2.6-i686.tar.gz -C /usr/local

# cd /usr/local/

# ln -sv mysql-5.5.33-linux2.6-i686  mysql

# cd mysql 


# chown -R mysql:mysql  .

# scripts/mysql_install_db --user=mysql --datadir=/mydata/data

# chown -R root  .


4、爲mysql提供主配置文件:


# cd /usr/local/mysql

# cp support-files/my-large.cnf  /etc/my.cnf


並修改此文件中thread_concurrency的值爲你的CPU個數乘以2,比如這裏使用如下行:

thread_concurrency = 2


另外還需要添加如下行指定mysql數據文件的存放位置:

datadir = /mydata/data


5、爲mysql提供sysv服務腳本:


# cd /usr/local/mysql

# cp support-files/mysql.server  /etc/rc.d/init.d/mysqld

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


添加至服務列表:

# chkconfig --add mysqld

# chkconfig mysqld on


6、輸出mysql的man手冊至man命令的查找路徑:


編輯/etc/man.config,添加如下行即可:

MANPATH  /usr/local/mysql/man


7、輸出mysql的頭文件至系統頭文件路徑/usr/include:


這可以通過簡單的創建鏈接實現:

# ln -sv /usr/local/mysql/include  /usr/include/mysql


8、輸出mysql的庫文件給系統庫查找路徑:


# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf


而後讓系統重新載入系統庫:

# ldconfig


9、修改PATH環境變量,讓系統可以直接使用mysql的相關命令。具體實現過程這裏不再給出。




編譯安裝php-5.4.26


1、解決依賴關係:


請配置好yum源(系統安裝源及epel源)後執行如下命令:

# yum -y groupinstall "Desktop Platform Development" 

# yum -y install bzip2-devel libmcrypt-devel



2、編譯安裝php-5.4.26


首先下載源碼包至本地目錄,下載位置ftp://172.16.0.1/pub/Sources/new_lamp。


# tar xf php-5.4.26.tar.bz2

# cd php-5.4.26

# ./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/apache/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 intall


爲php提供配置文件:

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


3、 編輯apache配置文件httpd.conf,以apache支持php

 

 # vim /etc/httpd/httpd.conf

 1、添加如下二行

   AddType application/x-httpd-php  .php

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


 2、定位至DirectoryIndex index.html 

   修改爲:

    DirectoryIndex  index.php  index.html



重新啓動httpd。檢測php是否可以正常使用。


wKiom1PrcfOw0w4PAAChNYT6wC8300.jpg


安裝xcache,爲php加速:


1、安裝

# tar xf xcache-3.0.3.tar.gz

# cd xcache-3.0.3

# /usr/local/php/bin/phpize

# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config

# make && make install


安裝結束時,會出現類似如下行:

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20100525/


2、編輯php.ini,整合php和xcache:


首先將xcache提供的樣例配置導入php.ini

# mkdir /etc/php.d

# cp xcache.ini /etc/php.d


說明:xcache.ini文件在xcache的源碼目錄中。


接下來編輯/etc/php.d/xcache.ini,找到zend_extension開頭的行,修改爲如下行:

zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so

wKioL1PrdArTUWWgAAXgAI_QdR8428.jpg

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章