1.准备工作:
1.1安装文件准备和安装环境确认
1.1.1源文件
1)Apache代理服务软件httpd-2.2.11
2)PHP开源代码包php-5.3.0
1.1.2安装环境确认
1) 操作系统版本【非必要环节】
OS:Linux 2.6.18-128.el5(RHAS 5.3)【默认安装】
gcc version 4.1.2 20080704
[root@localhost /]# cat /proc/version Linux version 2.6.18-128.el5 (mockbuild@hs20-bc1-5.build.redhat.com) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-44)) #1 SMP Wed Dec 17 11:42:39 EST 2008 [root@localhost /]# lsb_release -a LSB Version: :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch Distributor ID: RedHatEnterpriseServer Description: Red Hat Enterprise Linux Server release 5.3 (Tikanga) Release: 5.3 Codename: Tikanga [root@localhost /]# |
2)基本环境确认
以下查询确认的GCC和libxml2一般在安装操作系统时都已经默认安装过了。如果未安装或版本有特定要求,下载对应的rpm包,自行安装。
GCC:编译源码时需要GCC编译器,使用命令【rpm -qa | grep ^gcc】
查询确认是否已经安装。
[root@localhost ResourceDir]# rpm -qa | grep ^gcc gcc-4.1.2-44.el5 gcc-c++-4.1.2-44.el5 gcc-gfortran-4.1.2-44.el5 [root@localhost ResourceDir]# |
libxml2:
安装php5需要libxml2,没有装libxml2可能会出现这样的错误:
configure: error: xml2-config not found. Please check your libxml2 installation。使用【rpm -qa | grep libxml】查询确认。
[root@localhost ResourceDir]# rpm -qa | grep libxml libxml2-2.6.26-2.1.2.7 libxml2-python-2.6.26-2.1.2.7 libxml2-devel-2.6.26-2.1.2.7 [root@localhost ResourceDir]#
|
1.2目标安装程序的版本验证:
通常,Linux系统默认安装了Apache、PHP,但版本都比较低。更重要的一点是,在上述程序的安装配置过程中,有一些是相互关联的操作!虽然也可以手工配置,但是在安装过程中只是设置一些参数就能完成,还是比较方便的。所以建议如果已经安装的,就卸载掉,安装新版本。
1.2.1卸载Apache的代理服务httpd
1)查询是否已经安装
安装系统软件都是通过rpm包安装的,所以可以通过命令【rpm -qa | grep httpd】来查询可执行程序的安装列表:
-qa是指列出所有安装的软件,grep httpd,是只列出包含httpd的所有软件。
[root@localhost ResourceDir]# rpm -qa | grep httpd httpd-manual-2.2.3-22.el5 httpd-2.2.3-22.el5 [root@localhost ResourceDir]# |
本操作系统有关httpd的可执行程序列表如上。
2)卸载操作
使用【rpm -e httpd-2.2.3-22.el5】命令来卸载通过rpm包安装的可执行程序。如果要卸载的程序与其他程序存在依赖关系,则执行过程会中断,并且给出提示:
[root@localhost ResourceDir]# rpm -e httpd-2.2.3-22.el5 error: Failed dependencies: httpd-mmn = 20051115 is needed by (installed) mod_python-3.2.8-3.1.i386 httpd-mmn = 20051115 is needed by (installed) mod_ssl-2.2.3-22.el5.i386 httpd-mmn = 20051115 is needed by (installed) mod_perl-2.0.4-6.el5.i386 httpd-mmn = 20051115 is needed by (installed) php-5.1.6-23.el5.i386 webserver is needed by (installed) webalizer-2.01_10-30.1.i386 httpd >= 2.0.40 is needed by (installed) mod_python-3.2.8-3.1.i386 httpd = 0:2.2.3-22.el5 is needed by (installed) mod_ssl-2.2.3-22.el5.i386 [root@localhost ResourceDir]#
|
3)规避依赖关系的卸载操作
使用【rpm -e --allmatches --nodeps httpd-2.2.3-22.el5】命令来规避上述的依赖关系,完成卸载操作。具体过程如下:
[root@localhost ResourceDir]# which httpd /usr/sbin/httpd [root@localhost ResourceDir]# rpm -q -f /usr/sbin/httpd httpd-2.2.3-22.el5 [root@localhost ResourceDir]# rpm -e --allmatches --nodeps httpd-2.2.3-22.el5 [root@localhost ResourceDir]# [root@localhost ResourceDir]# which httpd /usr/bin/which: no httpd in (/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin) [root@localhost ResourceDir]#
|
1.2.2查询验证和卸载PHP
执行过程和上述Apache代理服务的卸载类似:
[root@localhost ResourceDir]# which php /usr/bin/php [root@localhost ResourceDir]# rpm -q -f /usr/bin/php php-cli-5.1.6-23.el5 [root@localhost ResourceDir]# rpm -e --allmatches --nodeps php-cli-5.1.6-23.el5 [root@localhost ResourceDir]# which php /usr/bin/which: no php in (/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin) [root@localhost ResourceDir]# rpm -qa |grep php php-ldap-5.1.6-23.el5 php-common-5.1.6-23.el5 php-5.1.6-23.el5 [root@localhost ResourceDir]# rpm -e php-common-5.1.6-23.el5 error: Failed dependencies: php-common = 5.1.6-23.el5 is needed by (installed) php-5.1.6-23.el5.i386 php-common = 5.1.6-23.el5 is needed by (installed) php-ldap-5.1.6-23.el5.i386 [root@localhost ResourceDir]# rpm -e php-ldap-5.1.6-23.el5 [root@localhost ResourceDir]# rpm -qa |grep php php-common-5.1.6-23.el5 php-5.1.6-23.el5 [root@localhost ResourceDir]# rpm -e php-5.1.6-23.el5 [root@localhost ResourceDir]# rpm -e php-common-5.1.6-23.el5 [root@localhost ResourceDir]#
|
2. Apache和PHP的安装配置
2.1安装配置的准备工作
2.1.1建立安装程序的源文件目录【具体操作步骤见文本框】
1)创建目录;
2)上传或者copy安装程序源文件到相应目录;
3) 解压缩
4)修改新建目录及上传源文件的群组访问权限(保证安装过程中的正常读写访问)
[root@localhost /]#mkdir /opt/ ResourceDir/Apache [root@localhost /]#mkdir /opt/ ResourceDir/PHP [root@localhost /]#cd opt/ ResourceDir [root@localhost ResourceDir]#cp /mnt/hgfs/ShareDocs/tools/httpd-2.2.11.tar.gz /opt/ResourceDir/Apache/ [root@localhost ResourceDir]# cp /mnt/hgfs/ShareDocs/tools/ php-5.3.0.tar.gz /opt/ResourceDir/PHP/ [root@localhost ResourceDir]#cd Apache [root@localhost Apache]#tar –zxvf httpd-2.2.11.tar.gz …… …… [root@localhost Apache]#cd /opt/ ResourceDir/PHP [root@localhost PHP]# tar –zxvf php-5.3.0.tar.gz …… …… [root@localhost PHP]#chmod 777 /opt/ ResourceDir [root@localhost PHP]# 2.2安装配置Apache 2.2.1安装步骤【具体操作步骤见文本框】 1)进入解压的目录 2)运行configure安装配置参数; ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-expires --enable-cache --enable-mem-cache 上述配置生效要执行一些时间。 configure指令参数: --prefix是安装的目标路径; enable后面模块选项,这里选择一些常用的模块: so是支持动态链接机制上加载DSO【动态共享对象Dynamic Shared Objects】模块。后面装PHP时就会创建一个so的php模块。 rewrite就是常用到的重写。 expires是控制HTTP的"Expires:"和"Cache-Control:"头内容,PHP用header控制缓存时要用到。 3)生成makefile文件; 4)make 编译源码时间较长。 5)make test(非必要) 6)make install
经过上述步骤,Apache的代理服务httpd已经成功安装完成,后续要做一些小的配置调整。 2.2.2安装验证 安装完成后,做如下验证操作: 1)监听进程查看
2)启动、重启动、停止apache服务 调用apachectl命令,须保证apachectl的调用路径准确。当然这与安装过程中./configure的prefix的配置参数有关。
3)服务访问验证 在浏览器打输入http://10.166.138.199/index4Apache.html 【默认安装的Apache,只需要输入发布服务的IP地址即可,默认访问80端口】 出现 It works!这说明服务已经安装部署成功,可以正常访问了。 2..2.3配置调整
2.3安装PHP 2.3.1安装步骤【具体操作步骤见文本框】 1)进入解压的目录 2)运行configure安装配置参数; ./configure --prefix=/usr/local/php--with-config-file-path=/usr/local/lib --with-apxs2=/usr/local/httpd/bin/apxs --with-zlib --enable-mbstring --enable-xml Configure配置需要执行一些时间 #configure参数: #--prefix是安装目录。 #--with-config-file-path是指定php配置文档php.ini所在的目录。 #--with-zlib安装zlib扩展,前提是linux已经安装了zlib,未安装可以去掉这个选项。 #安装mbstring和xml扩展。这些都是常用的模块。 3)生成makefile文件; 4)make 编译源码时间较长。 5)make test(非必要) 6)make install 7) 将php配置文档复制到/usr/local/lib
注:PHP的其他验证工作要由Apache代理配合完成。后续完成配置修改后,进行验证。
2.4修改Apache和PHP配置 2.4.1配置apache关联php 1)打开apache配置文档httpd.conf,进行编辑或确认 vi /usr/local/httpd/conf/httpd.conf vi编辑器打开httpd.conf,或者本地修改确认后,再上传。 2)确认LoadModule 打开后,直接输入/LoadModule后回车。确认LoadModule已经包含: LoadModule php5_module modules/libphp5.so 这个配置在安装PHP的configure参数已经设置好,安装时会修改Apache的httpd.conf配置文件,并将php标准库文件生成到/modules目录,这里需要确认下。
3)确认DocumentRoot 用同样的方法,找到DocumentRoot。确认是: DocumentRoot "/usr/local/httpd/htdocs" 之后发布页面文件的根目录就是指这个目录。以后就可以在这里创建php、html文件。 4)确认Directory 如果要修改上述的DocumentRoot,也要同步修改Directory。 <Directory "/usr/local/httpd/htdocs"> 5)增加AddType类型 输入/AddType,回车查找。找到后,追加(a【vi】)或者插入(i【vi】)如下内容: AddType application/x-httpd-php .php 然后点击 Esc ,退出插入编辑模式 6)增加或编辑DirectoryIndex 输入 /DirectoryIndex,回车查找。找到后,同样用追加或插入的方式,更新为如下内容: <IfModule dir_module> DirectoryIndex index.php index.html </IfModule> 修改发布后,浏览器访问时如果没有指明那个文件,就默认打开index.php。 7)修改项确认完毕,保存退出 点击 Esc 退出插入编辑模式,输入:wq后回车,即完成上述的修改保存。注:wq,保存并退出。
2.4.2配置PHP
2)修改php时区 php5默认是格林威治时间,不修改的话与北京时间相差8小时。 输入/timezone,回车查找 改成 date.timezone = PRC 3)显示notice警告提示 php5默认关闭notice警告提示,如果是在本地调试,建议打开notice警告提示。 输入/error_reporting,回车查找 改成 error_reporting = E_ALL 4)修改项确认完毕,保存退出 点击 Esc 退出插入编辑模式,输入:wq后回车,即完成上述的修改保存。
2.5建立PHP测试页面 2.5.1建立页面 1)vi vi /usr/local/httpd/htdocs/index.php 没有此文件的话,vi命令就会新建。 2)打开文件后,按键i,即进入修改模式,输入以下内容:
3)按键ESC,即退出修改编辑模式。 4)按键:wq,退出并保存上述修改内容。
2.6配置完成,验证PHP和Apache服务 2.6.1重启apache服务
2.6.2错误提示修订 如果出现类似的这样的错误,说明受selinux限制。
桌面系统上会有“提示”弹出,可以根据提示将其关闭。或者执行以下命令:
再次重启apache。 2.6.3浏览访问验证 在浏览器输入 http://10.166.138.199 回车后,可浏览以下内容,比较多,挑选了几个作为示例【phpinfo()根据php标准库的libphp5.so动态共享对象来获取服务内容】: 1)PHP基本信息 2)xml和zlib 3)mbstring
2.7随系统启动Apache代理服务 默认安装的Apache并不是随操作系统的启动而启动。可以通过如下修改,随系统启动apache代理服务。
2)点击 Esc,退出插入编辑模式 3)直接输入:wq 回车,即保存并退出。 以后,启动操作系统时,Apache代理服务即可自启动了。 OK!Apache和PHP的安装配置基本完成,可以在虚拟机上正常发布访问了。下一步去做一个简单的PHP开源代码扩展模块练练手吧!
3. PHP-WEB(添加php5开源代码的扩展模块test_module) 3.1创建PHP扩展模块及修改配置: 1)进入.. php-5.3.0/ext目录; 2)运行./ext_skel --extname=test_module【test_module为自定义名称,不与ext目录下其他模块名称重复即可】 3)生成扩展模块test_module 具体过程如下:
4)进入扩展模块路径
5)修改../test_module/config.m4:
输入/ PHP_ARG_ENABLE,回车找到后,i进入编辑模式,将如下内容:
修改为:
7)修改扩展模块php_test_module.h 修改 php_test_module.h,将confirm_my_module_compiled函数修改为test_module;增加函数sayhello;如下:
修改为
8)修改扩展模块test_module.c 修改 PHP_FE(test_module,NULL),并追加PHP_FE(sayhello,NULL)的定义;
并在文件最后,追加实现上述两个函数:
3.2编译扩展模块test_module 1)进入../php-5.3.0/ext路径 2)执行以下操作,生成.so文件的DSO:
3)生成的test_module.so文件在test_module目录下。
3.3手动加载DSO(Dynamic Share Object) 将上述的test_module.so文件copy到Apache目录,以备自动加载。具体目标路径,验证查看的操作如下:
3.4修改php.ini[w2]
[w2] 加载多个扩展extension=/usr/local/httpd/modules/XXX_web.so extension=/usr/local/httpd/modules/test_module.so
3.5编写扩展模块的验证页面
保存退出后,即可进行访问验证。 3.6浏览器访问验证 打开浏览器,输入http://10.166.138.199/test.php
|