kujhg 发表于 2015-3-11 08:19:49

LAMP配置

系统:RHEL6.6-i386
源:remi,epel
主要软件包:
    httpd-2.4.10.tar.bz2
    apr-1.5.1.tar.bz2
    apr-util-1.5.4.tar.bz2
    openlogic-mysql-5.6.10-linux-ia32-bin-glibc2.5-1.zip
    php-5.4.13.tar.bz2
    xcache-3.2.0.tar.gz
    Discuz_X3.2_SC_UTF8.zip

http2.4要求更高版本的apr,红帽系统rpm包版本较低,因此编译httpd之前需要编译apr,以及apr-util。
apr是什么呢?Apache portable Run-time libraries,Apache可移植运行库。主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库。目前,完整的APR实际上包含了三个开发包:apr、apr-util以及apr-iconv,每一个开发包分别独立开发,并拥有自己的版本。APR是一个库,APR-UTIL是这个库所提供的各种应用程序接口,包括XML,LDAP,数据库接口等。

XCache 是一个开源的PHP opcode 缓存器,可以提高PHP的性能,把编译 PHP 后的opcode缓冲到共享内存从而避免重复的编译过程,能够直接使用缓冲区的opcode从而提高速度。

php和apache交互有三种方式:cgi,Module,FastCGI,这里采用Module方式。
   cgi模式:apache进程发现用户访问php页面,需要调用php解释器执行者段代码。
   Module模式:将php做成apache的一个模块。
   FastCGI模式:安装一个php服务器,自身可以像apache的prefork一样,事先生成很多空闲进程,不由apache管理,由这个php服务器自我管理。前端apache需要php功能,只需向这个服务器发起请求,这个服务器分配一个进程给他。安装顺序:
    httpd-->mysql-->php-->xcache


注意:安装包所在目录在/usr/local目录下
步骤一:安装Apache
1,首先安装apr
    cd /usr/local
    tar xf apr-1.5.1.tar.bz2
    cd apr-1.5.1
    ./configure --prefix=/usr/local/apr
    make
    make install
2,安装apr-util
    tar xf 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,安装httpd
    tar xf httpd-2.4.10.tar.bz2
    cd httpd-2.4.10
    ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewrite --enable-ssl   --enable-cgi --enable-cgid --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-mpm=event --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
出现错误configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
解决办法:yum install -y pcre-devel
    make
    make install
    cd /usr/local/apache
    bin/apachectl   start    启动httpd,可看到logs目录下生成的httpd.pid文件。
    bin/apachectl   stop
打开/etc/httpd/httpd.conf文件,加入PidFile "/var/run/httpd.pid",httpd进程启动时生成的Pidfile默认在/usr/local/apache/logs目录下,将此文件放日志目录下显然不合理。

提供SysV风格的启动脚本:/etc/init.d/httpd


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/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/init.d/httpd      给予执行权限
    service httpd start
    chkconfig --add httpd            加入服务列表
    chkconfig httpd on
    echo "PATH=$PATH:/usr/local/apache/bin" > /etc/profile.d/httpd.sh    添加PATH路径
    su

关闭防火墙及selinux,在浏览器输入服务器ip,可看到 "It works!"字样。
至此Apache安装完毕。

步骤二:安装MySql-5.6.10
   

此处用的mysql软件包是二进制免编译包。
    unzipopenlogic-mysql-5.6.10-linux-ia32-bin-glibc2.5-1.zip
    ln -sv/usr/local/mysql-5.6.10/mysql-5.6.10-linux-glibc2.5-i686/ mysql
    cd mysql

    id mysql         查看有无mysql用户,mysql组,没有则创建。

    groupadd -r -g 306 mysql         

    useradd -g 306 -r -u 306 mysql

    chown -R mysql.mysql /usr/local/mysql/*

新建一个逻辑卷,挂载至/mydata下,后在mydata目录下创建data目录,用于存放mysql数据。

磁盘分区略去,存放mysql数据分区为/dev/sdb1。
    partprobe /dev/sdb1
    pvcreate /dev/sdb1
    vgcreate myvg /dev/sdb1
    lvcreate -n mydata -L 5G myvg
    mke2fs -j /dev/myvg/mydata
    mkdir /mydata
    echo "/dev/myvg/mydata/mydata ext3 defaults 0 0" >> /etc/fstab
    mkdir /mydata/data

    chown -R mysql.mysql /mydata/data

    scripts/mysql_install_db --user=mysql --datadir=/mydata/data
    chown -R root /usr/local/mysql/*

    cp support-files/mysql.server /etc/init.d/mysqld
    chkconfig --add mysqld
    cp my.cnf /etc/my.cnf
    将 "datadir=/mydat/data"和 "socket=/tmp/mysql.sock" 放入/etc/my.cnf中。

    ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
    echo "export PATH=$PATH:/usr/local/mysql/bin" > /etc/profile.d/mysql.sh
    echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
    su

    编辑/etc/man.config 找到MANPATH,将" MANPATH /usr/local/mysql/man " 放入。

    ln -sv /usr/local/mysql/include/ /usr/include/mysql
至此mysql安装完毕。

步骤三:编译安装php
    tar xf php-5.4.13.tar.bz2
    cd php-5.4.13
    ./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
    configure: error: mcrypt.h not found. Please reinstall libmcrypt.
    解决办法:yum -y install libmcrypt-devel mhash-devel
    make && make install
    cp php.ini-production /etc/php.ini
    编辑/etc/httpd/httpd.conf,搜索AddType,加上两项"
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
    找到DirectoryIndex index.html将其改为DirectoryIndex index.php index.html

    cd /usr/local/apache/htdocs/
    mv index.html index.php
    vim index.php    测试php与mysql的连接性,apache与mysql的连接性。
      <html><body><h1>It works!</h1></body></html>
            <?php
                $conn=mysql_connect('127.0.0.1','root','');
                if ($conn)
                  echo "Success";
                else
                  echo "Failure";
                phpinfo();
            ?>
   浏览器输入服务器ip地址, 输出Success成功。   

至此php安装成功,接下来安装xcache。

步骤4:编译安装xcache
    tar xf xcache-3.2.0.tar.gz
    cd xcache-3.2.0
    /usr/local/php/bin/phpize
    ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
    make

    make install

    mkdir /etc/php.d
    cp xcache.ini /etc/php.d
    service httpd restart
浏览器输入ip,可看到xcache相关信息。

步骤5:使用discuz论坛测试


vim /etc/httpd/httpd.conf
注释掉/DocumentRoot "/usr/local/apache/htdocs"
取消Include /etc/httpd/extra/httpd-vhosts.conf的注释
    # Virtual hosts
    Include /etc/httpd/extra/httpd-vhosts.conf
vim /etc/httpd/extra/httpd-vhosts.conf

1
2
3
4
5
6
7
8
9
10
11
<VirtualHost *:80>
    DocumentRoot "/www/mingxiao.info"
    <Directory "/www/mingxiao.info">
      Options none
      AllowOverride none
      Require all granted
    </Directory>
    ServerName www.mingxiao.info
    ErrorLog "/var/log/httpd/mingxiao.info_error.log"
    CustomLog "/var/log/httpd/mingxiao.info_access.log" combined
</VirtualHost>





    mkdir -pv /www/mingxiao.info
    mkdir /var/log/httpd
    service httpd restart
    unzip Discuz_X3.2_SC_UTF8.zip
    cd upload/
    cp -R ./* /www/mingxiao.info/
这样在浏览器输入服务器ip就可配置Discuz信息了。
页: [1]
查看完整版本: LAMP配置