apache2.2.4的安装及扩展配置

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:
apache2.2.4的安装及扩展配置
 
当前系统
redhat9
apache2.0.54  /usr/local/apache2
mysql5.0.16  /usr/local/mysql
php 5.0.4    /usr/local/php5
 
现在需要安装apache2.2.4
过程如下
编译:安装目录为--prefix=/usr/local/apache22
./configure --prefix=/usr/local/apache22 --with-layout=apache --enable-module=so --enable-module=setenvif --enable-module=rewrite --with-mpm=prefork --enable-ssl
安装
make
make install
 
在安装了apache2.2.4之后,直接启动,会报有关ServerName的警告,但是还是可以启动的.通过客户端访问看到的默认页面是一句话 it works
在配置文件中修改如下:
#ServerName [url]www.example.com:80[/url]
ServerName 127.0.0.1
就不会报错了
 
修改网站主目录如下
#DocumentRoot "/usr/local/apache22/htdocs"
DocumentRoot "/var/www/html"
访问的时候会报错
403 禁止访问
您无权查看该网页
您可能没有权限用您提供的凭据查看此目录或网页
例如在网站的主目录/var/ww/html下有1.html.在客户端访问[url]http://IP/1.html[/url]就会报这个错.
解决办法:
<Directory />
    Options FollowSymLinks
    AllowOverride None
#    Order deny,allow
#    Deny from all
   Order allow,deny
   Allow from all
</Directory>
 
分析错误原因
查看配置文件httpd.conf,相关部分内容如下:
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# features.
首先配置的缺省的限制,这个限制是非常严格的
<Directory />
    Options FollowSymLinks
    AllowOverride None
   Order deny,allow  次序是先拒绝,再允许
    Deny from all  默认是拒绝所有
</Directory>
 
#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#从这里开始你必须指定允许启用特定的功能,如果某些不能正常工作,需要查看你是否已经启用了它.
 
#
# This should be changed to whatever you set DocumentRoot to.
#这里应该改为你设的DocumentRoot
<Directory "/usr/local/apache22/htdocs">  可以看到这里是对缺省的主目录的设置
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # [url]http://httpd.apache.org/docs/2.2/mod/core.html#options[/url]
    # for more information.
    #
    Options Indexes FollowSymLinks
 
    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None
 
    #
    # Controls who can get stuff from this server.
    #控制谁能访问这个网站
    Order allow,deny  顺序是先允许再拒绝
    Allow from all  默认是允许所有
 
</Directory>
 
所以缺省状态下只是对默认的主目录/usr/local/apache22/htdocs设的是允许所有访问,而对于其他的目录,采用默认的设置是拒绝所有访问的.
所以我们之前做的修改
<Directory />
    Options FollowSymLinks
    AllowOverride None
#    Order deny,allow
#    Deny from all
   Order allow,deny
   Allow from all
</Directory>
是将默认的限制调大了,让默认对所有的目录都允许所有人访问.或许会带来安全威胁.
安全的做法是按照文档说的
# This should be changed to whatever you set DocumentRoot to.
#这里应该改为你设的DocumentRoot
<Directory "/usr/local/apache22/htdocs"> 把它改为你设的主目录
启动以后就可以正常访问了.
 
做多端口的虚拟主机
2.2.4里面一个很大的不同就是将很多的配置以单独的文件存放(路径是conf/extra),ssl,虚拟主机vhost.在使用的时候先要在主配置文件里面包含此配置文件,然后到相应的配置文件里面去具体配置.下面来配置虚拟主机
修改httpdconf,增加监听端口
Listen 80
Listen 81
 
启用虚拟主机配置
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
Include conf/extra/httpd-vhosts.conf
 
编辑配置文件目录下的/extra/httpd-vhosts.conf
[root@server1 extra]# vi httpd-vhosts.conf
 
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:[url]http://httpd.apache.org/docs/2.2/vhosts/>[/url]
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
 
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
 
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
    ServerAdmin [email]webmaster@dummy-host.example.com[/email]
    DocumentRoot /www/docs/dummy-host.example.com
    ServerName dummy-host.example.com
    ServerAlias [url]www.dummy-host.example.com[/url]
    ErrorLog logs/dummy-host.example.com-error_log
    CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
 
<VirtualHost *:80>
    ServerAdmin [email]webmaster@dummy-host2.example.com[/email]
    DocumentRoot /www/docs/dummy-host2.example.com
    ServerName dummy-host2.example.com
    ErrorLog logs/dummy-host2.example.com-error_log
    CustomLog logs/dummy-host2.example.com-access_log common
</VirtualHost>
 
做如下修改
[root@server1 extra]# vi httpd-vhosts.conf
 
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:[url]http://httpd.apache.org/docs/2.2/vhosts/>[/url]
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
 
#
# Use name-based virtual hosting.
#
#NameVirtualHost *:80  注释掉此句的原因见我有关虚拟主机的文章
 
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
    ServerAdmin [email]webmaster@dummy-host.example.com[/email]
    DocumentRoot /var/www/html/s1
    ServerName dummy-host.example.com
    ServerAlias [url]www.dummy-host.example.com[/url]
    ErrorLog logs/dummy-host.example.com-error_log
    CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
 
<VirtualHost *:81>
    ServerAdmin [email]webmaster@dummy-host2.example.com[/email]
    DocumentRoot /var/www/html/s2
    ServerName dummy-host2.example.com
    ErrorLog logs/dummy-host2.example.com-error_log
    CustomLog logs/dummy-host2.example.com-access_log common
</VirtualHost>
 
配置ssl
# Secure (SSL/TLS) connections
#Include conf/extra/httpd-ssl.conf
Include conf/extra/httpd-ssl.conf
 
将之前生成的server的那些证书文件copyconf目录下(因为是按照httpd-ssl.conf文件中的证书路径和名称配置的)
 
 [root@server1 conf]# ../bin/httpd -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   dummy-host.example.com (/usr/local/apache22/conf/extra/httpd-vhosts.conf:27)
*:81                   dummy-host2.example.com (/usr/local/apache22/conf/extra/httpd-vhosts.conf:36)
_default_:443          [url]www.example.com[/url] (/usr/local/apache22/conf/extra/httpd-ssl.conf:74)
Syntax OK
 
重启服务以后通过https访问
 
安装php
原来想用现成的php,不想重新编译安装php.毕竟我感觉需要的也只是那个so文件而已.
首先我想用原来的apache那个php的模块文件,将他copy到现在的模块目录
cp /usr/local/apache2/modules/libphp5.so /usr/local/apache2/modules/libphp5.so
然后修改httpd.conf来支持php
# Example:
# LoadModule foo_module modules/mod_foo.so
#
LoadModule php5_module        modules/libphp5.so
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
 
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>
 
启动报错
[root@server1 conf]# ../bin/httpd -k start
httpd: Syntax error on line 54 of /usr/local/apache22/conf/httpd.conf: API module structure `php5_module' in file /usr/local/apache22/modules/libphp5.so is garbled - perhaps this is not an Apache module DSO?
,失败了.(个人觉得如果是相同版本的apache应该是可以的copy使用的,但未测试)
 
经过sery指点想用apxs独立生成PHPdso模块.可就是不知道该编译PHP里面哪个文件是模块的源文件.只得放弃.没办法了重新编译安装一个PHP.(如果有谁知道如何用apxs来生成phpdso模块而不用编译安装php就告诉我一声哈.)
其实安装的过程与apache2.0.x一样.我写在这里留给自己以后参考
编译php:新装在另一个目录php5.04(这是为了不影响现有php的运行,节省空间的话就直接安装在原目录下),指向的apache也是新的apache的路径.
./configure --prefix=/usr/local/php5.04 --with-apxs2=/usr/local/apache22/bin/apxs --enable-track-vars  --enable-url-includes --enable-sockets --enable-force-cgi-redirect --enable-calendar --with-config-file-path=/usr/local/lib --with-jpeg-dir=/usr/local/jpeg6 --enable-gd-native-ttf --with-ttf --with-gdbm --with-gettext --with-iconv --with-png-dir=/usr/local/libpng2 --with-freetype-dir=/usr/local/freetype2 --with-libxml --with-zlib --with-zlib-dir=/usr/local/zlib2 --with-gd --enable-soap --with-curl --with-curlwrappers --with-java=/usr/java/j2sdk1.4.2_14 --with-mysql=/usr/local/mysql/
注意--with-mysql=/usr/local/mysql/,我之前使用的是—with-mysql这一步过不去,我停掉mysql还是不行,关掉apache也不行,所以就用这个来明确指向mysql的安装目录就搞定了
 
安装PHP
make
make install
报错如下
Installing PHP SAPI module:       apache2handler
make: execvp: /home/yahoon/php-5.0.4/build/shtool: Permission denied
make: [install-sapi] Error 127 (ignored)
/bin/sh: line 1: /home/yahoon/php-5.0.4/build/shtool: Permission denied
make: *** [install-sapi] Error 126
知道是权限问题,把这个文件提权
[root@server1 php-5.0.4]# chmod 777 build/shtool
[root@server1 php-5.0.4]# make install
最后的信息为
Installing PHP SAPI module:       apache2handler
/usr/local/apache22/build/instdso.sh SH_LIBTOOL='/usr/local/apache22/build/libtool' libphp5.la /usr/local/apache22/modules
/usr/local/apache22/build/libtool --mode=install cp libphp5.la /usr/local/apache22/modules/
cp .libs/libphp5.so /usr/local/apache22/modules/libphp5.so
cp .libs/libphp5.lai /usr/local/apache22/modules/libphp5.la
libtool: install: warning: remember to run `libtool --finish /home/yahoon/php-5.0.4/libs'
chmod 755 /usr/local/apache22/modules/libphp5.so
[activating module `php5' in /usr/local/apache22/conf/httpd.conf]
Installing PHP CLI binary:        /usr/local/php5.04/bin/
Installing PHP CLI man page:      /usr/local/php5.04/man/man1/
Installing PEAR environment:      /usr/local/php5.04/lib/php/
[PEAR] Archive_Tar    - installed: 1.1
[PEAR] Console_Getopt - installed: 1.2
[PEAR] PEAR           - installed: 1.3.5
Wrote PEAR system config file at: /usr/local/php5.04/etc/pear.conf
You may want to add: /usr/local/php5.04/lib/php to your php.ini include_path
[PEAR] HTML_Template_IT- installed: 1.1
[PEAR] Net_UserAgent_Detect- installed: 2.0.1
[PEAR] XML_RPC        - installed: 1.2.2
Installing build environment:     /usr/local/php5.04/lib/php/build/
Installing header files:          /usr/local/php5.04/include/php/
Installing helper programs:       /usr/local/php5.04/bin/
  program: phpize
  program: php-config
  program: phpextdist
红色的字说明了像apache的目录写入模块的过程. [activating module `php5' in /usr/local/apache22/conf/httpd.conf]这句话引起了我的注意.看来并不用手动添加对php的支持它会自动修改配置文件来激活模块.
/usr/local/apache22/conf/下看到出现了一个httpd.conf.bak,即它将原来的文件备份了.
这样重启apache就能访问php的页面了.
 
其实这时新安装的php路径/usr/local/php5.04即使删掉这个目录也是可以正常工作的.因为我们需要的so文件已经在apachemodules目录下了


本文转自yahoon 51CTO博客,原文链接:http://blog.51cto.com/yahoon/37092,如需转载请自行联系原作者
 
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
9天前
|
网络安全 Apache
Apache服务器安装SSL证书
Apache服务器安装SSL证书
14 0
|
1月前
|
SQL Apache HIVE
一文彻底掌握Apache Hudi的主键和分区配置
一文彻底掌握Apache Hudi的主键和分区配置
57 0
|
4月前
|
SQL 分布式计算 数据可视化
Apache Zeppelin系列教程第一篇——安装和使用
Apache Zeppelin系列教程第一篇——安装和使用
73 0
|
2月前
|
Java 程序员 API
Springboot-swagger配置(idea社区版2023.1.4+apache-maven-3.9.3-bin)
Springboot-swagger配置(idea社区版2023.1.4+apache-maven-3.9.3-bin)
58 1
|
2月前
|
前端开发 Java 数据库连接
Springboot-MyBatis配置-配置端口号与服务路径(idea社区版2023.1.4+apache-maven-3.9.3-bin)
Springboot-MyBatis配置-配置端口号与服务路径(idea社区版2023.1.4+apache-maven-3.9.3-bin)
33 0
|
1月前
|
安全 Linux Apache
Apache代理服务器搭建和配置
Apache代理服务器搭建和配置
|
1月前
|
XML Java Apache
Apache Flink自定义 logback xml配置
Apache Flink自定义 logback xml配置
144 0
|
1月前
|
监控 API Apache
实战!配置DataDog监控Apache Hudi应用指标
实战!配置DataDog监控Apache Hudi应用指标
21 0
|
3月前
|
Java 应用服务中间件 Apache
Windows安装Apache服务器
可能你听说过Apache Tomcat, Apache与Tomcat都是Apache开源组织开发的用于处理HTTP服务的项目,两者都是免费的,都可以作为独立的Web服务器运行。Apache是Web服务器。Tomcat是Java应用服务器,是 Apache 的扩展。本文档将详细描述如何在云服务器上安装Apache环境。
49 0
|
3月前
|
消息中间件 Java Kafka
Apache Kafka-初体验Kafka(02)-Centos7下搭建单节点kafka_配置参数详解_基本命令实操
Apache Kafka-初体验Kafka(02)-Centos7下搭建单节点kafka_配置参数详解_基本命令实操
58 0

热门文章

最新文章

推荐镜像

更多