`

apache2.2.4 PHP 环境的安装及扩展配置

阅读更多
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>
    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>
    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>
    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>
    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目录下了
 
分享到:
评论

相关推荐

    php配置+mysqlAdmin配置+apache配置的实现教程

    注意默认端口是80 安装成功后启动apache访问http://127.0.0.1及安装成功 3。 apache的配置文件\conf\httpd.conf apache的默认的项目存放目录\htdocs\ &lt;br&gt;2)apache的一些常用配置...

    OELove 婚恋交友安装版 v3.6_R50626

    OELove 婚恋交友安装版系列是专为用户能够快速简便的安装构建OE应用及系统运行所需环境而开发的。为了满足更多的用户实现快速一键安装体验,不用担心环境如何安装与配置的问题。1. 执行 Setup.exe,安装提示进行安装...

    OELove 婚恋交友安装版 v3.2_R40425.rar

    为了满足更多的用户实现快速一键安装体验,不用担心环境如何安装与配置的问题。 1. 执行 Setup.exe,安装提示进行安装; 2. 相关帐户说明 系统管理员初始账户:admin 系统管理员初始密码:admin 后台地址:http://...

    PHP5与MySQL5从入门到精通.rar

    1.2.1 Linux下安装.Apache和PHP 1.2.2 Windows下安装Apache和PHP 1.3 PHP配置 1.3.1 PHP配置文件 1.3.2 PHP常用配置选项 1.3.3 加载扩展库 1.4 本章小结 第2章 网站开发语法基础 2.1 基本语法 2.2 数据...

    PHP网络编程技术与实践 源码

    第1章 PHP开发环境的安装配置 1.1 Windows下IIS的安装配置 1.1.1 IIS的安装 1.1.2 配置调试IIS运行环境 1.1.3 IIS的设置 1.2 Linux下Apache的安装配置 1.2.1 Apache的安装工作 1.2.2 Apache的配置工作 1.3 PHP的安装...

    php网络开发完全手册

    第1章 PHP的介绍及环境搭建 2 1.1 PHP简介 2 1.1.1 PHP语言的发展简史 2 1.1.2 PHP的发展现状与未来展望 3 1.1.3 PHP语言的优势 3 1.1.4 相关资源及自学提示 4 1.2 PHP的应用范围及案例 5 1.2.1 PHP可以做什么 5 ...

    集群好书《高性能Linux服务器构建实战》 试读章节下载

    11.4.1 配置与检查安装环境 11.4.2 在Director Server上安装IPVS管理软件 11.5 搭建高可用 LVS集群 11.5.1 通过heartbeat搭建LVS高可用性集群 11.5.2 通过Keepalived搭建LVS高可用性集群系统 11.5.3 通过...

    JSP高级编程

    前 言 JSP是SUN公司推出的一种新型的Internet/Intranet开发语言,和前一代Internet/Intranet开发语言(ASP、PHP)相比,JSP在以下几个方面有了重大的突破: 1) 通过JSP的扩展标签库和JavaBeans功能,网站逻辑和网站...

Global site tag (gtag.js) - Google Analytics