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
接下来就可以启动服务进行测试了。
二、安装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();
?>
下面在测试下与mysql的连接
$link=mysql_connect('localhost','root','');
if ($link)
echo "Sucess!!";
echo "Failuser!!";
mysql_close();
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
用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 按步骤安装即可
五
、安装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的支持了
之后我们在重新做下ab压力测试,对比一下之前的看看,这里就不介绍了。