centos7下apache安装以及自动启动

  1. 近期玩 Apache mysql redis 等,so把遇到的坑给总结了下,一步步的安装如果还遇到问题,文章下面留言就好,一起交流。。。不多说了了,开始浪。。。。。。
  2. 安装好centos 7系统后需要配置下ip等信息,
  3. vi /etc/sysconfig/network-scripts/ifcfg-eth0
  4. BOOTPROTO=static
  5. 网卡获得ip地址的方式,Static(静态 ip地址)dhcp(通过dhcp协议获取ip)
  6. HWADDR=00:50:56:8E:47:EE  网卡物理地址
  7. IPADDR=10.0.0.193 网卡IP地址
  8. IPV6INIT=no 是否启用IPV6
  9. IPV6_AUTOCONF=no
  10. NETMASK=255.255.255.0 网卡对应网络掩码
  11. NETWORK=192.168.1.0 网卡对应的网络地址
  12. ONBOOT=yes  系统启动时是否设置此网络接口,设置为yes时,系统启动时激活此设备。默认设置为yes
  13. service network restart  重启服务或者 /etc/init.d/network  restart
  14. 你需要改的就是 IPADDR DNS1  GATEWAY  DEVICE ,安装自己的机子修改就好
  15. 修改完后,service network restart 然后ping 下百度,看能ping通不,如果能ping通就代表你能上网了,
  16. 下一步关闭防火墙,centos7的墙 是firewall
  17.     systemctl stop firewalld.service #停止firewall
  18.     systemctl disable firewalld.service #禁止firewall开机启动
  19.     firewall-cmd –state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
  20. 下一步上传apache 依赖包 首先 cd 到根目录 然后新建tools文件夹 ,mkdir tools ,将依赖包以及apache文件上传到tools 下面apr-1.6.3.tar.gz 、apr-util-1.6.1.tar.gz、pcre-8.41.zip、openssl-1.0.2n.tar.gz、httpd-2.4.29.tar.gz。
  21. 开始解压:
  22. tar -xzvf apr-1.6.3.tar.gz
  23. tar -xzvf apr-util-1.6.1.tar.gz
  24. 需要先安装uzip yum install -y unzip zip
  25. unzip pcre-8.41.zip
  26. 安装apr-1.6.3
  27. 进入安装目录
  28. cd /tools/apr-1.6.3/
  29. 安装及编译
  30. 先安装 gcc   yum -y install gcc
  31. ./configure –prefix=/usr/local/apr
  32. 会出现rm: cannot remove ‘libtoolT’: No such file or director
  33. cd apr-1.6.3
  34. 修改
  35. vi configure
  36. 9365 #RM=$ac_cv_prog_RM
  37. 9355 #ac_cv_prog_RM=“rm”
  38. make && make install  就不会报错了。
  39. 进入安装目录
  40. cd /tools/apr-util-1.6.1/
  41. yum install -y libxml2-devel
  42. ./configure –prefix=/usr/local/apr-util/ –with-apr=/usr/local/apr/bin/apr-1-config
  43. 在CentOS7最小安装版下,编译安装apr-util时报错:
  44. fatal error: expat.h: No such file or director
  45. 解决办法:yum install expat-devel
  46. make && make install
  47. 进入安装目录
  48. cd /tools/pcre-8.41/
  49. 安装及编译
  50. yum -y install gcc+ gcc-c++
  51. ./configure –prefix=/usr/local/pcre
  52. make && make install
  53. 进入安装目录
  54. tar -xvf openssl-1.0.2n.tar.gz
  55. cd openssl-1.0.2n
  56. 需要先安装yum install perl*
  57. ./config -fPIC –prefix=/usr/local/openssl –openssldir=/usr/local/openssl
  58. make && make install
  59. 在线安装gcc
  60. #yum install gcc*
  61. cd /tools  将安装包httpd-2.4.29.tar.gz拷至/tools目录下
  62. #tar zxvf  httpd-2.4.29.tar.gz
  63. #cd /tools/httpd-2.4.29
  64. yum install zlib-devel
  65. ./configure –prefix=/opt/apache/apache-2.4.29 –enable-deflate –enable-expires –enable-headers –enable-ssl –enable-cgi –with-zlib –with-mpm=worker –enable-so –enable-rewrite –enable-module=shared –enable-mods-shared=most ap_cv_void_ptr_lt_long=no  –with-apr=/usr/local/apr –with-apr-util=/usr/local/apr-util –with-pcre=/usr/local/pcre –with-ssl=/usr/local/openssl –enable-unique –enable-unique_id
  66. make && make install but后报错
  67. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_GetErrorCode’
  68. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetEntityDeclHandler’
  69. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserCreate’
  70. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetCharacterDataHandler’
  71. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserFree’
  72. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetUserData’
  73. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_StopParser’
  74. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_Parse’
  75. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ErrorString’
  76. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetElementHandler’
  77. collect2: error: ld returned 1 exit status
  78. make[2]: *** [htpasswd] Error 1
  79. make[2]: Leaving directory `/usr/local/httpd-2.4.26/support’
  80. make[1]: *** [all-recursive] Error 1
  81. make[1]: Leaving directory `/usr/local/httpd-2.4.26/support’
  82. make: *** [all-recursive] Error 1
  83. ①安装libxml2-devel
  84. 1   [root@test_01 ~]# yum install -y libxml2-devel
  85. ②删除apr-util目录并且重新编译安装
  86. 1
  87. 2
  88. 3
  89. 4
  90. 5
  91. [root@test_01 ~]#rm -rf /usr/local/apr-util
  92. [root@test_01 ~]# cd /tools/apr-util-1.6.1/
  93. [root@test_01 apr-util-1.6.1]# make clean
  94. [root@test_01 apr-util-1.6.1]#./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr
  95. [root@test_01 apr-util-1.6.1]#make && make install
  96. 重新编译下apache 然后安装就ok 了
  97. 进入安装后目录:
  98. # cd /opt/apache/apache-2.4.29/bin
  99. 检查进程模式:
  100. # ./apachectl -l
  101. Compiled in modules:
  102. core.c
  103. worker.c
  104. http_core.c
  105. mod_so.c
  106. 启动Apache Web Server:
  107. #./apachectl start
  108. ServerName localhost:80
  109. 然后浏览器打开地址就会出现 it works 了
  110. 下面开启做apache 开机启动
  111. 停止Apache Web Server:
  112. #./apachectl stop
  113. 1.将apachectl文件copy到/etc/init.d中,然后再/etc/rc.d/rc5.d中加入链接。
  114. 命令如下:
  115. cp /opt/apache/apache-2.4.29/bin/apachectl /etc/init.d/httpd
  116. ln -s /etc/init.d/httpd /etc/rc.d/rc5.d/S85httpd
  117. 2.运行chkconfig –list 发现列表中没有httpd,通过chkconfig –add httpd来添加,可能会提示httpd服务不支持chkconfig,需要编辑/etc/rc.d/init.d/httpd
  118. 添加以下注释信息:
  119. # chkconfig: 345 85 15
  120. # description: Activates/Deactivates Apache Web Server
  121. 345代表哪些linux级别需要启动httpd, 启动序号是85, 关闭序号是15
  122. 3.运行chkconfig –list,httpd 就存在了,可以使用service httpd start 和 service httpd stop来启动和停止服务
  123. 开机启动
  124. chkconfig –level 2345 httpd on
  125. 教程写完了,有遇到apache的问题可以,留言相互交流。。。
© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享
评论 抢沙发

    暂无评论内容