最近百度了下网上编译搭建lamp平台的文章,感受大都写的乱糟糟的,不少编译过程当中会遇到的问题文章里也都没有提出来,搞的断断续续的非常不爽,这里本人将作下统筹,把常见的问题也列举出来供你们参考php
检查是否安装过apache mysql php,如有就删掉吧,检查方法自行百度html
centos7停用firewall防火墙,启用iptables(centos6的话直接去开放端口就好)mysql
systemctl stop firewalld.service #中止firewall服务 systemctl disable firewalld.service #禁止firewall开机启动 yum -y install iptables-services #安装iptables服务 vi /etc/sysconfig/iptables #编辑iptables配置 .....在22端口行下添加80和3306端口 -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT #apache端口 -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT #mysql端口 :wq! #保存退出 systemctl restart iptables.service #重启iptables服务 systemctl enable iptables.service #开机启动iptables
若是你不想用iptables,继续要用firewall,firewall添加端口的方法以下linux
firewall-cmd --zone=public --add-port=80/tcp --permanent firewall-cmd --zone=public --add-port=3306/tcp --permanent firewall-cmd --reload
停用selinux,不然编译安装可能会出错sql
vi /etc/selinux/config #编辑selinux配置 ..... #SELINUX=enforcing #注释掉 #SELINUXTYPE=targeted #注释掉 SELINUX=disabled #增长 :wq! #保存退出 setenforce 0 #使配置当即生效
更新下yum的仓库apache
epel 为 yum 的扩展源centos
yum install epel-release #扩展包更新包 yum update #更新yum源
安装开发包工具浏览器
yum groupinstall "Development Tools"
apache的下载:http://httpd.apache.org/download.cgi,这里咱们下载稳定版httpd-2.4.12.tar.gztcp
apache的新版须要apr apr-util的支持,确定少人在编译时都遇到 apr not found的错误,解决方法有两个ide
一、编译安装apr和apr-util,但同时要编译安装pcre
二、将apr和apr-util的源文件放入apache的srclib文件夹下,编译时加上使用内置的apr版本便可,方便的很
第一种:
yum remove "apr*" tar -zxvf apr-1.5.2.tar.gz tar -zxvf apr-util-1.5.4.tar.gz cd apr-1.5.2 ./configure --prefix=/usr/local/apr make && make install cd apr-util-1.5.4 ./configure --prefix=/usr/local/apr-util –-with-apr=/usr/local/apr make && make install #本身下pcre,我推荐使用第二种方法,简单 unzip -o pcre-8.10.zip cd pcre-8.10 ./configure --prefix=/usr/local/pcre make && make install cd httpd-2.4.12 ./configure --prefix=/usr/local/apache --enable-so --enable-deflate=shared --enable-expires=shared --enable-headers=shared --enable-rewrite=shared --enable-static-support --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre make && make install
第二种很简单:(推荐)
下载apr和apr-util将文件放在apache源文件的srclib目录下
srclib
|--apr
|--apr-util
tar -zxvf httpd-2.4.12.tar.gz #解压到当前目录 mkdir ./httpd-2.4.12/srclib/apr ./httpd-2.4.12/srclib/apr-util #建立apr和apr-util的内置文件夹 #解压apr apr-util tar -zxvf apr-1.5.2.tar.gz tar -zxvf apr-util-1.5.4.tar.gz #将apr apr-util分别拷贝至 apache源文件加下的srclib/apr 和 srclib/apr-util下 cp -r apr-1.5.2/* ./httpd-2.4.12/srclib/apr cp -r apr-util-1.5.4/* ./httpd-2.4.12/srclib/apr-util #编译安装apache cd httpd-2.4.12 ./configure --prefix=/usr/local/apache --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-headers=shared --enable-rewrite=shared --enable-static-support make && make install
--prefix=/usr/local/apache:指定安装目录
--with-included-apr:在编译时强制使用当前源代码中绑定的APR版本,也就是咱们放入srclib文件夹下的apr和apr-util
--enable-so:容许运行时加载DSO模块
--enable-deflate=shared:将deflate模块编译为DSO
--enable-expires=shared:将expires模块编译为DSO
--enable-headers=shared:将headers模块编译为DSO
--enable-rewrite=shared:将rewrite模块编译为DSO
--enable-static-support:使用静态链接(默认为动态链接)编译全部二进制支持程序
#将apache加入系统服务,并设置开机启动 cp /usr/local/apache/bin/apachectl /etc/init.d/httpd vi /etc/init.d/httpd #在#!/bin/sh下加入 #chkconfig: 2345 10 90 #description:Activates/Deactivates Apache Web Server :wq! chkconfig --add httpd 将apache加入系统控制 chkconfig httpd on 将apache设为开机启动 systemctl enable httpd.service也能够 #添加apache用户 useradd apache #建立apache文档根目录(我比较强迫保持与yum安装的一致) mkdir -p /var/www/html chown -R apache:apache /var/www/html vi /usr/local/apache/conf/http.conf DocumentRoot '/var/www/html' AllowOverride All Require all granted :wq! #重启apache systemctl restart httpd.service
如今去浏览器中输入localhost就能够正常访问了
apache安装到此就OK了
下一篇:http://my.oschina.net/sallency/blog/473626