Freebsd7.0+Apache2.2+MySQL5+PHP5安装配置
<p>一、<a target="_blank" href="#" class="UBBWordLink">安装</a>apache2.2.8<br />首先去http://www.apache.org 网站上下载apache2.2.8源码包<br />
解压缩<br />
#tar zxvf httpd-2.2.8.tar.gz<br />
得到 httpd-2.2.8文件夹<br />
#cd httpd-2.2.8<br />
配置<br />
#./configure --prefix=/usr/local/apache --enable-so --enable-module=rewrite <br />
编译<br />
#make<br />
<a target="_blank" href="#" class="UBBWordLink">安装</a><br />
#make install<br />
<a target="_blank" href="#" class="UBBWordLink">安装</a>完成<br />
测试一下<a target="_blank" href="#" class="UBBWordLink">安装</a>效果<br />
#cd /usr/local/apache<br />
#cd bin<br />
# ./apachectl start<br />
httpd: apr_sockaddr_info_get() failed for <br />
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName<br />
(2)No such file or directory: Failed to enable the 'httpready' Accept Filter<br />
出现上述提示<br />
#vi /usr/local/apache/conf/httpd.conf<br />
修改SeverName一项即可<a target="_blank" href="#" class="UBBWordLink">解决</a>(1)错误提示<br />
产生(2)的原因是:FreeBSD <a target="_blank" href="#" class="UBBWordLink">系统</a>还提供了http filter,会自动过滤掉不完整的HTTP请求。<br />
<a target="_blank" href="#" class="UBBWordLink">解决</a><a target="_blank" href="#" class="UBBWordLink">方法</a>:<br />
kldload accf_http<br />
修改/boot/defaults/loader.conf中,以便下次启动自动装载模块<br />
accf_http_load="YES"<br />
在浏览器是输入http://serverip<br />
出现 "It works!" 表明apache安装成功<br />
二、<a target="_blank" href="#" class="UBBWordLink">安装</a>MySQL<br />
下载MySQL源码包 <br />
# ls<br />
httpd-2.2.8.tar.gz mysql-5.0.51.tar.gz<br />
解压缩<br />
#tar zxvf mysql-5.0.51.tar.gz<br />
# cd mysql-5.0.51<br />
配置<br />
#./configure --prefix=/usr/local/mysql<br />
编译<br />
#make<br />
编译时间可能需要较长时间,请耐心等待。<br />
<a target="_blank" href="#" class="UBBWordLink">安装</a><br />
#make install<br />
创建MySQL组<br />
# pw groupadd mysql<br />
创建MySQL用户<br />
# pw useradd mysql -g mysql -d /usr/local/mysql/ -m mysql<br />
修改MySQL用户密码<br />
#passwd mysql<br />
建立用户后我们就初始化表 (注意:必须先执行本步骤后才能进行以下步骤)<br />
# ./scripts/mysql_install_db --user=mysql #初试化表并且规定用mysql用户来访问<br />
初始化表以后就开始给mysql和root用户设定访问权限, 我们先到<a target="_blank" href="#" class="UBBWordLink">安装</a>mysql的目录:<br />
# cd /usr/local/mysql<br />
然后<a target="_blank" href="#" class="UBBWordLink">设置</a>权限<br />
# chown -R root . #设定root能访问/usr/local/mysql<br />
# chown -R mysql var #设定mysql用户能访问/usr/local/mysql/var ,里面存的是mysql的数据库文件<br />
# chown -R mysql var/. #设定mysql用户能访问/usr/local/mysql/var下的所有文件<br />
# chown -R mysql var/mysql/. #设定mysql用户能访问/usr/local/mysql/var/mysql下的所有文件<br />
# chgrp -R mysql . #设定mysql组能够访问/usr/local/mysql<br />
<a target="_blank" href="#" class="UBBWordLink">设置</a>完成后,基本上就装好了,好了,我们运行一下我们的mysql:<br />
# /usr/local/mysql/bin/mysqld_safe --user=mysql &<br />
出现如下提示:<br />
# /usr/local/mysql/bin/mysqld_safe --user=mysql &<br />
7022<br />
# Starting mysqld daemon with databases from /usr/local/mysql/var<br />
# ps -ef<br />
ps: Process environment requires procfs(5)<br />
PID TT STAT TIME COMMAND<br />
1040 v0 Is+ 0:00.00 /usr/libexec/getty Pc ttyv0<br />
723 v1 Is+ 0:00.00 /usr/libexec/getty Pc ttyv1<br />
724 v2 Is+ 0:00.00 /usr/libexec/getty Pc ttyv2<br />
725 v3 Is+ 0:00.00 /usr/libexec/getty Pc ttyv3<br />
726 v4 Is+ 0:00.00 /usr/libexec/getty Pc ttyv4<br />
727 v5 Is+ 0:00.00 /usr/libexec/getty Pc ttyv5<br />
728 v6 Is+ 0:00.00 /usr/libexec/getty Pc ttyv6<br />
729 v7 Is+ 0:00.00 /usr/libexec/getty Pc ttyv7<br />
7022 p0 S 0:00.01 /bin/sh /usr/local/mysql/bin/mysqld_safe --user=mysql<br />
7038 p0 R+ 0:00.00 ps -ef<br />
上述信息表明MySQL安装成功<br />
为了每次<a target="_blank" href="#" class="UBBWordLink">系统</a>重启后都能运行mysql,可以写一个脚本放到 /etc/rc.d目录下,用来运行mysql,我们写一个脚本mysql_start.sh<br />
#! /bin/sh<br />
/usr/local/mysql/bin/mysqld_safe&<br />
然后保存到/etc/rc.d目录下,那么以后reboot系统后都能启动mysql了.<br />
MySQL的<a target="_blank" href="#" class="UBBWordLink">安装</a>是最顺利的一个<br />
三、<a target="_blank" href="#" class="UBBWordLink">安装</a>PHP<br />
去http://www.php.net网站上去下载php-5.2.5的源码包<br />
解压缩<br />
#tar zxvf php-5.2.5.tar.gz<br />
#cd php-5.2.5<br />
配置<br />
# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql<br />
出现如下错误提示:<br />
Sorry, I cannot run apxs. Possible reasons follow:<br />
1. Perl is not installed<br />
2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs<br />
3. Apache was not built using --enable-so (the apxs usage page is displayed)<br />
The output of /usr/local/apache/bin/apxs follows:<br />
./configure: /usr/local/apache/bin/apxs: not found<br />
configure: error: Aborting<br />
表明没有<a target="_blank" href="#" class="UBBWordLink">安装</a>perl<br />
下载perl进行<a target="_blank" href="#" class="UBBWordLink">安装</a>(去http://www.perl.com下载最新版本,我从别的网站下载了个5.8版本make时死活过不去)<br />
#tar xzvf perl-5.10.0.tar.gz <br />
#sh Configure -de <br />
#make <br />
#make test <br />
#make install<br />
<a target="_blank" href="#" class="UBBWordLink">安装</a>完perl后还是提示上述错误,<br />
我就去apche的源程序中又来了一次下面的动作<br />
配置<br />
#./configure --prefix=/usr/local/apache --enable-so --enable-module=rewrite <br />
编译<br />
#make<br />
<a target="_blank" href="#" class="UBBWordLink">安装</a><br />
#make install<br />
后重新configure php时出现如下错误:<br />
configure: error: xml2-config not found. Please check your libxml2 installation.<br />
<a target="_blank" href="#" class="UBBWordLink">安装</a>libxml2<br />
#tar zxvf libxml2-2.6.31.tar.gz<br />
#cd libxm2-2.6.31<br />
#./configure<br />
#make<br />
#make install<br />
<a target="_blank" href="#" class="UBBWordLink">安装</a>libxml2后,重新configure php 出现如个错误提示:<br />
configure: error: Please specify the install prefix of iconv with --with-iconv=<DIR><br />
#tar zxvf libiconv-1.10.tar.gz<br />
#cd libiconv-1.10<br />
#./configure<br />
#make<br />
#make install<br />
注意:我开始的时候<a target="_blank" href="#" class="UBBWordLink">安装</a>的 libiconv-1.11结果<a target="_blank" href="#" class="UBBWordLink">安装</a>完成后,重起启动时出现问题(用户就是登录不去,不是是<a target="_blank" href="#" class="UBBWordLink">系统</a>的bug还是软件的兼容性不好,后来用单用户进入,删除了/usr/local/下的libiconv相关文件才得以登录<a target="_blank" href="#" class="UBBWordLink">系统</a>,从出现这个问题到<a target="_blank" href="#" class="UBBWordLink">解决</a>这个问题花了我半天的时间,大家一定要记住这个教训)<br />
<a target="_blank" href="#" class="UBBWordLink">安装</a>完libxml2后重新configure php<br />
这样再configure php时结果还提示错误,具体的信息忘记记下来了,大体的意思是说没有找到iconv和libiconv请reinstall iconv,这时候已经是晚上10点多了,我怒了,决定试一下ports安装iconv和libiconv.(这下子我是实在没有耐心了)<br />
#whereis iconv<br />
根据提示到相应的目录下iconvpath指相应的目录(当时<a target="_blank" href="#" class="UBBWordLink">系统</a>提示的信息具体是什么我记不清了)<br />
#cd iconvpath<br />
然后开始<a target="_blank" href="#" class="UBBWordLink">安装</a><br />
#make install clean<br />
执行上述命令时出/usr/ports/distfiles下没有找到文件,然后出现一个连接到ftp下载的信息,没办法我这个机器不能上外面,我只能用另一台机器上那个ftp上下载软件然后再放到/usr/ports/distfiles这里,重新make install clean 结果又提示缺少什么软件,我就这样一个一个的下载下来放到/usr/ports/distfiles里面<br />
按照上述的方式又<a target="_blank" href="#" class="UBBWordLink">安装</a>了libiconv<br />
本已经编译<a target="_blank" href="#" class="UBBWordLink">安装</a>了perl 后来一想反正是要ports,就再ports一下这个perl吧 <br />
就这样又ports安装了perl一次.<br />
这一切准备完毕<br />
再重新开始的信息configure PHP <br />
这一次没问题了<br />
过几分钟后出现如下提示:<br />
+--------------------------------------------------------------------+<br />
| License: |<br />
| This software is subject to the PHP License, available in this |<br />
| distribution in the file LICENSE. By continuing this installation |<br />
| process, you are bound by the terms of this license agreement. |<br />
| If you d#loadModule php4_module modules/libphp4.so not agree with the terms of this license, you must abort |<br />
| the installation process at this point. |<br />
+--------------------------------------------------------------------+<br />
Thank you for using PHP.<br />
这次终于没有错误了<br />
继续一口气做完吧<br />
编译php<br />
#make<br />
#make test<br />
#make install<br />
#cp php.ini-dist /usr/local/php/lib/php.ini<br />
上述这几步就是有些耗时间,不过再也没有出现这样的那样的错误,这一点让我很欣慰.<br />
<a target="_blank" href="#" class="UBBWordLink">安装</a>完成<br />
接下来的事情就简单了<br />
四、整合apache和php<br />
为了让Apache能够直接解析php,我们还要进行一些配置<br />
首先进入apache的配置文件目录:<br />
# cd /usr/local/apache/conf<br />
# vi httpd.conf<br />
在httpd.conf文件中,添加<br />
AddType application/x-httpd-php .php<br />
AddType application/x-httpd-php-source .phps<br />
应该将以上两句添加在其他AddType之后。<br />
确保文件中有以下一句话,没有就自己添加在所有LoadModule之后。<br />
LoadModule php5_module modules/libphp5.so<br />
若存在loadModule php4_module modules/libphp4.so请将此句注释掉因为我们<a target="_blank" href="#" class="UBBWordLink">安装</a>的是php5<br />
在下面中添加index.php<br />
<IfModule dir_module><br />
DirectoryIndex index.php index.html<br />
</IfModule><br />
至此,配置结束!<br />
在/usr/local/apache/htdocs中新建一个页面info.php<br />
<?php<br />
phpinfo();<br />
?><br />
在浏览器中中输入http://serverip/info.php<br />
看一下输出,看看是否是自己想要的结果<br />
配置完成!</p>
頁:
[1]