天天看點

LAMP(二)

httpd 2.4.2 + mysql-5.5.24 + php-5.4.4編譯安裝過程:

一、編譯安裝apache

1、httpd-2.4.2需要較新版本的apr和apr-util,是以需要事先對其進行更新,另外,httpd-2.4.2編譯過程也要依賴于pcre-devel軟體包,需要事先安裝。

# yum -y install pcre-devel

# tar xf apr-1.4.6.tar.bz2

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

# make

# make install

tar xf apr-util-1.4.1.tar.bz2

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

2、安裝http

# tar xf httpd-2.4.2.tar.bz2

# cd httpd-2.4.2

# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

# make && make install

3、修改httpd的主配置檔案,設定其Pid檔案的路徑

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

PidFile "/var/run/httpd.pid"

4、提供啟動服務腳本/etc/rc.d/init.d/httpd,從别的機器copy的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 = 0 ] && rm -f ${lockfile} ${pidfile}

reload() {

echo -n $"Reloading $prog: "

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

echo $"not reloading due to configuration syntax error"

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

else

killproc -p ${pidfile} $httpd -HUP

# See how we were called.

case "$1" in

start)

start

;;

stop)

stop

status)

status -p ${pidfile} $httpd

restart)

condrestart)

if [ -f ${pidfile} ] ; then

reload)

reload

graceful|help|configtest|fullstatus)

$apachectl $@

*)

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

設定PATH,省的老用絕對路徑,永久生效的話寫在/etc/profile/裡export前面即可

# export PATH=/usr/local/apache/bin/:$PATH

接下來就可以啟動服務進行測試了。

LAMP(二)

二、安裝mysql-5.5.24

1、建立使用者資訊,和資料存放位置

# groupadd -r mysql

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

# mkdir -p /mydata/data

# chown -R mysql.mysql /mydata/data/

因為Mysql比較大,,是以這裡用的是綠色安裝的軟體解壓即可使用

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

# cd /usr/local/

# ln -s mysql-5.5.24-linux2.6-i686/ mysql

# cd mysql

# chown -R mysql.mysql .

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

# chown -R root .

2、為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

3、為mysql提供服務啟動腳本:

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

添加至服務清單:

# chkconfig --add mysqld

# chkconfig mysqld on

修改PATH環境變量,讓系統可以直接使用mysql的相關指令。重新開機生效的話一樣寫在/etc/profile

# export PATH=/usr/local/mysql/bin:$PATH

三、編譯安裝php-5.4.4

1、需要依賴關系

# yum -y groupinstall "X Software Development"

如果想讓編譯的php支援mcrypt擴充,此處還需要下載下傳安裝如下軟體包

libmcrypt-2.5.7-5.el5.i386.rpm

libmcrypt-devel-2.5.7-5.el5.i386.rpm

2、編譯安裝php-5.4.4.

# tar xf php-5.4.4.tar.bz2

# cd php-5.4.4

# ./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 --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2

3、為php提供配置檔案:

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

4、編輯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

5、重新啟動httpd,發現有錯誤。這是因為SElinux的原因,關閉會就Ok了

service httpd restart

Stopping httpd: [ OK ]

Starting httpd: httpd: Syntax error on line 148 of /etc/httpd/httpd.conf: Cannot load /usr/local/apache/modules/libphp5.so into server: /usr/local/apache/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied

[FAILED]

6、這裡寫個.php頁面做下測試

# cd /usr/local/apache/htdocs/

# cat index.php

<?php

phpinfo();

?>

LAMP(二)

下面在測試下與mysql的連接配接

$link=mysql_connect('localhost','root','');

if ($link)

echo "Sucess!!";

echo "Failuser!!";

mysql_close();

LAMP(二)

OK,成功了

三,安裝phpMyAdmin

# tar xf phpMyAdmin-3.5.1-all-languages.tar.bz2 -C /usr/local/apache/htdocs/

# mv phpMyAdmin-3.5.1-all-languages/ phpmyadmin

# service httpd restart

首先需要給資料庫設定密碼

mysql> SET PASSWORD FOR root@'localhost'=PASSWORD('redhat');

Query OK, 0 rows affected (0.09 sec)

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.04 sec)

# mv config.sample.inc.php config.inc.php

# vim config.inc.php 在a8b這裡随便添加字元即可

$cfg['blowfish_secret'] = 'a8b7cfdafs6d'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

下面通路下http://192.168.80.139/phpmyadmin

LAMP(二)

用apache自帶的ab來做下壓力測試,模拟下1000請求,100個并發

# ab -n 1000 -c 100 http://192.168.80.139/phpmyadmin/

在進行測試的時候通路發現已經通路很慢了,看下結果

Concurrency Level: 100 并發連接配接數

Time taken for tests: 39.878 seconds 測試過程消耗時間

Complete requests: 1000 總共完成的請求數

Failed requests: 0 失敗的請求數

Write errors: 0

Total transferred: 7502552 bytes 測試過程網絡傳輸量

HTML transferred: 6784000 bytes HTML記憶體傳輸量

Requests per second: 25.08 [#/sec] (mean) 平均每秒響應的請求數

Time per request: 3987.764 [ms] (mean) 平均每請求的響應時間

、安裝Discuz論壇

# unzip Discuz_7.2_FULL_SC_UTF8.zip -d /usr/local/apache/htdocs/

# vim /etc/php.ini

# short_open_tag = On

# cd /usr/local/apache/htdocs/upload/

# chown -R daemon config.inc.php p_w_uploads/ forumdata/ uc_client/data/cache/

下面通路http://192.168.80.139/upload/install 按步驟安裝即可

LAMP(二)

、安裝xcache-2.0.0

# tar xf xcache-2.0.0.tar.bz2

# cd xcache-2.0.0

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

将xcache提供的樣例導入到php.ini中

mkdir /etc/php.d

cp xcache.ini /etc/php.d

# cat xcache.ini >> /etc/php.ini

添加,make install後輸出的一段話下的xcache.so

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

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

# service httpd restart

通過之前的index.php可以檢視到這裡已經有xcache的支援了

LAMP(二)

之後我們在重新做下ab壓力測試,對比一下之前的看看,這裡就不介紹了。

繼續閱讀