5----CentOS6.5源码搭建LAMP--基于module方式实现php(单台机器)

前端之家收集整理的这篇文章主要介绍了5----CentOS6.5源码搭建LAMP--基于module方式实现php(单台机器)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

源码搭建LAMP


软件包下载源:

搜狐镜像源:http://mirrors.sohu.com/

apache下载网:http://mirror.bit.edu.cn/apache/

pcre官网:http://www.pcre.org/

apr官网:http://apr.apache.org/

apache官网:http://httpd.apache.org/

MysqL官网:https://www.mysql.com/

PHP官网:http://php.net/

freetds:http://download.csdn.net/download/xhu_eternalcc/7457555

官网:http://www.freetds.org/

@H_301_30@

实验环境:

CentOS6.5-x86_64单台机器

IP192.168.9.168

版本:

apr-1.5.2

apr-util-1.5.4

httpd-2.4.20

PHP-5.6.22

MysqL-5.6.32


说明,因为PHP要连接MysqL,所以安装顺序为apache,MysqLPHP

注:httpd2.4版本需要较新的apr和apr-util



注:新机器要初始化:参考http://www.jb51.cc/article/p-wtbdmwnu-bqn.html@H_301_30@

注:(生产环境一般包放内网ftp下载比较快,一般前端用Nginx反向代理至后端apache+PHP机器,MysqL独立并做集群)

@H_301_30@

  1. 一、编译安装apache
  1. 1、#yum安装httpd依赖软件
  2. [root@192-168-9-168~]#yuminstall-ygccgcc-c++libtoollibtool-ltdl-devel\
  3. makegd-develfreetype-devellibxml2-devel\
  4. libjpeg-devellibpng-developenssl-develpatch
  5. [root@192-168-9-168~]#yuminstall-ycurl-develbzip2pcre-develzip2-develbzip2-devel
  6. [root@192-168-9-168~]#yuminstall-ymcrypt-develzlib-develwget
  7.  
  8. 2、#编译安装apr
  9. [root@192-168-9-168~]#cd/usr/local/src/
  10. [root@192-168-9-168src]#wgethttps://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.5.2.tar.bz2
  11. [root@192-168-9-168src]#tarxfapr-1.5.2.tar.bz2
  12. [root@192-168-9-168src]#cdapr-1.5.2
  13. [root@192-168-9-168apr-1.5.2]#./configure--prefix=/usr/local/apr
  14. [root@192-168-9-168apr-1.5.2]#make&&makeinstall
  15.  
  16. 3、编译安装apr-util
  17. [root@192-168-9-168apr-1.5.2]#cd/usr/local/src/
  18. [root@192-168-9-168src]#wgethttps://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.5.4.tar.bz2
  19. [root@192-168-9-168src]#tarxfapr-util-1.5.4.tar.bz2
  20. [root@192-168-9-168src]#cdapr-util-1.5.4
  21. [root@192-168-9-168apr-util-1.5.4]#./configure--prefix=/usr/local/apr-util--with-apr=/usr/local/apr
  22. [root@192-168-9-168apr-util-1.5.4]#make&&makeinstall
  23.  
  24. 4、编译安装httpd
  25. [root@192-168-9-168apr-util-1.5.4]#useradd-s/sbin/nologinwww
  26. [root@192-168-9-168apr-util-1.5.4]#cd/usr/local/src/
  27. [root@192-168-9-168src]#wgethttp://apache.fayea.com//httpd/httpd-2.4.20.tar.bz2
  28. [root@192-168-9-168src]#tarxfhttpd-2.4.20.tar.bz2
  29. [root@192-168-9-168src]#cdhttpd-2.4.20
  30. [root@192-168-9-168httpd-2.4.20]#./configure--prefix=/usr/local/apache\
  31. --with-apr=/usr/local/apr\
  32. --with-apr-util=/usr/local/apr-util/\
  33. --enable-so\
  34. --enable-ssl\
  35. --enable-cgi\
  36. --enable-rewrite\
  37. --with-zlib\
  38. --with-pcre\
  39. --enable-modules=most\
  40. --enable-mpms-shared=all\
  41. --with-mpm=prefork
  42. [root@192-168-9-168httpd-2.4.20]#make
  43. [root@192-168-9-168httpd-2.4.20]#makeinstall
  44. [root@192-168-9-168httpd-2.4.20]#sed-i's/Userdaemon/Userwww/g'/usr/local/apache/conf/httpd.conf
  45. [root@192-168-9-168httpd-2.4.20]#sed-i's/Groupdaemon/Groupwww/g'/usr/local/apache/conf/httpd.conf
  46. [root@192-168-9-168httpd-2.4.20]#sed-i"/ServerName/s/#ServerName.*/ServerNamelocalhost/g"/usr/local/apache/conf/httpd.conf
  47.  
  48.  
  49. 6、启动方法
  50. [root@192-168-9-168httpd-2.4.20]#/usr/local/apache/bin/apachectl-kstart|reload|restart|stop
  51.  
  52. 7、测试验证
  53. [root@192-168-9-168httpd-2.4.20]#curl-Ihttp://192.168.9.168
  54. HTTP/1.1200OK
  55. Date:Fri,11Aug201715:22:43GMT
  56. Server:Apache/2.4.20(Unix)
  57. Last-Modified:Mon,11Jun200718:53:14GMT
  58. ETag:"2d-432a5e4a73a80"
  59. Accept-Ranges:bytes
  60. Content-Length:45
  61. Content-Type:text/html

@H_301_30@

二、编译安装MysqL

  1. 1、#下载安装包
  2. [root@192-168-9-168httpd-2.4.20]#cd/usr/local/src/
  3. [root@192-168-9-168src]#wgethttps://cdn.MysqL.com//Downloads/MysqL-5.6/MysqL-5.6.37-linux-glibc2.12-x86_64.tar.gz
  4.  
  5. 2、#建立运行MysqL用户和组为系统账号
  6. [root@192-168-9-168src]#groupadd-rMysqL
  7. [root@192-168-9-168src]#useradd-r-gMysqL-s/sbin/nologinMysqL
  8.  
  9. 3、#编译安装
  10. [root@192-168-9-168src]#yuminstall-ylibaiolibaio-develnumactlnumactl-develcmakencurses-devellibxml2-devellibtool-ltdl-develgcc-c++autoconfautomakebisonzlib-devel
  11. [root@192-168-9-168src]#tarxfMysqL-5.6.37-linux-glibc2.12-x86_64.tar.gz
  12. [root@192-168-9-168src]#mvMysqL-5.6.37-linux-glibc2.12-x86_64/usr/local/MysqL
  13. #建议MysqL使用独立设备独立目录,本实验只建立目录,独立设备请参考磁盘分区与挂载
  14. [root@192-168-9-168src]#mkdir-p/data0/MysqL
  15. #更改属主属组
  16. [root@192-168-9-168src]#chown-RMysqL.MysqL/usr/local/MysqL
  17. #初始化数据库
  18. [root@192-168-9-168src]#cd/usr/local/MysqL
  19. [root@192-168-9-168MysqL]#./scripts/MysqL_install_db--datadir=/data0/MysqL--user=MysqL
  20. [root@192-168-9-168MysqL]#cp./support-files/my-default.cnf/data0/MysqL/my.cnf
  21. [root@192-168-9-168MysqL]#echo"basedir=/usr/local/MysqL
  22. datadir=/data0/MysqL
  23. port=3306
  24. server_id=1000
  25. socket=/tmp/MysqL.sock">>/data0/MysqL/my.cnf
  26. [root@192-168-9-168MysqL]#chown-RMysqL.MysqL/data0/MysqL/
  27. 4,启动:
  28. [root@192-168-9-168MysqL]#/usr/local/MysqL/bin/MysqLd_safe--defaults-file=/data0/MysqL/my.cnf&
  29. [root@192-168-9-168MysqL]#echo"/usr/local/MysqL/bin/MysqLd_safe--defaults-file=/data0/MysqL/my.cnf&">>/etc/rc.d/rc.local
  30.  
  31. 6、#安全初始化
  32. #安全验证初始化,设置root用户密码,删除匿名用户禁止root用户远程连接,删除test库
  33. [root@192-168-9-168MysqL]#./bin/MysqL_secure_installation
  34. #导出头文件
  35. [root@192-168-9-168MysqL]#ln-sv/usr/local/MysqL/include//usr/include/MysqL
  36. #加载库文件
  37. [root@192-168-9-168MysqL]#echo"/usr/local/MysqL/lib/MysqL/">>/etc/ld.so.conf
  38. [root@192-168-9-168MysqL]#ldconfig
  39. [root@192-168-9-168MysqL]#echo"PATH=$PATH:/usr/local/MysqL/bin/">>/etc/profile


三、编译安装PHP

  1. 1、#编译安装libmcrypt扩展
  2. [root@192-168-9-168src]#cd/usr/local/src/
  3. [root@192-168-9-168src]#wgetftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
  4. [root@192-168-9-168src]#tarxflibmcrypt-2.5.7.tar.gz
  5. [root@192-168-9-168src]#cdlibmcrypt-2.5.7
  6. [root@192-168-9-168libmcrypt-2.5.7]#./configure
  7. [root@192-168-9-168libmcrypt-2.5.7]#make&&makeinstall
  8.  
  9. 2、#编译安装freetds扩展
  10. [root@clocal]#cd/usr/local/src/
  11. [root@csrc]#wgetftp://ftp.freetds.org/pub/freetds/stable/freetds-patched.tar.gz
  12. [root@192-168-9-168src]#tarxffreetds-patched.tar.gz
  13. [root@192-168-9-168src]#cdfreetds-1.00.53/
  14. [root@192-168-9-168freetds-1.00.53]#./configure--prefix=/usr/local/freetds--with-tdsver=7.4--enable-msdblib
  15. [root@192-168-9-168freetds-1.00.53]#make&&makeinstall
  16. [root@192-168-9-168freetds-1.00.53]#exportLD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/freetds/lib/
  17.  
  18. 4、#下载安装包
  19. [root@192-168-9-168src]#cd/usr/local/src/
  20. [root@192-168-9-168src]#wgethttp://cn2.PHP.net/distributions/PHP-5.6.22.tar.bz2
  21. [root@192-168-9-168src]#tarxfPHP-5.6.22.tar.bz2
  22. [root@192-168-9-168src]#cdPHP-5.6.22
  23. [root@192-168-9-168PHP-5.6.22]#./configure--prefix=/usr/local/PHP\
  24. --with-MysqL=/usr/local/MysqL/\
  25. --with-openssl\
  26. --with-MysqLi=/usr/local/MysqL/bin/MysqL_config\
  27. --enable-mbstring\
  28. --with-freetype-dir\
  29. --with-jpeg-dir\
  30. --with-png-dir\
  31. --with-zlib\
  32. --with-libxml-dir=/usr/\
  33. --enable-xml\
  34. --enable-sockets\
  35. --with-apxs2=/usr/local/apache/bin/apxs\
  36. --with-mcrypt\
  37. --with-mssql=/usr/local/freetds\
  38. --with-bz2\
  39. --enable-maintainer-zts\
  40. --with-curl\
  41. --enable-ftp\
  42. --enable-bcmath\
  43. --with-gd\
  44. --with-freetype-dir\
  45. --enable-gd-native-ttf\
  46. --with-iconv-dir\
  47. --enable-mbstring\
  48. --enable-calendar\
  49. --with-gettext\
  50. --enable-dom\
  51. --enable-fpm
  52. #说明:如果PHP5.3以上的版本,为了链接数据库,可以指定MysqLnd,这样本机就可以不用安装MysqLMysqL开发包。5.4已经是默认设置。
  53. 如:--with-MysqL=MysqLnd--with-pdo-MysqL=MysqLnd--with-MysqLi=MysqLnd
  54. [root@192-168-9-168PHP-5.6.22]#make
  55. [root@192-168-9-168PHP-5.6.22]#makeinstall
  56.  
  57. #为PHP提供配置文件
  58. [root@192-168-9-168PHP-5.6.22]#cpPHP.ini-development/usr/local/PHP/etc/PHP.ini
  59.  
  60. 5、编辑apache配置文件httpd.confapache支持PHP
  61. [root@192-168-9-168PHP-5.6.22]#sed-i'/LoadModulePHP5_module/aAddTypeapplication/x-httpd-PHP-source.PHPs'/usr/local/apache/conf/httpd.conf
  62. [root@192-168-9-168PHP-5.6.22]#sed-i'/LoadModulePHP5_module/aAddTypeapplication/x-httpd-PHP.PHP.PHP5'/usr/local/apache/conf/httpd.conf
  63. [root@192-168-9-168PHP-5.6.22]#sed-i'/DirectoryIndex/s/index.html/index.PHPindex.html/'/usr/local/apache/conf/httpd.conf
  64.  
  65. #重启httpd
  66. [root@192-168-9-168PHP-5.6.22]#/usr/local/apache/bin/apachectl-krestart
  67. 4、测试验证PHP
  68. "<?PHP
  69. PHPinfo();
  70. ?>">/usr/local/apache/htdocs/index.PHP
  71. 5、浏览器访问:
  72. http://192.168.9.168
  73. 5、测试验证PHP连接数据库
  74. [root@192-168-9-168PHP-5.6.22]#vimindex.PHP
  75.  
  76. <?PHP
  77. $link=MysqL_connect('127.0.0.1','root','123456');
  78. if($link)
  79. echo"Success...";
  80. else
  81. echo"Failure...";
  82. MysqL_close()
  83. ?>
  84. #浏览器访问
  85. http://192.168.9.168
  86.  
  87. 6、#ab压力测试
  88. [root@192-168-9-168PHP-5.6.22]#ab-c100-n10000
  89.  
  90. 四、测试XcachePHP加速
  91. 1、#编译安装
  92. [root@192-168-9-168htdocs]#cd/usr/local/src/
  93. [root@192-168-9-168src]#tarxfxcache-3.2.0.tar.bz2
  94. [root@192-168-9-168src]#cdxcache-3.2.0
  95. [root@192-168-9-168xcache-3.2.0]#/usr/local/PHP/bin/PHPize
  96. [root@192-168-9-168xcache-3.2.0]#./configure--enable-xcache--with-PHP-config=/usr/local/PHP/bin/PHP-config
  97. [root@192-168-9-168xcache-3.2.0]#make&&makeinstall
  98. 2、#编辑PHP.ini,整合PHPxcache
  99. [root@192-168-9-168xcache-3.2.0]#mkdir-p/etc/PHP.d
  100. [root@192-168-9-168xcache-3.2.0]#cpxcache.ini/etc/PHP.d
  101.  
  102.  
  103. #重启apache
  104. [root@192-168-9-168xcache-3.2.0]#apachectl-krestart
  105. #压力测试,看效果

猜你在找的CentOS相关文章