A-A+

centos6.4安装配置lamp环境的方法

2016年02月20日 站长资讯 暂无评论

系统环境:

CentOS 6.4

软件源码包版本:

httpd-2.4.10

php-5.4.32

mysql-5.5.39

一、编译安装apache2.4

1、下载所需的软件源码包,使用wget命令进行下载:

apr-1.5.1:wget http://mirrors.hust.edu.cn/apache//apr/apr-1.5.1.tar.bz2

apr-util-1.5.3:wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.3.tar.bz2

httpd-2.4.10:wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.10.tar.bz2

2、解决依赖关系

(1)使用yum安装系统所需的一些依赖库

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers pcre pcre-devel

(注意:在这次的安装实验中,只需要yum安装openssl,openssl-devel,pcre,pcre-devel即可正常编译完成httpd,而且上面所列出的库与工具,有不少是系统已经安装过了的,这里只是进行一下更新,还有其他的一些库是为下面编译安装mysql与php作的准备)

(2) 先编译安装apr

  1. tar jxf apr-1.5.1.tar.bz2  
  2. cd apr-1.5.1  
  3. ./configure --prefix=/usr/local/apr  
  4. make && make install  

(3) 再编译安装apr-util

  1. tar jxf apr-util-1.5.3.tar.bz2  
  2. cd apr-util-1.5.3  
  3. ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr  #(注意:--with-apr=/usr/local/apr是上面安装apr的路径)  
  4. make && make install  

(解释:apr,全称为Apache portable Run-time libraries,叫Apache可移植运行库,主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库,安装apache都需要先安装这个库的)

3、正式编译安装httpd

  1. tar jxf httpd-2.4.10.tar.bz2  
  2. cd httpd-2.4.10  
  3. ./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 --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-mpm=event  
  4. make && make install   http://www.xiaoxiongboke.com/  

4、配置httpd

(1)为httpd提供sysv服务启动与关闭脚本,把以下内容复制成/etc/init.d/httpd,并且给予此文件执行权限(chmod +x /etc/rc.d/init.d/httpd),就可以直接使用service httpd 的命令形式控制httpd服务:

  1. #!/bin/bash  
  2. #  
  3. # httpd        Startup script for the Apache HTTP Server  
  4. #  
  5. # chkconfig: - 85 15  
  6. # description: Apache is a World Wide Web server.  It is used to serve \  
  7. #       HTML files and CGI.  
  8. # processname: httpd  
  9. # config: /etc/httpd/conf/httpd.conf  
  10. # config: /etc/sysconfig/httpd  
  11. # pidfile: /var/run/httpd.pid  
  12.   
  13.    
  14. # Source function library.  
  15. . /etc/rc.d/init.d/functions  
  16.   
  17.    
  18. if [ -f /etc/sysconfig/httpd ]; then  
  19.         . /etc/sysconfig/httpd  
  20. fi  
  21.   
  22.    
  23. # Start httpd in the C locale by default.  
  24. HTTPD_LANG=${HTTPD_LANG-"C"}  
  25.   
  26.    
  27. # This will prevent initlog from swallowing up a pass-phrase prompt if  
  28. # mod_ssl needs a pass-phrase from the user.  
  29. INITLOG_ARGS=""  
  30.   
  31.    
  32. # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server  
  33. # with the thread-based "worker" MPM; BE WARNED that some modules may not  
  34. # work correctly with a thread-based MPM; notably PHP will refuse to start.  
  35.   
  36.    
  37. # Path to the apachectl script, server binary, and short-form for messages.  
  38. apachectl=/usr/local/apache/bin/apachectl  
  39. httpd=${HTTPD-/usr/local/apache/bin/httpd}  
  40. prog=httpd  
  41. pidfile=${PIDFILE-/var/run/httpd.pid}  
  42. lockfile=${LOCKFILE-/var/lock/subsys/httpd}  
  43. RETVAL=0  
  44.   
  45.    
  46. start() {  
  47.         echo -n $"Starting $prog: "  
  48.         LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS  
  49.         RETVAL=$?  
  50.         echo  
  51.         [ $RETVAL = 0 ] && touch ${lockfile}  
  52.         return $RETVAL  
  53. }  
  54.   
  55.    
  56. stop() {  
  57. echo -n $"Stopping $prog: "  
  58. killproc -p ${pidfile} -d 10 $httpd  
  59. RETVAL=$?  
  60. echo  
  61. [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}  
  62. }  
  63. reload() {  
  64.     echo -n $"Reloading $prog: "  
  65.     if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then  
  66.         RETVAL=$?  
  67.         echo $"not reloading due to configuration syntax error"  
  68.         failure $"not reloading $httpd due to configuration syntax error"  
  69.     else  
  70.         killproc -p ${pidfile} $httpd -HUP  
  71.         RETVAL=$?  
  72.     fi  
  73.     echo  
  74. }  
  75.   
  76.    
  77. # See how we were called.  
  78. case "$1" in  
  79.   start)  
  80. start  
  81. ;;  
  82.   stop)  
  83. stop  
  84. ;;  
  85.   status)  
  86.         status -p ${pidfile} $httpd  
  87. RETVAL=$?  
  88. ;;  
  89.   restart)  
  90. stop  
  91. start  
  92. ;;  
  93.   condrestart)  
  94. if [ -f ${pidfile} ] ; then  
  95. stop  
  96. start  
  97. fi  
  98. ;;  
  99.   reload)  
  100.         reload  
  101. ;;  
  102.   graceful|help|configtest|fullstatus)  
  103. $apachectl $@  
  104. RETVAL=$?  
  105. ;;  
  106.   *)  
  107. echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"  
  108. exit 1  
  109. esac  
  110. exit $RETVAL  

(2)把httpd服务添加为开机自启动:

chkconfig --add httpd

chkconfig httpd on

(3)修改httpd主配置文件/etc/httpd/httpd.conf,指定httpd服务的PID文件,直接在配置文件添加如下字段:

PidFile "/var/run/httpd.pid"

(4)启动httpd服务,并进行访问测试

service httpd start

(注:如果启动的时候出现这个警告:httpd: apr_sockaddr_info_get() failed for longren
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName,解决方法:在/etc/httpd/httpd.conf添加ServerName 127.0.0.1)
访问测试:http://your_ipadress,如果出现It Works,就证明httpd编译安装成功

二、编译安装mysql(注:一般来说是先安装mysql再安装php,因为在php编译时需要指定mysql路径)

1、下载所需软件源码包

mysql-5.5.39:http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.39.tar.gz

2、解决库依赖关系

(1)yum安装依赖库

yum -y install cmake #mysql5.5是使用cmake进行编译的

yum -y install bison automake zlib* libxml* ncurses-devel libtool-ltdl-devel* mysql-devel

3、添加mysql用户,下面的编译需要用到

groupadd -r mysql

useradd -g mysql -r -s /sbin/nologin mysql

4、正式编译安装mysql

  1. tar zxf mysql-5.5.39.tar.gz  
  2. cd mysql-5.5.39  
  3. cmake \  
  4. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \  
  5. -DMYSQL_DATADIR=/user/local/mysql/data \  
  6. -DSYSCONFDIR=/etc \  
  7. -DEXTRA_CHARSETS=all \  
  8. -DDEFAULT_CHARSET=utf8 \  
  9. -DDEFAULT_COLLATION=utf8_general_ci \  
  10. -DWITH_INNOBASE_STORAGE_ENGINE=1 \  
  11. -DWITH_ARCHIVE_STORAGE_ENGINE=1 \  
  12. -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \  
  13. -DWITH_FEDERATED_STORAGE_ENGINE=1 \  
  14. -DWITH_PARTITION_STORAGE_ENGINE=1 \  
  15. -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \  
  16. -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \  
  17. -DMYSQL_TCP_PORT=3306 \  
  18. -DWITH_DEBUG=0 \  
  19. -DMYSQL_USER=mysql \  
  20. -DENABLED_LOCAL_INFILE=1  
  21. make && make install  

5、初始化数据库

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

cd /usr/local/mysql

./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data

6、配置数据库

(1)从源码包中拷贝数据库配置文件

cd mysql-5.5.39

cp support-files/my-medium.cnf /etc/my.cnf

(注:support-files目录里有my-small.cnf、my-medium.cnf、my-large.cnf、my-huge.cnf,使用哪个是根据机器的内存大小进行选择)

(2)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

(3)添加至服务列表:

chkconfig --add mysqld

chkconfig mysqld on

7、额外的配置:为了使mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:

(1)输出mysql的man手册至man命令的查找路径:

编辑/etc/man.config,添加如下行即可:

MANPATH /usr/local/mysql/man

(2)输出mysql的头文件至系统头文件路径/usr/include:

通过简单的创建链接实现:

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

(3)输出mysql的库文件给系统库查找路径:

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

让系统重新载入系统库:

ldconfig

(4)修改PATH环境变量,让系统可以直接使用mysql的相关命令,添加如下命令后,需要重新连接会话才能生效

echo "export PATH=$PATH:/usr/local/mysql/bin" > /etc/profile.d/mysql.sh

8、启动mysql服务

service mysqld start

三、源码编译安装php

1、下载所需软件源码包

php-5.4.32:http://cn2.php.net/get/php-5.4.32.tar.bz2/from/this/mirror

libmcrypt-2.5.7:ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz

xcache-3.1.0:http://xcache.lighttpd.net/pub/Releases/3.1.0/xcache-3.1.0.tar.bz2

mhash-0.9.9:http://pan.baidu.com/s/1hqDtQ2C

2、解决依赖关系

  1. tar zxf libmcrypt-2.5.7.tar.gz   
  2. cd libmcrypt-2.5.7  
  3. ./configure  
  4. make && make install  
  5.   
  6. tar jxf mhash-0.9.9.tar.gz  
  7. cd mhash-0.9.9  
  8. ./configure http://www.xiaoxiongboke.com/  
  9. make && make install  

3、正式编译安装php

  1. tar jxf php-5.4.32.tar.bz2  
  2. cd php-5.4.32  
  3. ./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  
  4. make && make install  

4、配置php

(1)从源码包拷贝php配置文件:

cd php-5.4.32

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

(2)整合httpd与php:编辑apache配置文件httpd.conf,使apache支持php

vim /etc/httpd/httpd.conf

a、添加如下二行

AddType application/x-httpd-php .php

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

b、定位至DirectoryIndex index.html修改为:

DirectoryIndex index.php index.html

重新启动httpd服务,或让其重新载入配置文件

测试:在/usr/local/apache/htdocs中添加index.php,里面写入php代码

(3)安装xcache,为php加速

  1. tar jxf xcache-3.1.0.tar.bz2  
  2. cd xcache-3.1.0  
  3. /usr/local/php/bin/phpize  
  4. ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config  
  5. make && make install  

编辑php.ini,整合php和xcache:

首先将xcache提供的样例配置导入php.ini

cd xcache-3.1.0

mkdir /etc/php.d

cp xcache.ini /etc/php.d

然后编辑/etc/php.d/xcache.ini,找到zend_extension开头的行,修改为如下行:

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

重启httpd服务并测试xcache是否与php整合成功

service httpd restart

在index.php添加phpinfo()函数,让后访问index.php,查看xcache选项的显示

标签:

给我留言