apache2.2.4的安装及扩展配置-阿里云开发者社区

开发者社区> 科技小先锋> 正文

apache2.2.4的安装及扩展配置

简介:
+关注继续查看
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,如需转载请自行联系原作者
 

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
阿里云服务器端口号设置
阿里云服务器初级使用者可能面临的问题之一. 使用tomcat或者其他服务器软件设置端口号后,比如 一些不是默认的, mysql的 3306, mssql的1433,有时候打不开网页, 原因是没有在ecs安全组去设置这个端口号. 解决: 点击ecs下网络和安全下的安全组 在弹出的安全组中,如果没有就新建安全组,然后点击配置规则 最后如上图点击添加...或快速创建.   have fun!  将编程看作是一门艺术,而不单单是个技术。
4486 0
CentOS 7.0安装配置LAMP服务器(Apache+PHP+MariaDB)
原文 CentOS 7.0安装配置LAMP服务器(Apache+PHP+MariaDB)     一、配置防火墙,开启80端口、3306端口 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。
1134 0
CentOs 安装配置 Apache
配置过两次CentOs Apahce ,但是每次都忘了,所以想把在CentOS7 上面安装配置 Apache 2.4 的经验分享,以便以后自己查阅。写的可能有些不好,不对的地方还请大家指正。kensoon918@163.com only for feedback.
2785 0
PHP5.6和Apache2.4的安装和配置
安装前准备 系统:win8.1 64位 所用软件:php5.6和Apache2.4 64位版本 php5.6(5.6.6)下载地址:http://windows.php.net/download/点击这里,有线程安全和非线程安全两种可供选择。
1069 0
阿里云ECS云服务器初始化设置教程方法
阿里云ECS云服务器初始化是指将云服务器系统恢复到最初状态的过程,阿里云的服务器初始化是通过更换系统盘来实现的,是免费的,阿里云百科网分享服务器初始化教程: 服务器初始化教程方法 本文的服务器初始化是指将ECS云服务器系统恢复到最初状态,服务器中的数据也会被清空,所以初始化之前一定要先备份好。
3228 0
4571
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
文娱运维技术
立即下载
《SaaS模式云原生数据仓库应用场景实践》
立即下载
《看见新力量:二》电子书
立即下载