天天看点

Linux下Apache与MySQL+PHP的综合应用案例

<b>Linux</b><b>下</b><b>Apache</b><b>与</b><b>MySQL+PHP</b><b>的综合应用案例</b><b></b>

<b></b> 

<b>实验背景:</b><b></b>

小诺公司的Linux服务器中已经编译安装了Apache服务器,为了构建公司的论坛系统,需要安装phpBB论坛程序。phpBB是典型的LAMP(Linux+Apache+MySQL+PHP)架构应用系统,因此需要在现有Apache服务器的基础上搭建完整的LAMP运行环境,具体的应用需求如下:

1、 搭建Apache服务器,并创建虚拟主机。

2、 安装MySQL服务器,作为phpBB论坛程序的后台SQL数据库服务器使用。

3、 配置Apache服务器支持PHP程序运行,一边phpBB程序能够在Apache服务器中被正确处理。

4、 在已经安装构建的LAMP环境中安装和配置phpBB程序,从而实现论坛系统的功能。

<b>实验步骤:</b><b></b>

<b>一、 </b><b>安装并管理</b><b>MySQL</b><b>服务器。</b><b></b>

下载完成之后,使用tar命令将下载的mysql源码包解压到/usr/local/目录下,会释放出一个名为mysql-2.23.58-pc-linux-i686.的文件。

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722703wykk.jpg"></a>

为了方便管理,需要使用ln命令建立该目录的符号链接目录为mysql。

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722705HYKr.jpg"></a>

进入mysql服务器程序的目录,删除mysql的配置文件my.cnf

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722706oVk0.jpg"></a>

执行mysql_install_db命令初始化MySQL服务器中的数据库。

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722708NraX.jpg"></a>

由于是手动安装MySQL数据库,因此需要在系统中建立名为mysql的用户和组,并指定mysql用户的宿主目录是“/usr/local/mysql/data”。参数“-R”是将mysql目录中的所有文件的属主和属组都修改。

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722710jZFb.jpg"></a>

使用safe_mysqld命令启动MYSQL服务器运行,并使用命令选项“--user”指定MySQL数据库服务程序以系统用户mysql的身份运行。

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722711Jepw.jpg"></a>

运行./bin/mysql,查看MySQL数据库是否能够运行。

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_12447227125WOO.jpg"></a>

由于MySQL数据库的管理员用户root的初始口令为空,所有mysql数据库程序启动后的第一件工作就是为MySQL数据库中的root用户设置口令,“-p”参数可以更改密码。成功设置数据库用户root口令之后,执行MySQL程序可以进入MySQL数据库的交互界面,在mysql命令中需要使用“-u”选项指定登录数据库使用的用户名,使用“-p”选项设置提示用户输入口令。

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_12447227140zQC.jpg"></a>

<b>二、 </b><b>安装并管理</b><b>PHP</b><b>环境</b><b></b>

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722716Yz9N.jpg"></a>

进入php-4.4.4子目录,并使用“./configure”命令进行编译之前的准备工作。

--prefix设置PHP程序的安装路径。

--with-apxs2 设置PHP为Apache服务器提供的模块的安装位置。

--with-mysql 设置MySQL服务器程序的安装位置。

-with-config-file-path 设置PHP程序的配置文件所在的位置。

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722718oH94.jpg"></a>

在完成“./configure”命令的配置后,就可以使用make命令进行编译并使用make install命令进行PHP程序的安装了。

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722719wslt.jpg"></a>

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722720sxMQ.jpg"></a>

安装完成之后,PHP程序还没有配置文件,需要将PHP的配置模板文件php.ini-disk复制到PHP的配置目录中作为配置文件使用。

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_12447227201QOK.jpg"></a>

<b>三、进行</b><b>Apache</b><b>服务器中的设置</b><b></b>

由于PHP程序需要和Apache服务器配合工作,因此需要在Apache服务器的主配置文件httpd.conf中进行PHP的相关设置。

编辑httpd.conf文件,确认LocadModule php4_module modules/lobphp4.so设置行已经有效,并在相应的位置添加设置行AddType application/x-httpd-php .php

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722721F5Eg.jpg"></a>

在DirectoryIndex这一行的末尾添加index.php,以便Apache服务器能够正确处理php类型的index文件。如果访问的时候不想输入index.php,可以将index.php放置在最前面。

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722722GNBA.jpg"></a>

对httpd.conf设置完成之后,停止服务apachectl,然后启用服务apachectl。如果不生效,使用命令“killall -9 httpd服务”然后再通过以下脚步启动httpd服务。

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722723utHS.jpg"></a>

<b>四、测试</b><b>PHP</b><b>环境是否可用</b><b></b>

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722724Oz4o.jpg"></a>

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722725dg0J.jpg"></a>

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722726LgVg.jpg"></a>

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_124472272793Bn.jpg"></a>

修改完成之后,重新启动apachectl服务。然后在Windows客户机上进行测试。

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722728htsP.jpg"></a>

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722730fDpX.jpg"></a>

如何浏览器中出现上图所示的PHP页面信息,说明php程序已经能够与Apache服务器正常协同工作了。

<b>五、安装</b><b>phpBB</b><b>论坛系统</b><b></b>

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722731694N.jpg"></a>

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722732FkzN.jpg"></a>

使用chown命令将phpBB2子目录及其下所有文件的属主和属组都设置为nobody(默认的系统账户,不允许登录系统),以便Apache服务器有足够的权限访问phpBB程序。

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722733Ij90.jpg"></a>

使用命令“/usr/local/mysql/bin/mysql –u root -p”登录数据库MySQL,并创建一个名为phpbb_dreamfire的数据库作为phpBB的后台数据库。

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722735dhSg.jpg"></a>

Database Type: 设置数据库的版本为3.x

Your Database Name:输入数据库的名称

Database Username:输入登录数据库的用户名

Database password:输入登录数据库的密码

Admin Email Address:输入管理员的邮件地址,以便日后联系

Domain Name:输入phpBB论坛的FQDN

Administrator Username:输入管理phpBB论坛的用户名

Administrator Password:输入管理phpBB论坛的密码

Administrator Password【Confirn】:再次输入管理phpBB论坛的密码

设置完成之后,点击“Start Install”进行安装

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722737Lcuc.jpg"></a>

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722741o8ud.jpg"></a>

在浏览器中见下图所示的安装结束画面后,先不要急于访问phpBB论坛程序的页面,出于安全性的考虑,需要先删除phpBB2程序目录中的install和contrib两个子目录。删除完成之后,单击“Finish Installation”

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_12447227445snt.jpg"></a>

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722746axIZ.jpg"></a>

使用phpBB论坛的用户名和密码登录论坛,并进行相应的设置。

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722748BvPR.jpg"></a>

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_12447227525BYK.jpg"></a>

所有论坛的动态更新数据库都保存在“/usr/local/mysql/data/phpbb_dreamfire/”目录中。

<a href="http://dreamfire.blog.51cto.com/attachment/200906/11/418026_1244722757kfxX.jpg"></a>

至此在LAMP环境中安装phpBB论坛程序的整个过程已经完成了,对论坛内容的管理更多的会在Web界面下完成。

本文转自凌激冰51CTO博客,原文链接:http://blog.51cto.com/dreamfire/166056,如需转载请自行联系原作者