1、安装Apache前准备:
1、检查该环境中是否已经存在httpd服务的配置文件,默认存储路径:/etc/httpd/httpd.conf(这是centos预装的Apache的一个ent版本,一般我们安装源代码版的Apache)。如果已经存在/etc/httpd/httpd.conf,请先卸载或者关闭centos系统自带的web服务,执行命令:chkconfig httpd off,再或者把centos自带的httpd服务的80端口改为其他端口,只要不与我们安装的Apache服务的端口冲突就可以啦。
停止并卸载Linux系统自带的httpd服务:
1、service httpd stop
2、ps -ef | grep httpd
3、kill -9 pid号(逐个删除)
4、rpm -qa |grep httpd
5、rpm -e httpd软件包
2、下载Apache安装包
下载地址:http://httpd.apache.org/
3、解压到/usr/local下
#tar xzvf httpd-2.2.16.tar.gz
4、配置安装参数
#cd /usr/local/httpd-2.2.16
在安装Apache时,我分别针对不同版本进行了安装,在编译时是不同的,configure后跟的参数不同。
httpd-2.2.23版本编译命令:
./configure --prefix=/usr/local/apache2 (安装目录参数后面可以不加任何参数,直接安装即可)
make
make install
httpd-2.4.3版本编译命令:
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre (除了指定Apache的安装目录外,还要安装apr、apr-util、pcre,并指定参数)
make
make install
编译时或换成如下参数:(仅供参考)
#./configure --prefix=/usr/local/apache2 --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
5、安装报错情况处理
在编译Apache(在安装httpd-2.4.3时遇到的问题)时分别出现了apr not found、APR-util not found、pcre-config for libpcre not found的问题,下面就httpd-2.4.3的这些问题解决来实际操作一把。
http://apr.apache.org/download.cgi 下载apr-1.4.5.tar.gz、apr-util-1.3.12.tar.gz
http://sourceforge.net/projects/pcre/files/latest/download 下载pcre-8.31.zip
1.解决apr not found问题
[iyunv@localhost bin]# tar -zxf apr-1.4.5.tar.gz
[iyunv@localhost apr-1.4.5]# ./configure --prefix=/usr/local/apr
[iyunv@localhost apr-1.4.5]# make
[iyunv@localhost apr-1.4.5]# make install
2.解决APR-util not found问题
[iyunv@localhost bin]# tar -zxf apr-util-1.3.12.tar.gz
[iyunv@localhost apr-util-1.3.12]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config
[iyunv@localhost apr-util-1.3.12]# make
[iyunv@localhost apr-util-1.3.12]# make install
3、解决pcre-config for libpcre not found问题
[iyunv@localhost ~]# unzip pcre-8.31.zip
[iyunv@localhost ~]# cd pcre-8.31
[iyunv@localhost pcre-8.31]# ./configure --prefix=/usr/local/pcre
[iyunv@localhost pcre-8.31]# make[iyunv@localhost pcre-8.31]# make install
6、apache的启动、停止
启动Apache:
#cd /usr/local/apache2/bin
#./apachectl start
停止Apache:
#cd /usr/local/apache2/bin
#./apachectl stop
重启Apache:
#cd /usr/local/apache2/bin
#./apachectl restart
7、安装成功后,配置参数修改:
#vi /usr/local/apache/conf/httpd.conf
Listen 80 //apache默认端口,可以修改
DocumentRoot "/home/mahaibo/apache/htdocs" //用户默认访问的apache目录
//日志输出的2种格式
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog logs/access_log common //访问日志:access_log的输出采用common格式
8、网站的测试:
网站放在/usr/local/apache2/htdocs目录下
在IE中通过http://localhost:80
如果看到页面中显示“It works!”字样,则代表Apache验证通过。
如果网站的index后缀是PHP格式的,则要修改httpd.conf配置文件(/usr/local/apache2/conf),在DirectoryIndex增加 index.php。
# # DirectoryIndex: sets the file that Apache will serve if a directory# is requested.#<IfModule dir_module> DirectoryIndex index.html index.php </IfModule>
9、网站的安全加固:
修改文件的所有者和所有组
cd /usr/local/apache
chown -R nobody:root htdocs
修改apache下所有文件权限
chmod -R 755 *
10、apache的默认重要配置信息如下:
配置文件:/usr/local/apache2/httpd/httpd.conf
服务器的根目录:/usr/local/apache2/htdocs
访问日志文件:/var/log/httpd/access_log
错误日志文件:/var/log/httpd/error_log
运行apache的用户:apache
运行apache的组:apache
端口:80
模块存放路径:/usr/lib/httpd/modules
11、安装apache补充说明
安装apache2 , ./configure ;make;make install。安装完毕后却不能找到mod_proxy和mod_rewrite模块,主要原因是APACHE2.2默认的安装选项是最小化的安装,一些扩展模块在默认的状态下都没有被安装,如果需要要在./configure后用参数指定,比方要用到mod_proxy 和 mod_rewrite两个模块进行实验,所以命令行是:./configure --enable-mods-shared='proxy proxy_ajp proxy_balancer proxy_connect proxy_ftp proxy_http proxy_rewrite'。这个配置不仅指定了这些模块,同时也默认安装其他最小项。这样配置完后make和make install后,mod_proxy和mod_rewrite两个模块都能找到了
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com